.. _read_write_data: ======================== Reading and Writing Data ======================== .. _read_attributes: Reading Attributes ################## Reading attributes is done with the *read* method. This method exists for both the :ref:`client ` and the :ref:`server `. Read parameters --------------- :NodeId | NodeID[]: (:ref:`NodeId`) A signle identifier of a node or an array of node identifiers. it will try to read :ref:`all attributes ` of a node. For existing attributes will be returned value, for absent attrubutes of a noe will be returned status code BadAttributeIdInvalid. :NodesToRead[]: An array of tables with the following fields: **NodeID** (:ref:`NodeId`) The identifier of a node **AttributeId** (uint32) :ref:`attribute` Attribute of node to read With these parameters you can read exact attributes of a node, for example, the value of a variable. values of several variable nodes. Read Attributes Of One Node --------------------------- .. literalinclude:: examples/client/client_read.lua :language: lua :lines: 44-57 `Full source <_static/client/client_read.lua>`__ Read Attributes Of Several Nodes -------------------------------- .. literalinclude:: examples/client/client_read.lua :language: lua :lines: 44-46, 59-69 `Full source <_static/client/client_read.lua>`__ Read Variables Values --------------------- Variables in the OPCUA holds valuable data in the attribute Value. It is possible to read several values at once. .. literalinclude:: examples/client/client_read.lua :language: lua :lines: 73-96 `Full source <_static/client/client_read.lua>`__ Writing Attributes ################## Changing the values of attributes is done with the Write method. Write Parameters ---------------- +----------------------------------+---------------------------------------------------------------+ | **NodesToWrite** | Array of nodes and attributes to write | +----------------+-----------------+-----------------------------------+---------------------------+ | | **NodeId** | :ref:`NodeId` | The identifier of a node | | +-----------------+-----------------------------------+---------------------------+ | | **AttributeId** | uint32 | :ref:`attribute` | | +-----------------+-----------------------------------+---------------------------+ | | **Value** | :ref:`DataValue` | New value of the attribute| +----------------+-----------------+-----------------------------------+---------------------------+ Write example ------------- .. code-block:: lua local Server_ServerStatus_StartTime = "i=2257" local nodes = { NodesToWrite = { { NodeId = ua.NodeIds.Server_ServerStatus_StartTime, AttributeId = AttributeId.Value, Value = { -- DataValue Type = ua.VariantType.DateTime, Value = 0.0, StatusCode = ua.StatusCode.Good } } } } local response = svc:write(nodes) if response.Results[1] ~= ua.StatusCode.Good then print(string.format("Changing attribute value failed: 0x%X", response.Results[1])) return end .. _attribute: Node Attribute ############## Every node in the address space is represented by a set of attributes. Base node attribute numbers --------------------------- +--------+--------------------------+-------------------+ | Number | Attribute name | Data type | +--------+--------------------------+-------------------+ | 1 | NodeId | nodeID | +--------+--------------------------+-------------------+ | 2 | NodeClass | uint32 | +--------+--------------------------+-------------------+ | 3 | BrowseName | qualifiedName | +--------+--------------------------+-------------------+ | 4 | DisplayName | localizedText | +--------+--------------------------+-------------------+ | 5 | Description | localizedText | +--------+--------------------------+-------------------+ | 6 | WriteMask | uint32 | +--------+--------------------------+-------------------+ | 7 | UserWriteMask | uint32 | +--------+--------------------------+-------------------+ | 24 | RolePermissions | structure (TBD) | +--------+--------------------------+-------------------+ | 25 | UserRolePermissions | structure (TBD) | +--------+--------------------------+-------------------+ | 26 | AccessRestrictions | uint16 | +--------+--------------------------+-------------------+ Object node attribute numbers ----------------------------- +--------+--------------------------+-------------------+ | Number | Attribute name | Data type | +--------+--------------------------+-------------------+ | * | Base attributes | | +--------+--------------------------+-------------------+ | 12 | EventNotifier | byte | +--------+--------------------------+-------------------+ Object Type node attribute numbers ---------------------------------- +--------+--------------------------+-------------------+ | Number | Attribute name | Data type | +--------+--------------------------+-------------------+ | * | Base attributes | | +--------+--------------------------+-------------------+ | 8 | IsAbstract | boolean | +--------+--------------------------+-------------------+ Variable node attribute numbers ------------------------------- +--------+--------------------------+-------------------+ | Number | Attribute name | Data type | +--------+--------------------------+-------------------+ | * | Base attributes | | +--------+--------------------------+-------------------+ | 13 | Value | DataValue | +--------+--------------------------+-------------------+ | 14 | DataType | NodeID | +--------+--------------------------+-------------------+ | 15 | Rank | int32 | +--------+--------------------------+-------------------+ | 16 | ArrayDimensions | int32[] | +--------+--------------------------+-------------------+ | 17 | AccessLevel | byte | +--------+--------------------------+-------------------+ | 18 | UserAccessLevel | byte | +--------+--------------------------+-------------------+ | 19 | MinimumSamplingInterval | double | +--------+--------------------------+-------------------+ | 20 | Historizing | boolean | +--------+--------------------------+-------------------+ | 27 | AccessLevelEx | uint32 | +--------+--------------------------+-------------------+ Variable Type node attribute numbers ------------------------------------ +--------+--------------------------+-------------------+ | Number | Attribute name | Data type | +--------+--------------------------+-------------------+ | * | Base attributes | | +--------+--------------------------+-------------------+ | 8 | IsAbstract | boolean | +--------+--------------------------+-------------------+ | 13 | Value | DataValue | +--------+--------------------------+-------------------+ | 14 | DataType | NodeID | +--------+--------------------------+-------------------+ | 15 | Rank | int32 | +--------+--------------------------+-------------------+ | 16 | ArrayDimensions | int32[] | +--------+--------------------------+-------------------+ Reference Type node attribute numbers ------------------------------------- +--------+--------------------------+-------------------+ | Number | Attribute name | Data type | +--------+--------------------------+-------------------+ | * | Base attributes | | +--------+--------------------------+-------------------+ | 8 | IsAbstract | boolean | +--------+--------------------------+-------------------+ | 9 | Symmetric | boolean | +--------+--------------------------+-------------------+ | 10 | InverseName | localizedText | +--------+--------------------------+-------------------+ Data Type node attribute numbers -------------------------------- +--------+--------------------------+-------------------+ | Number | Attribute name | Data type | +--------+--------------------------+-------------------+ | * | Base attributes | | +--------+--------------------------+-------------------+ | 8 | IsAbstract | boolean | +--------+--------------------------+-------------------+ | 23 | DataTypeDefinition | nodeID | +--------+--------------------------+-------------------+ Method node attribute numbers ----------------------------- +--------+--------------------------+-------------------+ | Number | Attribute name | Data type | +--------+--------------------------+-------------------+ | * | Base attributes | | +--------+--------------------------+-------------------+ | 21 | Executable | boolean | +--------+--------------------------+-------------------+ | 22 | UserExecutable | boolean | +--------+--------------------------+-------------------+ View node attribute numbers --------------------------- +--------+--------------------------+-------------------+ | Number | Attribute name | Data type | +--------+--------------------------+-------------------+ | * | Base attributes | | +--------+--------------------------+-------------------+ | 11 | ContainsNoLoops | boolean | +--------+--------------------------+-------------------+ | 12 | EventNotifier | byte | +--------+--------------------------+-------------------+ .. _all_attributes: List of all attribute numbers ----------------------------- +--------+--------------------------+-------------------+ | Number | Attribute name | Data type | +--------+--------------------------+-------------------+ | 1 | NodeId | nodeID | +--------+--------------------------+-------------------+ | 2 | NodeClass | uint32 | +--------+--------------------------+-------------------+ | 3 | BrowseName | qualifiedName | +--------+--------------------------+-------------------+ | 4 | DisplayName | localizedText | +--------+--------------------------+-------------------+ | 5 | Description | localizedText | +--------+--------------------------+-------------------+ | 6 | WriteMask | uint32 | +--------+--------------------------+-------------------+ | 7 | UserWriteMask | uint32 | +--------+--------------------------+-------------------+ | 8 | IsAbstract | boolean | +--------+--------------------------+-------------------+ | 9 | Symmetric | boolean | +--------+--------------------------+-------------------+ | 10 | InverseName | localizedText | +--------+--------------------------+-------------------+ | 11 | ContainsNoLoops | boolean | +--------+--------------------------+-------------------+ | 12 | EventNotifier | byte | +--------+--------------------------+-------------------+ | 13 | Value | DataValue | +--------+--------------------------+-------------------+ | 14 | DataType | NodeID | +--------+--------------------------+-------------------+ | 15 | Rank | int32 | +--------+--------------------------+-------------------+ | 16 | ArrayDimensions | int32[] | +--------+--------------------------+-------------------+ | 17 | AccessLevel | byte | +--------+--------------------------+-------------------+ | 18 | UserAccessLevel | byte | +--------+--------------------------+-------------------+ | 19 | MinimumSamplingInterval | double | +--------+--------------------------+-------------------+ | 20 | Historizing | boolean | +--------+--------------------------+-------------------+ | 21 | Executable | boolean | +--------+--------------------------+-------------------+ | 22 | UserExecutable | boolean | +--------+--------------------------+-------------------+ | 23 | DataTypeDefinition | nodeID | +--------+--------------------------+-------------------+ | 24 | RolePermissions | structure (TBD) | +--------+--------------------------+-------------------+ | 25 | UserRolePermissions | structure (TBD) | +--------+--------------------------+-------------------+ | 26 | AccessRestrictions | uint16 | +--------+--------------------------+-------------------+ | 27 | AccessLevelEx | uint32 | +--------+--------------------------+-------------------+