Main Content

OPC Read

Read data from OPC server

  • Library:
  • OPC Toolbox

  • OPC_Read block

Description

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.

Note

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.

Ports

Output

expand all

Values of the requested items, returned as a vector of type specified by the Value port data type parameter.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean

Quality of requested items, returned as a vector of uint16. For details on the quality format, see OPC Quality. This port is optional, depending on the setting of the Show quality port parameter.

Data Types: uint16

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.

Data Types: double

Parameters

expand all

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 the same DataType property.

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.

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.

Defines the read mode for this block. Available options are Asynchronous, Synchronous (cache), or Synchronous (device). Synchronous reads are generally more reliable, but have slightly more overhead than asynchronous reads.

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.

Defines the data type for the value output port. The OPC server is responsible for converting all data to the required type. See DataType.

Note

For items with a CanonicalDataType of 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 -1 for signed data types, or the maximum value for unsigned integers.

  • When the item value is false, the block value output is 0.

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.

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).

Introduced before R2006a