opcread
(To be removed) Read logged records from disk to MATLAB workspace
Support for the OPC Data Access (DA) standard will be removed in a future release. Instead use OPC Unified Architecture (UA). See Version History.
Syntax
S = OPCREAD('LogFileName')
S = opcread('LogFileName','PropertyName
','PropertyValue',...)
TSCell = opcread('LogFileName','DataType','timeseries')
[I,V,Q,TS,ET] = opcread('LogFileName','DataType',DType
,...)
Description
S = OPCREAD('LogFileName')
returns all
available records from the OPC log file named LogFileName
. If no
extension is specified as part of LogFileName
, then
.olf
is used.
S
is an NRec
-by-1
structure array, where NRec
is the number of records returned.
S
contains the fields 'LocalEventTime'
and
'Items'
. LocalEventTime
is a date vector
corresponding to the local event time for that record. Items
is
an NItems
-by-1
structure array containing the
fields show below.
Field Name | Description |
---|---|
| The fully qualified item ID, as a character vector. |
| The data value. The data type is dependent on the original
Item's |
| The data quality, as a character vector. |
| The time the value was changed, as a date vector. |
S = opcread('LogFileName','
limits the data read from the specified OPC log file based on the properties and
values provided. Valid property names and property values are defined in the table
below. PropertyName
','PropertyValue',...)
Property Name | Property Value |
---|---|
| Specify the required records as |
| Specify the date range for records as |
| Specify the required item IDs as a character vector,
string, or array. If no records match the required
|
TSCell = opcread('LogFileName','DataType','timeseries')
assigns the data received from the OPC log file to a cell array of time series
objects. TSCell
contains as many time series objects as there are
items in the group, with the name of each time series object set to the item ID. The
quality value stored in the time series object is offset from the quality value
returned by the OPC server by 128. The quality displayed by each is the same.
Because each record logged 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.
[I,V,Q,TS,ET] = opcread('LogFileName','DataType',
assigns the data retrieved from the OPC log file to separate arrays. Valid data
types for DType
,...)DType
are 'double'
,
'single'
, 'int8'
,
'int16'
, 'int32'
,
'uint8'
, 'uint16'
,
'uint32'
, 'logical'
,
'currency'
, 'date'
, and
'cell'
.
I
is a 1
-by-NItem
cell
array of item names.
V
is an NRec
-by-NItem
array of values with the data type specified. If a data type of
'cell'
is specified, V
is a cell array
containing data in the returned data type for each item. Otherwise,
V
is a numeric array of the specified data type.
Note
DType
must be set to 'cell'
when
retrieving records containing character vectors or arrays of values.
Q
is an NRec
-by-NItem
array of quality character vectors for each value in V
.
TS
is an NRec
-by-NItem
array of MATLAB date numbers representing the time when the relevant value and quality
were stored on the OPC server.
ET
is an NRec
-by-1
array
of MATLAB date numbers, corresponding to the local event time for each
record.
Each record logged may not contain information for every item returned, since data for that item may not have changed from the previous update. When data is returned as a numeric matrix, the missing item columns for that record are filled as follows.
| The corresponding value entry is set to the previous value
of that item, or to |
| The corresponding quality entry is set to
|
| The corresponding time stamp entry is set to the first valid time stamp for that record. |
Examples
Configure and start a logging task. Wait for the task to complete.
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 = 'disk'; grp.RecordsToAcquire = 30; grp.LogFileName = 'ExOPCREAD.olf'; start(grp); wait(grp);
Retrieve the first two records into a structure:
s = opcread('ExOPCREAD.olf','Records',[1, 2]);
Retrieve all the data and plot it with a legend:
[itmID,val,qual,tStamp] = opcread('ExOPCREAD.olf', ... 'DataType','double'); plot(tStamp(:,1),val(:,1),tStamp(:,2),val(:,2)); legend(itmID); datetick x keeplimits