This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

opcda

Create OPC data access object

Syntax

DAobj = opcda(HostID,ServerID)
DAobj = opcda(HostID,ServerID,Name,Value)

Description

example

DAobj = opcda(HostID,ServerID) creates an OPC data access object, DAobj, for the host specified by Host and the OPC server ID specified by ServerID. When you create DAobj, its initial Status property value is 'disconnected'. To communicate with the server, you must connect DAobj to the server with the connect function.

DAobj = opcda(HostID,ServerID,Name,Value) creates an OPC DA object, DAobj, for the host specified by Host and the OPC server ID specified by ServerID, applying the specified property values. If you specify an invalid property name or value, the function does not create an object.

For a complete listing of OPC Toolbox™ functions and properties, type opchelp.

Examples

collapse all

These examples show how to create OPC DA clients for local and remote servers.

Create an OPC DA client for a local server.

daObj1 = opcda('localhost','Dummy.Server.ID');

Create an OPC DA client for a remote server.

daObj2 = opcda('ServerHost1','OPCServer.ID');

Input Arguments

collapse all

OPC server host name or IP address, specified as a character vector or string.

Example: 'localhost'

Data Types: char | string

OPC server ID, specified as a character vector or string.

Example: 'OPCsrvhost'

Data Types: char | string

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Timeout',60

The property name-value pairs can be any format that the set function supports, i.e., name-value pairs, structures, and name-value cell array pairs. You can specify the writeable properties described in Output Arguments, including the following.

Maximum time to wait for completion of instruction to server, specified in seconds.

Example: 60

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

Data to associate with object, specified as any MATLAB data type. UserData stores any data that you want to associate with the object. The object does not use this data directly, but you can use the data for identification or other purposes.

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

Output Arguments

collapse all

OPC DA client, returned as an opcda object, with the following properties.

PropertyDescription
HostDNS host name or IP address of server (read-only)
ServerIDServer identity (read-only)
StatusStatus of connection to OPC server (read-only)
TimeoutMaximum time allowed for all operations on the server to complete
GroupData access group objects contained by client (read-only)
NameDescriptive name for OPC DA client object
TagLabel to associate with OPC DA client object
TypeOPC Toolbox object type (read-only)
UserDataData to associate with OPC DA client object
ErrorFcnCallback function to execute when error event occurs
EventLogEvent information log (read-only)
EventLogMaxMaximum number of events to store in event log
ShutDownFcnCallback function to execute when OPC server shuts down
TimerFcnCallback function to execute when predefined period passes
TimerPeriodPeriod between timer events (read-only while logging)

For information on any of these properties, type opchelp opcda.PropName, for example:

opchelp opcda.TimerPeriod

Introduced before R2006a