Main Content


Create OPC UA node objects



NodeList = opcuanode(Index,Id) creates an OPC UA node object or array of objects from the information in Index and Id. Index is a number or numeric vector. Id is a character vector, string, scalar integer, or cell array containing character vectors and scalar integers. Use this syntax to create node objects for known nodes on an OPC UA server. Each node Name property is set to 'Index:Identifier', and other properties of the node are left empty until you use the node to access an OPC UA server. When you successfully use the node object with a client using writeValue or readValue, the Client property of the node is set to the client, and other attributes are read from that client.


NodeList = opcuanode(Index,Id,UaClient) immediately associates the node object with the specified client UaClient. If UaClient is connected at this time, the opcuanode function also retrieves other properties from the server associated with UaClient.

Use opcuanode to create node objects only when you know the index and identifier of nodes you are interested in. For nodes that you need to find from the server, create node objects by browsing the namespace of a connected OPC UA client object with browseNamespace or getNamespace, or browse the Parent and Children properties of existing node objects.


collapse all

Construct a node object from index and identifier values. Use the node to write a value to the server, then note that the node has its properties set from the server.

S = opcuaserverinfo('localhost');
UaClient = opcua(S);
myNode = opcuanode(2,10225); % Not associated with server yet.
myNode = 
OPC UA Node:
   Node Information:
                      Name: 2:10225
            NamespaceIndex: 2
                Identifier: 10225
                  NodeType: Variable

   Hierarchy Information:
                    Parent: ''
                  Children: 0

   Server Information:
            ServerDataType: Float
        AccessLevelCurrent: read/write
        AccessLevelHistory: none
               Historizing: 0

Create a known node object and use it to browse for other nodes.

UaClient = opcua('localhost',51210);
boilerNode = opcuanode(4,1241,UaClient);
ftxNodes = findNodeByName(boilerNode,'FTX','-partial')
ftxNodes = 
1x2 OPC UA Node array:
    index   Name   NsInd  Identifier  NodeType  Children
    -----  ------  -----  ----------  --------  --------
      1    FTX001  4      1243        Object    1
      2    FTX002  4      1266        Object    1

Input Arguments

collapse all

Node index, specified as a numeric value or array.

Example: 2

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Node ID, specified as a numeric, character, or string value, or an array of these.

Example: 10225

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | char | string

OPC UA client, specified as an object. You can create the client using the opcua function.

Example: opcua()

Output Arguments

collapse all

OPC UA nodes, returned as an array of objects. An OPC UA node object stores information about a node in an OPC UA server. You can read and write current data, and read historical data using variable nodes. You can browse the name space using object and variable nodes.

A node’s type is described by its NodeType property, which can indicate an 'Object' or 'Variable' type. Variable type nodes can contain data values, while object type nodes cannot contain values. Each node type can contain other nodes: object nodes can contain object and variable nodes, variable nodes can contain other variable nodes.

Node objects include the following properties.

Node Information
NameDisplay name for the node.
DescriptionCharacter vector describing the node.
NamespaceIndexNamespace index for this node.
IdentifierUnique identifier with data type as a character vector or integer.
NodeTypeType of node: 'Object' or 'Method'or 'Variable'.
Hierarchy Information
ParentParent node of this node.
ChildrenChild nodes of this node.
Variable Information
ServerDataTypeOPC UA data type for node.
AccessLevelCurrentUser access level to current value: 'none', 'read', 'write', 'read/write'.
AccessLevelHistoryUser access level to historical values: 'none', 'read', 'write', 'read/write'.
HistorizingTrue if the server is storing history for the node data.
Method Information
ExecutableTrue if the node is executable.
UserExecutableTrue if the node is executable by the current user.
NumInputsNumber of inputs required by the node.
InputTypesData types of input arguments.
NumOutputsNumber of outputs returned by the node.
OutputTypesData types of output arguments.

Version History

Introduced in R2015b