OPC UA read task
Read the values of OPC UA nodes at a fixed rate and record them in channels.
An OPC UA read task reads the values of nodes on a server at a fixed rate and records them in channels. For example, it can record the tank pressures and pump speeds of a PLC 50 times a second. The Driver times each read in software.
Before you start, you need a connected OPC UA server.
Node IDs
Each channel of the task reads one node. A node ID has the form
NS=<namespace>;<type>=<identifier>:
Write NS and the type in uppercase. The Driver rejects ns=2;s=Tank1.Pressure. The
browser in the Console fills the node IDs for you.
Create an OPC UA read task
Console
Python
TypeScript
- In the devices toolbar, right-click the server and select Create read task.
- Set Sample rate and Stream rate.
- In the Browser, expand the folders of the server.
- Drag the variables to read into Channels. You can select more than one.
- Click (Start).
The Console creates a channel for each node, named from the browse name of the node. To
choose a name, edit the name of the channel before you start. The Console also creates
an index channel named <server>_time_for_<task>, unless one of the channels already
has an index or you use server timestamps.
Python does not create channels. Create an index channel and a channel for each node first.
import synnax as sy
from synnax import opcua
server = client.devices.retrieve(name="Line 1 PLC")
time = client.channels.create(
name="plc_time", is_index=True, data_type=sy.DataType.TIMESTAMP
)
pressure = client.channels.create(
name="tank_1_pressure", index=time.key, data_type=sy.DataType.FLOAT64
)
task = opcua.ReadTask(
name="Line 1 PLC read",
device=server.key,
sample_rate=50,
stream_rate=25,
channels=[
opcua.ReadChannel(channel=pressure.key, node_id="NS=2;S=Tank1.Pressure")
],
)
client.tasks.configure(task)
task.start()Always pass sample_rate and stream_rate. In Python they default to 10 Hz and 5 Hz,
not to the Console defaults.
TypeScript does not create channels. Create an index channel and a channel for each node first.
import { opcua } from "@synnaxlabs/client";
const [server] = await client.devices.retrieve({ names: ["Line 1 PLC"] });
const time = await client.channels.create({
name: "plc_time",
isIndex: true,
dataType: "timestamp",
});
const pressure = await client.channels.create({
name: "tank_1_pressure",
index: time.key,
dataType: "float64",
});
const task = await client.tasks.create({
name: "Line 1 PLC read",
rack: server.rack,
type: "opc_read",
config: opcua.readConfigZ.parse({
device: server.key,
sampleRate: 50,
streamRate: 25,
channels: [{ channel: pressure.key, nodeId: "NS=2;S=Tank1.Pressure" }],
}),
});
await task.start();Read arrays
Some servers buffer fast samples in an array node. To read the arrays:
- Turn on Array sampling.
- Set Array size to the number of values in each array.
The Driver then reads each node Sample rate / Array size times a second, and spreads
the timestamps of the values evenly over the read period. Sample rate must be equal
to or more than Array size. Each array must have exactly Array size values, or
the Driver drops the frame and shows a warning. Stream rate does not apply in array
mode.
Use server timestamps
By default, the Driver gives the values of each read the time halfway through the read request. To use the time from the server instead:
- Add a node with a DateTime value, such as the source time of the PLC, to the task.
- Turn on Use as index for that channel.
The Driver then uses the value of that node as the timestamp of every channel in the task. Only one channel can be the index.
Task options
TypeScript uses the same fields in camel case, such as sampleRate. See
timing.
Channel reference
The table shows the Console label of each setting, with its Python field under it.
Data types
The Console creates each channel with the data type of its node:
Troubleshooting
- Cause
The node ID is not in the form
NS=<namespace>;<type>=<identifier>.- Fix
Write
NSand the type in uppercase.
- Cause
The server has no node with that ID.
- Fix
Drag the node from the Browser again.
- Cause
An array node has a different number of values than Array size.
- Fix
Set Array size to the length of the array.
- Cause
The server sent a value that the Driver cannot convert. The Driver skips the frame.
- Fix
Check the data type of the node.
- Cause
Another task already reads the node into that channel.
- Fix
Move the channels to one task.
- Cause
The Driver could not browse the server.
- Fix
Check the server connection.
For other problems, see Troubleshoot hardware.