Read data from OPC server
Industrial Communication Toolbox
The OPC Read block reads data from one or more items on an OPC server. The read operation takes place synchronously (from the cache or from the device) or asynchronously (from the device).
The block outputs the values (
V) of the requested items in the first
output, and optionally outputs the quality IDs (
Q) and the time stamps
T) associated with each data value in separate outputs. The time stamp
can be output as a serial date number (real-world time), or as the number of seconds from the
start of the simulation (simulation time).
The V,Q,T triple available at the output ports is the last known data for each of the items read by the block. Use the time stamp output to determine when a sample last changed.
You must have an OPC Configuration block in your model to use the OPC Read block. You cannot open the OPC Read parameters dialog without first including an OPC Configuration block in the model.
V — Values of requested items
item value data
Values of the requested items, returned as a vector of type specified by the Value port data type parameter.
Q — Quality of requested items
Quality of requested items, returned as a vector of
details on the quality format, see OPC Quality. This port is optional, depending on the setting of the
Show quality port parameter.
T — Time stamps of requested items
seconds | date number
The time stamp can be output as a vector of serial date number (real-world time), or as the number of seconds from the start of the simulation (simulation time). This port is optional, depending on the setting of the Show timestamp port as parameter.
Import from Workspace — Import block settings from
dagroup object in workspace
The import dialog allows you to import settings for the OPC Read
block from a
dagroup object in the MATLAB base workspace. The client,
item IDs, and sample time are updated based on the properties of the imported group. The
Value port data type is also set if all items in the group have
Client — Define OPC client for block
Defines the OPC client associated with this block. You can add clients to the list using Configure OPC Clients. For more information, see Use the OPC Client Manager.
Item IDs — List of OPC server items
Shows the items to be read from the specified server. You can add items to the list using Add Items, or delete items using Delete. You can change the order of the items in the list using Move Up or Move Down. The order of the items determines the order of their values in the block outputs.
Read mode — Set synchronous reading
Synchronous (cache) (default) |
Synchronous (device) |
Defines the read mode for this block. Available options are
Synchronous (cache), or
Synchronous (device). Synchronous reads are generally more
reliable, but have slightly more overhead than asynchronous reads.
Sample time — Sample time for block reads
0.5 (default) | numeric
Defines the sample time for the block, in seconds. For synchronous reads, data is read from the server at the specified sample time. For asynchronous reads, the sample time setting defines the update rate for data change events.
Value port data type — Data type for value
double (default) |
Defines the data type for the value output port. The OPC server is responsible for
converting all data to the required type. See
For items with a
logical on the server, you can set the OPC Read
block to output a numeric value type:
When the item value is
true, the OPC Read block value output is
-1for signed data types, or the maximum value for unsigned integers.
When the item value is
false, the block value output is
Show quality port — Add quality output to block
on (default) | off
When checked (on), the quality IDs of all the items are output in the second port as
a vector of unsigned 16-bit integers (
uint16). Use the OPC Quality Parts block to separate the quality ID
into component parts.
Show timestamp port as — Set time stamp basis
on (default) | off
When checked (on), the timestamps for each of the items are output in the last port as a vector of doubles. You can choose whether to output the timestamps as Seconds since start (i.e., simulation time) or as Serial date numbers (i.e., real-world time).