Main Content

opcstruct2timeseries

Convert OPC data from structure to time series format

Syntax

TS = opcstruct2timeseries(S)

Description

TS = opcstruct2timeseries(S) converts the OPC data structure S into a cell array of time series objects. S must be a structure in the format that the getdata and opcread functions return. S must contain the fields LocalEventTime and Items. The Items field of S must contain the fields ItemID, Value, Quality, and TimeStamp.

The cell array TS contains as many time series objects as there are unique item IDs in the data structure, with the name of each time series object indicating the item ID. The time series object contains the quality, although this value is offset by 128 from the quality value that the OPC server returns. However, the qualities are the same. Because each logged record might not contain information for every item, the time series objects have only as many data points as there are records containing information about that particular item ID.

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 time series objects and plot each separately:

ts = opcstruct2timeseries(s);
subplot(2,1,1); plot(ts{1});
subplot(2,1,2); plot(ts{2});

Version History

Introduced in R2007b