Contenuto principale

writeValue

Write values to nodes on OPC UA server

Description

writeValue(uaClient,nodeList,values) writes content of values to the nodes identified by nodeList, on the server associated with the connected client uaClient. nodeList can be a single OPC UA node object or an array of node objects.

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

example

Examples

collapse all

Write a value to the Double node on a local OPC UA server.

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

    3.1416


newTS = 

  datetime

   08-Jan-2026 16:57:39

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. You can create node objects using findNodeByName, findNodeById, browseNamespace, or opcuanode. For information on node object functions and properties, see OPC UA Node.

Values specified as a scalar, array, or cell array values. When you write to a single node, use a scalar or array of values. When you write to an array of nodes, use a cell array of values, and the function writes each element of the cell array to the corresponding node.

When you write values to the server, using the MATLAB data type that corresponds to the OPC UA Data Type is recommended. For more information, see OPC UA Server Data Types.

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

Version History

Introduced in R2015b