Main Content

writeValue

Write values to nodes on OPC UA server

Description

writeValue(uaClient,nodeList,values) writes content of Values, to the nodes identified by nodeList. You can browse for node objects using browseNamespace. You can also create nodes using opcuanode.

If nodeList is a single node, then values is the value written to the node. If nodeList is an array of nodes, values must be a cell array the same size as nodeList, and each element of the cell array is written to the corresponding element of nodeList.

The data type of the value you are writing does not need to match the node ServerDataType property. All values are automatically converted before writing to the server. However, a warning or error is generated if the data type conversion fails. For DateTime data types, you can pass a MATLAB datetime or a number; any numeric value can be interpreted as a MATLAB datetime.

To confirm what size arrays can be written to a node, check the ServerValueRank and ServerArrayDimensions properties of the node:

  • A ServerValueRank value of -3 indicates a scalar or 1-dimensional array, -2 indicates any size array, -1 indicates a scalar, 0 indicates an array with 1 or more dimensions, and a positive value indicates the number of dimensions.

  • If the number of dimensions is fixed, ServerArrayDimensions is an array specifying the maximum possible length of each dimension. A value of 0 for a dimension length indicates no limit.

    For example, if a node supports 2-dimensional arrays of a maximum size of 64-by-32, ServerValueRank has a value of 2 and ServerArrayDimensions [64, 32].

writeValue(nodeList,values) writes content of values, to the nodes identified by nodeList. All nodes must be of the same connected client.

example

Examples

collapse all

Write a new value to the Static Double node on a local server.

uaClient = opcua('localhost', 53530); 
connect(uaClient); 
staticNode = findNodeByName(uaClient.Namespace, 'StaticData', '-once');
scalarNode = findNodeByName(staticNode, 'StaticVariables', '-once');
dblNode = findNodeByName(staticNode, 'Double'); 
writeValue(uaClient, dblNode, 3.14159)
[newVal,newTS] = readValue(uaClient, dblNode)

Write multiple values to a single node.

arrayNode = opcuanode(6, 'DoubleArray', uaClient);
writeValue(arrayNode, [3.14, 1.212]);

Write scalar values to multiple nodes.

multiNodes = opcuanode(6, {'Double','Float'}, uaClient);
writeValue(multiNodes, {34,12});

Input Arguments

collapse all

OPC UA client specified as an OPC UA client object. The client must be connected.

List of nodes specified as an array of node objects or a single node. For information on node object functions and properties, see OPC UA Node.

Values specified as a scalar, array, or cell array values. If writing to a single node, use a scalar or array of values. If writing to an array of nodes, use a cell array of values; each element of the call array is written to the corresponding node.

Version History

Introduced in R2015b