.. _custom_data_source: ===================== Exporting Device Data ===================== The main purpose with an OPC-UA server is to provide access to real world objects. External information is stored in the address space in the form of variable nodes. Variable nodes have value attributes. The following section shows how to connect attributes with real world objects. Value Callback -------------- The value callback is a function and is used for both reading and writing. .. code-block:: lua function callback(nodeId, value) end Write Callback Parameters ------------------------- **nodeId** of type :ref:`node_id_type` The Node ID of the node to modify. **value** of type ::ref:`DataValue` For write The new variable value set by the client. Nil for read operation **return** :ref:`DataValue` Data from device for read operation. Ignored for write operation. Read Callback Parameters ------------------------ **nodeId** of type :ref:`node_id_type` The Node ID of the node to read. **return** of type :ref:`variant_type` The return value is returned to the client. Error reporting --------------- To report an error, the callback should raise a LUA error with a suitable OPC-UA status code. .. literalinclude:: examples/server/server_value_callback.lua :language: lua :lines: 46-62 `Full source <_static/server/server_value_callback.lua>`__ Custom data source example -------------------------- .. literalinclude:: examples/server/server_value_callback.lua :language: lua :lines: 64-84 `Full source <_static/server/server_value_callback.lua>`__