Retrieve OPC HDA Server Namespace
You can use the getNamespace function to retrieve
the namespace from an OPC HDA server. You must specify the client object that is
connected to the server of interest. The namespace is returned as a structure array
containing information about each node in the namespace.
This example retrieves the namespace of the Matrikon OPC Simulation Server installed on the local host.
hdaClient = opchda('localhost','Matrikon.OPC.Simulation.1'); connect(hdaClient); ns = getnamespace(hdaClient)
ns =
3x1 struct array with fields:
Name
FullyQualifiedID
NodeType
Nodes
This table describes the fields in the structure.
| Field | Description |
|---|---|
Name | The name of the node, as a character vector. |
FullyQualifiedID | The fully qualified item ID of the node, as a character vector, often
composed of the path to the node, concatenated with
'.' characters. Use the fully qualified item ID
when creating an item object associated with this node. |
NodeType | The type of node. Can be 'branch' (contains other
nodes) or 'leaf' (contains no other branches).
|
Nodes | Child nodes. Structure array with the same fields as
ns, representing the nodes contained in this
branch of the namespace. |
You can obtain the field descriptions by querying each element in the structure array.
ns(1)
ans =
Name: 'Simulation Items'
FullyQualifiedID: 'Simulation Items'
NodeType: 'branch'
Nodes: [8x1 struct]ns(3)
ans =
Name: 'Clients'
FullyQualifiedID: 'Clients'
NodeType: 'leaf'
Nodes: []In this example, the first node is a branch node called 'Simulation
Items'. Because it is a branch node, it is probably not a valid server
item. The third node is a leaf node (containing no other nodes) with a fully qualified
ID of 'Clients'. Because this node is a leaf node, it is most likely
a server item that can be read. To examine the nodes further down the tree, you need to
reference the Nodes field of a branch node. For example, the
following code obtains the first node contained within the 'Simulation
Items' node.
ns(1).Nodes(1)
ans =
Name: 'Bucket Brigade'
FullyQualifiedID: 'Bucket Brigade.'
NodeType: 'branch'
Nodes: [14x1 struct]The result shows that the first node of 'Simulation Items' is a
branch node named 'Bucket Brigade', and contains 14 nodes.
ns(1).Nodes(1).Nodes(9)
ans =
Name: 'Real8'
FullyQualifiedID: 'Bucket Brigade.Real8'
NodeType: 'leaf'
Nodes: []The ninth node in 'Bucket Brigade' is named
'Real8' and has a fully qualified ID of 'Bucket
Brigade.Real8'. You use the fully qualified ID to refer to that specific
node in the server namespace when referencing items.