Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

opcstruct2array

Convert OPC data from structure to array format

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 by OPC Toolbox™ software 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

See Also

|

Introduced before R2006a

Was this topic helpful?