Contenido principal

opcuanode

Create OPC UA node objects

    Description

    An opc.ua.Node object stores information about a node in an OPC UA server. You use this object to browse the server namespace, access data, and run operations. Each node has a NodeType of Object, Variable, or Method. Object nodes do not store data values, and you use them to navigate the server namespace. Variable nodes store data values such as sensor or actuator readings, and you read or write current and historical values using these nodes. Method nodes behave as callable functions linked to objects, and you use them to run object specific operations.

    Creation

    Description

    nodeList = opcuanode(index,id) creates an OPC UA node object or array of node objects using the namespace index and identifier without associating the nodes with an OPC UA server. Each node object sets its Name property to 'index:id'. Other properties of the node objects remain unknown until you associate the nodes with an OPC UA server.

    To associate the nodes with an OPC UA server, specify the client when using these nodes with the writeValue or readValue function.

    example

    nodeList = opcuanode(index,id,uaClient) immediately associates the node object with the specified client uaClient. If uaClient is connected at this time, the function also retrieves other properties from the server associated with uaClient.

    Tip

    • Create node objects with opcuanode only when you know the namespace index and identifier of the nodes you are interested in.

    • If you do not know the namespace index and identifier for the node, 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.

    example

    Input Arguments

    expand all

    Namespace index of the node or nodes, specified as a numeric value or array.

    Example: [1,3,5]

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

    Node identifier, specified as a numeric, character, or string value, or an array of any of these data types. To provide identifiers of mixed data type, use a cell array.

    Example: {10225,1001,'BooleanDataItem'}

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

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

    Example: opcua()

    Output Arguments

    expand all

    OPC UA nodes, returned as an array of opc.ua.Node objects. An OPC UA node object stores information about a node in an OPC UA server.

    Properties

    expand all

    Node Information

    This property is read-only.

    Display name for the node, represented as a character vector.

    Example: 'BooleanDataItem'

    Data Types: char

    This property is read-only.

    Description of the node fetched from the server, represented as a character vector. If the server has no description for the node, the property returns an empty character array.

    Example: 'Boolean data'

    Data Types: char

    This property is read-only.

    Namespace index for the node, represented as an integer. The namespace index of an OPC UA node helps you identify the namespace URI associated with the node identifier. This mapping helps you distinguish nodes across different information models. Each OPC UA server includes a namespace with index 0 named Server that contains server information.

    Example: 5

    Data Types: uint32

    This property is read-only.

    Unique identifier for the node, represented as a character vector or integer. The unique identifier helps you distinguish a node within its namespace.

    Example: 'BooleanDataItem'

    Data Types: char | uint32

    This property is read-only.

    Type of node, represented as a character vector. The OPC UA client in MATLAB® supports these node types: 'Object', 'Method', and 'Variable'.

    Object nodes do not hold data values but can contain other object, method, and variable nodes, allowing for hierarchical organization within the server. Method nodes represent function calls to an object, and you can invoke them to execute object specific processes. Variable nodes allow you to read and write current data, as well as access historical data. These nodes can contain data values and may also include other variable nodes.

    Example: 'Variable'

    Data Types: char

    Hierarchy Information

    This property is read-only.

    Name of parent node, represented as a character vector.

    Example: 'DataItems'

    Data Types: char

    This property is read-only.

    Child nodes of a given node, represented as an array of node objects. The node object output shows only the number of children. To access the child nodes as an array of node objects, use the syntax nodeObj.Children.

    Example:

    >> nodeObj.Children
    
    ans = 
    
    1×2 OPC UA Node array:
        Index       Name        NamespaceIndex          Identifier          NodeType
        -----  ---------------  --------------  --------------------------  --------
          1    InputArguments                6  MyMethod/0:InputArguments   Variable
          2    OutputArguments               6  MyMethod/0:OutputArguments  Variable

    Variable Information

    This property is read-only.

    OPC UA data type for the node, represented as a character vector. For more information, see OPC UA Server Data Types.

    Example: 'Boolean'

    Data Types: char

    This property is read-only.

    User access level to current value of the node, represented as a character vector. This property indicates the operations a client can perform on the current value of a node.

    • 'none' — client cannot read or write the current value

    • 'read' — client can read the current value

    • 'write' — client can write the current value

    • 'read/write' — client can read or write the current value

    Example: 'read'

    Data Types: char

    This property is read-only.

    User access level to historical values of the node, represented as a character vector. This property indicates the operations a client can perform on the historical values of a node.

    • 'none' — client cannot read or write the historical values

    • 'read' — client can read the historical values

    • 'write' — client can write the historical values

    • 'read/write' — client can read or write the historical values

    Example: 'write'

    Data Types: char

    This property is read-only.

    Indicates whether the server stores historical data for a node, represented as a logical 0 or 1.

    Example: 1

    Data Types: logical

    Method Information

    This property is read-only.

    Indicates whether the method node is executable, represented as a logical 0 or 1.

    Example: 1

    Data Types: logical

    This property is read-only.

    Indicates whether the method node is executable by the current user, represented as a logical 0 or 1.

    Example: 1

    Data Types: logical

    This property is read-only.

    Number of inputs required to execute the method node, represented as a double.

    Example: 2

    Data Types: double

    This property is read-only.

    Data types of input arguments to execute the method node, represented as a cell array of character vectors.

    Example:

    >> mNodeObj.InputTypes
    
    ans =
    
      1×2 cell array
    
        {'String'}    {'Double'}

    This property is read-only.

    Number of outputs returned by the method node, represented as a double.

    Example: 1

    Data Types: double

    This property is read-only.

    Data types of output arguments of the method node, represented as a cell array of character vectors.

    Example:

    >> mNodeObj.OutputTypes
    
    ans =
    
      1×1 cell array
    
        {'Double'}

    Object Functions

    findNodeByIdFind OPC UA server node by namespace index and identifier
    findNodeByNameFind OPC UA server nodes by name
    getAllChildrenRecursively retrieve all children of OPC UA server node
    getNodeAttributesRead OPC UA server node attributes
    invokeExecute method node on OPC UA server
    isEmptyNodeTrue for empty nodes of OPC UA node array
    isObjectTypeDetermine if nodes are object type
    isVariableTypeDetermine if nodes are variable type
    readAtTimeRead historical data from nodes of OPC UA server at specific times
    readHistoryRead historical data from nodes on OPC UA server
    readProcessedRead aggregate data from nodes of an OPC UA server
    readValueRead values from nodes on OPC UA server
    writeValueWrite values to nodes on OPC UA server

    Examples

    collapse all

    Create an OPC UA client and connect it to the server.

    uaClient = opcua("opc.tcp://localhost:53530/OPCUA/SimulationServer2");
    connect(uaClient);

    Construct a node object using index and identifier values. The properties listed in the node object output shows that the node object is not yet associated with the server.

    myNode = opcuanode(2,10225)
    myNode = 
    
    OPC UA Node:
    
       Node Information:
                  Name: '2:10225'
           Description: ''
        NamespaceIndex: 2
            Identifier: 10225
              NodeType: 'Unknown'
    
       Hierarchy Information:
                Parent: 'Use this node in read or write operations to associate the node with a client.'
              Children: 0

    Use the node object to write a value to the server and then inspect its properties. The output shows that the node object now has its properties set from the server.

    writeValue(uaClient,myNode,67.4);
    myNode
    myNode = 
    OPC UA Node:
       Node Information:
                          Name: '2:10225'
                   Description: ''
                NamespaceIndex: 2
                    Identifier: 10225
                      NodeType: 'Variable'
    
       Hierarchy Information:
                        Parent: ''
                      Children: 0
    
       Variable Information:
                ServerDataType: 'Float'
            AccessLevelCurrent: 'read/write'
            AccessLevelHistory: 'none'
                   Historizing: 0

    Create an OPC UA client and connect it to the server.

    uaClient = opcua("opc.tcp://localhost:53530/OPCUA/SimulationServer2");
    connect(uaClient);

    Construct an array of node objects using indices and identifier values. Note that the node properties are Unknown because the nodes are not yet associated with the server.

    myNode = opcuanode([3,3,5],{1001,1002,'BooleanDataItem'})
    myNodes = 
    
    1×3 OPC UA Node array:
        index        Name         NsInd    Identifier     NodeType
        -----  -----------------  -----  ---------------  --------
          1    3:1001             3      1001             Unknown
          2    3:1002             3      1002             Unknown
          3    5:BooleanDataItem  5      BooleanDataItem  Unknown
    

    Use the array of node objects to read values from the server. The read operation associates the nodes with the server.

    nodeValues = readValue(uaClient,myNodes)
    nodeValues =
    
      3×1 cell array
    
        {[ 1]}
        {[21]}
        {[ 1]}

    Retrieve information on the array of node objects and note that the node object has its properties set from the server.

    myNodes
    myNodes = 
    
    1×3 OPC UA Node array:
        index        Name         NsInd    Identifier     NodeType
        -----  -----------------  -----  ---------------  --------
          1    3:1001             3      1001             Variable
          2    3:1002             3      1002             Variable
          3    5:BooleanDataItem  5      BooleanDataItem  Variable

    Create an OPC UA client and connect it to the server.

    uaClient = opcua("localhost",51210);
    connect(uaClient);

    Create a known node object and use it to browse its child nodes. Creating the node object by specifying the client associates the node with that client. This example finds all child nodes whose name contain the string Boolean.

    staticNode = opcuanode(5,"StaticData",uaClient);
    booleanNodes = findNodeByName(staticNode,"Boolean","-partial")
    booleanNodes = 
    
    1×3 OPC UA Node array:
        Index       Name        NamespaceIndex    Identifier     NodeType
        -----  ---------------  --------------  ---------------  --------
          1    BooleanDataItem               5  BooleanDataItem  Variable
          2    BooleanArray                  5  BooleanArray     Variable
          3    Boolean                       5  Boolean          Variable

    Limitations

    Version History

    Introduced in R2015b

    expand all