OPC UA write task
Write a value to an OPC UA node each time a command channel gets a new value.
An OPC UA write task writes a value to a node each time you write a value to a command channel. For example, a valve on a schematic can set a PLC setpoint. If you write several values at once, the task writes only the last one. The task writes single values, not arrays.
The task has no state channels. To see the value on the server, read the node back with an OPC UA read task. Before you start, you need a connected OPC UA server.
Create an OPC UA write task
When you create command channels with a client library, give each one its own index channel. A writer that holds several commands on one index must write all of them in every frame.
Console
Python
TypeScript
- In the devices toolbar, right-click the server and select Create write task.
- In the Browser, expand the folders of the server.
- Drag the variables to write into Channels.
- Click (Start).
The Console creates a command channel for each node, named <node>_cmd, and its index
<node>_cmd_time. To choose another name, right-click the channel and select Rename
before you start.
Python does not create channels. Create the command channel and its index first.
import synnax as sy
from synnax import opcua
server = client.devices.retrieve(name="Line 1 PLC")
cmd_time = client.channels.create(
name="pump_setpoint_cmd_time", is_index=True, data_type=sy.DataType.TIMESTAMP
)
cmd = client.channels.create(
name="pump_setpoint_cmd", index=cmd_time.key, data_type=sy.DataType.FLOAT64
)
task = opcua.WriteTask(
name="Line 1 PLC write",
device=server.key,
channels=[
opcua.WriteChannel(cmd_channel=cmd.key, node_id="NS=2;S=Pump1.Setpoint")
],
)
client.tasks.configure(task)
task.start()TypeScript does not create channels. Create the command channel and its index first.
import { opcua } from "@synnaxlabs/client";
const [server] = await client.devices.retrieve({ names: ["Line 1 PLC"] });
const cmdTime = await client.channels.create({
name: "pump_setpoint_cmd_time",
isIndex: true,
dataType: "timestamp",
});
const cmd = await client.channels.create({
name: "pump_setpoint_cmd",
index: cmdTime.key,
dataType: "float64",
});
const task = await client.tasks.create({
name: "Line 1 PLC write",
rack: server.rack,
type: "opc_write",
config: opcua.writeConfigZ.parse({
device: server.key,
channels: [{ cmdChannel: cmd.key, nodeId: "NS=2;S=Pump1.Setpoint" }],
}),
});
await task.start();The OPC UA write task has one option, Auto start (auto_start), which starts the
task each time the Driver starts. For node IDs, see
node IDs.
Channel reference
The table shows the Console label of each setting, with its Python field under it.
Data types
The Driver writes each value with the OPC UA type that matches the data type of the command channel:
A uint8 channel writes a Boolean, so the task cannot write to a Byte node.
Troubleshooting
- Cause
The data type of the command channel does not match the type of the node.
- Fix
Use the data type from the table. For example, a Double node needs a
float64channel.
- Cause
The node is read only on the server, or the user of the connection cannot write to it.
- Fix
Make the node writable on the server, or connect with a user that can write to it.
- Cause
The node ID is not in the form
NS=<namespace>;<type>=<identifier>.- Fix
Write
NSand the type in uppercase.
- The server disconnects during a write.
- Cause
The Driver connects again once and repeats the write. If the second write fails, the task shows the error.
For other problems, see Troubleshoot hardware.