OPC Toolbox software provides all three OPC Data Access Standard mechanisms for reading data from an OPC server. The toolbox uses these three mechanisms in various ways to return data from those functions, to provide event information, to update properties of toolbox objects, and to log data to memory and disk.
The way OPC Toolbox software uses the three OPC Data Access mechanisms is described in the following sections:
• “OPC Data Returned from Synchronous Read Operations” on page 8-4 describes the synchronous read mechanism used by the read function.
• “OPC Data Returned in Asynchronous Read Operations” on page 8-4 describes the asynchronous read mechanism used by the readasync function.
• “OPC Data Returned from a Data Change Event” on page 8-5 describes the data change event notification mechanism used with subscribed, active groups, with the refresh function, and by the toolbox logging process.
8
Working with OPC DataOPC Data Returned from Synchronous Read Operations
You initiate a synchronous read operation by using the read function. When you read from a dagroup object, all items in that group are read in one instruction.
You can specify the source of a synchronous read operation as 'cache' or 'device'.
If you read from the cache, the server simply returns the value in the cache. If you read from the device, the server will get the value from the device and update the cache before sending the Value, Quality, and TimeStamp information back as part of the read operation.
OPC Toolbox software returns the data in the output structure from the read operation.
Each element of the structure array contains information about one of the items read.
Whenever you read values using the read function, the toolbox updates the daitem object's Value, Quality, and TimeStamp properties with the values read from the server.
OPC Data Returned in Asynchronous Read Operations
You initiate an asynchronous read operation by using the readasync function. When you read from a dagroup object, all items in that group are read in one instruction.
Asynchronous read operations always use the device as the source of the read. Whenever you send an asynchronous read request, the server will read values from the devices connected to the items. The server will then update that server item's Value, Quality, and TimeStamp in the cache before sending an asynchronous read event back to the toolbox.
OPC Toolbox software returns information from an asynchronous read operation via the read async event structure. This event structure is stored in the opcda client object's event log, which you can access using the EventLog property of the client. The event structure is also passed to the callback function defined in the ReadAsyncFcn property of the dagroup object that initiated the asynchronous read operation. For more information on the format of the event structures, see “Event Structures” on page 9-9.
When an asynchronous read operation succeeds, in addition to returning data via the event structures, the toolbox also updates the Value, Quality, and TimeStamp properties of the associated daitem object.
OPC Data: Value, Quality, and TimeStamp
8-5 OPC Data Returned from a Data Change Event
The third mechanism for getting data from an OPC server involves the data change event. The OPC server generates a data change event for a group at the period specified by the UpdateRate property when the Value or Quality of an item in the group changes.
You do not have to specifically request a data change event, because the OPC server will automatically generate a data change event. However, you can force a data change event at any time using the refresh function.
An OPC server will generate a data change event only for an active, subscribed group containing active items. You control the active status of dagroup objects and daitem objects by setting their Active property. You control the subscribed status of a dagroup object by setting the Subscription property of the dagroup object.
The following points describe how an OPC server generates a data change event:
• When you configure a group, you define the rate at which the server must scan items in that group. This rate is controlled by the UpdateRate property for a dagroup object. The server updates the Value, Quality, and TimeStamp values in the cache for the items in that group at the required update rate. Note that if a device cannot provide a value in that time, the server may reduce the rate at which it updates the value in the server cache for that item.
• If you set an item's Active property to 'off', the server will stop scanning that item. You must set the Active property to 'on' for the server to scan the item again.
• If you set the Active property of a dagroup object to 'off', the server will stop scanning all items in that group. You can still perform asynchronous read operations, and synchronous read operations from the 'device', but no operations involving the server cache can be performed. You must set the Active property to 'on' to enable operations involving the server cache.
• If the Subscription property for a dagroup object is set to 'on', then every time the server updates cache values for the items in that group, the server will send a data change event for that group, to the client object. The data change event contains information about every item whose Value, Quality, or TimeStamp updated.
• If you set the Subscription property to 'off', then the OPC server will not generate data change events. However, as long as the group is still active, the OPC server will continue to scan all active items for that group, at the rate specified by the UpdateRate property.
When the OPC server generates a data change event, OPC Toolbox software performs the following tasks:
8
Working with OPC Data1 The daitem object Value, Quality, and TimeStamp properties are updated for each item that is included in the data change event.
2 The callback function defined by the DataChangeFcn property of the dagroup object is called. For more information on callbacks, see “Create and Execute Callback Functions” on page 9-15.
3 If the group is logging data, the data change event is stored in memory and/or on disk. For more information on logging, see “Log OPC Server Data” on page 7-15.
4 If the group is logging, and the number of records acquired is a multiple of the RecordsAcquiredFcnCount property of the dagroup object, then the callback function defined by the RecordsAcquiredFcn property of the dagroup object is called. For more information on callbacks, see “Create and Execute Callback Functions” on page 9-15.
For more information on the structure of a data change event, see “Data Fields for Cancel Async, Data Change, Error, Read Async, and Write Async Events” on page 9-9.