Main Content


(To be removed) Read data synchronously from OPC DA groups or items

Support for the OPC Data Access (DA) standard will be removed in a future release. Instead use OPC Unified Architecture (UA). See Compatibility Considerations.



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, and assigned to the structure S.

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,Src) and S = read(IObj,Src) read data from the source specified by Src. Src can be 'cache' or 'device'. If Src is 'device', data is returned directly from the device. If Src 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.


collapse all

This example reads from a device and cache.

Configure a client, 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');
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')

Input Arguments

collapse all

OPC DC group, specified as a dagroup object.

Example: GObj = addgroup()

OPC DA items, specified as an array of opcda item objects.

Example: IObj = additem()

Data source to read, specified as 'device' or 'cache'.

Example: 'device'

Data Types: char | string

Output Arguments

collapse all

Read data, returned as a structure containing data for each item in the following fields:

Field Name




Fully qualified item name

character vector



double, character vector


Quality of the value

character vector


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 message

character vector

Version History

Introduced before R2006a

expand all

See Also