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. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


Read data synchronously from OPC groups or items


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


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




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

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.


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');
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')

See Also


Introduced before R2006a

Was this topic helpful?