NI digital write task
Write command channel values to the digital output lines of an NI device.
An NI digital write task writes the values of command channels to the digital output
lines of one NI device. For example, a valve on a schematic can switch port0/line0 of
a USB-6343 through a relay.
Each line has a command channel and a state channel. Send 1 to turn a line on and 0 to turn it off.
Before you start, you need a configured device.
The Console gives the digital write tasks of a device one state index channel, and only one writer can hold an index channel. So only one of these tasks can run on a device at a time, even when the tasks use different lines. A second task stops right after it starts, with an error that names the running task. Tasks from a client library have this limit only when they share an index channel.
Create an NI digital 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 device and select Create digital write task.
- Set State update rate.
- The task starts with one channel. To add more, click Add channel, or click a free line in the map above the channel list. See ports.
- In the channel list, enter the Port and the Line of each channel.
- Click (Start).
The Console creates the channels. For a device with the identifier dev1, port 0, line
0 gives the command channel dev1_do_0_0_cmd with the index dev1_do_0_0_cmd_time, and
the state channel dev1_do_0_0_state with the index dev1_do_state_time.
Python does not create channels. Create them first.
import synnax as sy
from synnax import ni
dev = client.devices.retrieve(key="<device key>")
state_time = client.channels.create(
name="dev1_do_state_time", is_index=True, data_type=sy.DataType.TIMESTAMP
)
state = client.channels.create(
name="valve_1_state", index=state_time.key, data_type=sy.DataType.UINT8
)
cmd_time = client.channels.create(
name="valve_1_cmd_time", is_index=True, data_type=sy.DataType.TIMESTAMP
)
cmd = client.channels.create(
name="valve_1_cmd", index=cmd_time.key, data_type=sy.DataType.UINT8
)
task = ni.DigitalWriteTask(
name="Valves",
device=dev.key,
channels=[
ni.DOChannel(port=0, line=0, cmd_channel=cmd.key, state_channel=state.key)
],
)
client.tasks.configure(task)
task.start()TypeScript does not create channels. Create them first, as in the Python example.
import { ni } from "@synnaxlabs/client";
const dev = await client.devices.retrieve({ key: "<device key>" });
const task = await client.tasks.create({
name: "Valves",
rack: dev.rack,
type: "ni_digital_write",
config: ni.digitalWriteConfigZ.parse({
device: dev.key,
channels: [
{
port: 0,
line: 0,
cmdChannel: cmd.key,
stateChannel: state.key,
},
],
}),
});
await task.start();Task options
Channel reference
Each channel has a cmd_channel and a state_channel. The table shows the Console
label of each setting, with its Python field under it.
Troubleshooting
- Cause
Two enabled channels use the same line.
- Fix
Change the Port or the Line of one of the channels, or disable one of them.
- Cause
The channel uses a port that the device does not have, or a port that cannot write output.
- Fix
Change the Port of the channel. The line map above the channel list shows the ports of the device.
- Cause
The Line of the channel is past the last line of its port.
- Fix
Change the Line to a number in the range of the message.
- Cause
Another running task writes to the same index channel. The error names that task.
- Fix
Stop the other task, or move its channels into this task.
For other problems, see Configure an NI device and Troubleshoot hardware.