read

Read data synchronously from OPC groups or items

Syntax

S = read(GObj)
S = read(Iobj)
S = read(GObj,'Source')
S = read(IObj,'Source')

Description

S = read(GObj) and S = read(Iobj) read data for all the items contained in the dagroup object, GObj, or for the vector of daitem objects, IObj. The data is read from the OPC server's cache. S is a structure array containing data for each item in the following fields:

Field Name

Description

Type

ItemID

Fully qualified item name

string

Value

Value

double, string

Quality

Quality of the value

string

TimeStamp

The time that the value and quality was obtained by the device (if this is available), or the time the server updated or validated the value and quality in its cache

Date vector

Error

Error message

string

You can synchronously read from the cache only if the Active property is set to 'on' for both the item and the group that contains the item. A warning is issued if any of the objects passed to read are inactive. An inactive item is still returned in S, but the Quality is set to 'BAD: Out of Service'.

S = read(GObj,'Source') and S = read(IObj,'Source') read data from the source specified by 'Source'. 'Source' can be 'cache' or 'device'. If 'Source' is 'device', data is returned directly from the device. If 'Source' is 'cache', data is returned from the OPC server's cache, which contains a copy of the device data. Note that the Active property is ignored when reading from 'device'. Note also, that reading data from the device can be slow.

When a read operation succeeds, the Value, Quality, and Timestamp properties of the associated items are updated to reflect the values obtained from the read operation.

Examples

Configure a client and a group and item, for the Matrikon™ Simulation Server. Set the update rate for this group to prevent frequent cache updates:

da = opcda('localhost','Matrikon.OPC.Simulation');
connect(da);
grp = addgroup(da,'ExRead');
grp.UpdateRate = 20;
itm = additem(grp,'Random.Real8');

Read twice from the cache, noting that the values are the same each time:

v1 = read(grp)
v2 = read(grp)

Now read twice from the device, noting that the value updates each time:

v3 = read(grp,'device')
v4 = read(grp,'device')
Was this topic helpful?