Main Content

opcstruct2array

(To be removed) Convert OPC data from structure to array format

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

Syntax

[ItmID,Val,Qual,TStamp,EvtTime] = opcstruct2array(S)
[ItmID,Val,Qual,TStamp,EvtTime] = opcstruct2array(S,'DataType')

Description

[ItmID,Val,Qual,TStamp,EvtTime] = opcstruct2array(S) converts the OPC data structure S into separate arrays for the item ID, value, quality, time stamp, and event time. S must be a structure as returned by the getdata and opcread functions. S must contain the fields LocalEventTime and Items. The Items field of S must contain the fields ItemID, Value, Quality, and TimeStamp.

ItmID is a 1-by-nItm cell array containing the item IDs of all unique items found in the ItemID field of the Items structures in S.

Val is an nRec-by-nItm array of doubles containing the value of each item in ItmID, at each time specified by TStamp.

Qual is an nRec-by-nItm cell array of character vectors containing the quality of each value in Val.

TStamp is an nRec-by-nItm array of doubles containing the time stamp for each value in Val.

EvtTime is nRec-by-1 array of doubles containing the local time each data change event occurred.

Each row of Val represents data from one record received at the corresponding entry in EvtTime, while each column of Val represents the time series for the corresponding item ID in ItmID.

[ItmID,Val,Qual,TStamp,EvtTime] = opcstruct2array(S,'DataType') uses the data type specified by the character vector 'DataType' for the value array. Valid data types are 'double', 'single', 'int8', 'int16', 'int32', 'uint8', 'uint16', 'uint32', 'logical', 'currency', 'date', and 'cell'.

Examples

Configure and start a logging task for 30 seconds of data:

da = opcda('localhost', 'Matrikon.OPC.Simulation');
connect(da);
grp = addgroup(da, 'ExOPCREAD');
itm1 = additem(grp, 'Triangle Waves.Real8');
itm2 = additem(grp, 'Saw-Toothed Waves.Int2');
grp.LoggingMode = 'memory';
grp.UpdateRate = 0.5;
grp.RecordsToAcquire = 60;
start(grp);
wait(grp);

Retrieve the records into a structure:

s = getdata(grp);

Convert the structure into a double array and plot it with a legend:

[itmID, val, qual, tStamp] = opcstruct2array(s,'double');
plot(tStamp(:,1), val(:,1), tStamp(:,2), val(:,2));
legend(itmID);
datetick x keeplimits

Version History

Introduced before R2006a

expand all

See Also

|