The OPC Data Access Standard uses the Microsoft® COM Specification for communication between the OPC server and OPC client. A significant amount of the data exchanged between the OPC server and the client is the value from a server item or the value that a client wants to write to a server item. The Microsoft COM Specification uses Microsoft Variants to send different data types between the client and server. This section discusses how OPC Toolbox™ software converts MATLAB® data types to COM Variants when writing values, and COM Variants to MATLAB data types when reading values.
OPC servers require all values to be written to server items
in COM Variant format. The server also provides the toolbox with COM
Variants when an item's
Value property is read
or returned by the server. The toolbox automatically converts between
the COM Variant type and MATLAB data types according to the table
Table 8-1, Conversion from MATLAB Data Type to COM Variant Data Type
MATLAB Data Type
OPC Server Data Type (COM Variant Type)
Returns the empty matrix (
When you write values to the OPC server using the
you can provide any MATLAB data for the write operation. When
you write data to an OPC server, the following data conversions take
OPC Toolbox software converts the value into the equivalent COM Variant according to Table 8-1, Conversion from MATLAB Data Type to COM Variant Data Type. If any disallowed data type is encountered (for example, if you attempt to write a MATLAB structure), an error will be generated.
The COM Variant is sent to the OPC server.
The OPC server will attempt to convert the COM Variant to the server item's canonical data type, using COM Variant conversion rules. If the conversion fails, the server will return an error.
When an OPC server returns values for a server item to MATLAB,
the OPC server will first convert the value to the COM Variant equivalent
of the data type specified by the
DataType property. If the conversion fails,
an error message is returned with the value. When OPC Toolbox software
receives the value, the COM Variant is converted to the equivalent MATLAB data
type according to Table 8-1, Conversion from MATLAB Data Type to COM Variant Data Type.
The OPC Specification supports arrays of values being written to a server item, and read from a server item. However, a specific server item may not accept an array of values. The behavior of the server in that case is server-dependent. For example, one server may use only the first value of the array. Another server may return an error when attempting to write an array of values to a server item that only supports a scalar value. OPC Toolbox software is not able to determine if a server item accepts only scalar values.
For all of the data types listed in Table 8-1, Conversion from MATLAB Data Type to COM Variant Data Type that can be converted between MATLAB and a COM Variant, scalar and array data are permitted by the toolbox. However, the OPC Specification supports only one-dimensional arrays of data. Higher dimension MATLAB arrays are flattened into a one-dimensional vector when writing data to the OPC server.