After you get information about your OPC servers, described in Discover Available Data Access Servers you can establish a connection to the server by creating an OPC Client object and connecting that client to the server. These steps are described in the following sections.
Note To run the sample code in the following examples, you must have the Matrikon™ OPC Simulation Server available on your local machine. For information on installing this, see Install the Matrikon OPC Simulation Server. The code requires only minor changes work with other servers.
To create an
opcda object, call the
opcda function specifying the hostname, and
server ID. You retrieved this information using the
(described in Discover Available Data Access Servers).
This example creates an
opcda object to represent
the connection to a Matrikon OPC Simulation Server. The
includes the default
opcda syntax in the
da = opcda('localhost', 'Matrikon.OPC.Simulation.1');
To view a summary of the characteristics of the
you created, enter the variable name you assigned to the object at
the command prompt. For example, this is the summary for the object
The items in this list correspond to the numbered elements in the object summary:
The title of the
the name of the
opcda client object. The default
name for a client object is made up of the
You can change the name of a client object using the
described in Configure OPC Toolbox Data Access Object Properties.
Server Parameters provide
information on the OPC server that the client is associated with.
The host name, server ID, and connection status are provided in this
section. You connect to an OPC server using the
described in Connect a Client to the DA Server.
Object Parameters section
contains information on the OPC Data Access Group (
objects configured on this client. You use group objects to contain
collections of items. Creating group objects is described in Create Data Access Group Objects.
You connect a client to the server using the
Once you have connected to the server, the
in the client summary display will change from
If the client could not connect to the server for some reason (for example, if the OPC server is shut down) an error message will be generated. For information on troubleshooting connections to an OPC server, see Troubleshooting.
Once you have connected the client to the server, you can perform the following tasks:
Get diagnostic information about the OPC server, such
as the server status, last update time, and supported interfaces.
You use the
opcserverinfo function to obtain this
the function reference for more information.
Browse the OPC server name space for information on the available server items. See Browse the OPC DA Server Name Space for details on browsing the server name space.
Create group and item objects to interact with OPC server data. See Create OPC Toolbox Data Access Objects for information on creating group and item objects.
A connected client object allows you to interact with the OPC server to obtain information about the name space of that server. The server name space provides access to all the data points provided by the OPC server by naming each of the data points with a server item, and then arranging those server items into a name space that provides a unique identifier for each server item.
This section describes how you use a connected client object to browse the name space and find information about each server item. These activities are described in the following sections:
Get the DA Server Name Space describes how to obtain a server
name space, or a partial server name space, using the
Get Information about a Specific Server Item describes how to query the server for the properties of a specific server item.
You use the
to retrieve the name space from an OPC server. You must specify the
client object that is connected to the server you are interested in.
The name space is returned to you as a structure array containing
information about each node in the name space.
The example below retrieves the name space of the Matrikon OPC Simulation Server installed on the local host.
da = opcda('localhost','Matrikon.OPC.Simulation.1'); connect(da); ns = getnamespace(da) ns = 3x1 struct array with fields: Name FullyQualifiedID NodeType Nodes
The fields of the structure are described in the following table.
The name of the node, as a string.
The fully qualified item ID of the
node, as a string. The fully qualified item ID is made up of the path
to the node, concatenated with
The type of node.
From the example above, exploring the name space shows.
ns(1) ans = Name: 'Simulation Items' FullyQualifiedID: 'Simulation Items' NodeType: 'branch' Nodes: [8x1 struct] ns(3) ans = Name: 'Clients' FullyQualifiedID: 'Clients' NodeType: 'leaf' Nodes: 
From the information above, the first node is a branch node
'Simulation Items'. Since it is a branch
node, it is most likely not a valid server item. The third node is
a leaf node (containing no other nodes) with a fully qualified ID
'Clients'. Since this node is a leaf node, it
is most likely a server item that can be monitored by creating an
To examine the nodes further down the tree, you need to reference
Nodes field of a branch node. For example,
the first node contained within the
'Simulation Items' node
is obtained as follows.
ns(1).Nodes(1) ans = Name: 'Bucket Brigade' FullyQualifiedID: 'Bucket Brigade.' NodeType: 'branch' Nodes: [14x1 struct]
The returned result shows that the first node of
Items' is a branch node named
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
has a fully qualified ID of
You use the fully qualified ID to refer to that specific node in
the server name space when creating items with OPC Toolbox™ software.
You can use the
flatnamespace function to
flatten a hierarchical name space.
In addition to publishing a name space to all clients, an OPC server provides information about the properties of each of the server items in the name space. These properties provide information on the data format used by the server to store the server item value, a description of the server item, and additional properties configured when the server item was created. The additional properties may include information on the range of the server item, the maximum rate at which the server can update that server item value, etc.
You access a property using a defined set of property IDs. A property ID is simply a number that defines a specific property of the server item. Property IDs are divided into three categories:
OPC Specific Properties (1-99) that every OPC server must provide. The OPC Specific Properties include the server item's Value, Quality, and Timestamp. See OPC Data: Value, Quality, and TimeStamp for more information on understanding OPC data.
OPC Recommended Properties (100-4999) that OPC servers can provide. These properties include maximum and minimum values, a description of the server item, and other commonly used properties. See OPC DA Server Item Properties for more information on OPC Recommended Properties.
Vendor Specific Properties (5000 and higher) that an OPC server can define and use. These properties may be different for each OPC server, and provide a space for OPC server manufacturers to define their own properties.
You query a server item's properties using the
specifying the client object, the fully qualified item ID of the server
item you are interested in, and an optional vector of property IDs
that you wish to retrieve. If you do not specify the property IDs,
all properties defined for that server item are returned to you.
You obtain the fully qualified item ID from the server using
The following example queries the Item Description property
(ID 101) of the server item
'Bucket Brigade.ArrayOfReal8' from
the example in Get the DA Server Name Space.
p = serveritemprops(da, 'Bucket Brigade.ArrayOfReal8', 101) p = PropID: 101 PropDescription: 'Item Description' PropValue: 'Bucket brigade item.'
For a list of OPC Foundation property IDs, see OPC DA Server Item Properties.