NI digital read task
Read the digital input lines of an NI device into channels.
An NI digital read task reads the digital input lines of one NI device into channels.
Each line gives 0 or 1. For example, it can record limit switches on port0/line0 and
port0/line1 of a USB-6343.
Before you start, you need a configured device.
Ports and lines
NI devices group digital lines into ports. Each channel reads one line, set by its port and line numbers. The device manual lists the ports and lines.
The Driver reads the lines on the computer clock, at the Sample rate. See timing.
Create an NI digital read task
Console
Python
TypeScript
- In the devices toolbar, right-click the device and select Create digital read task.
- Set Sample rate and Stream rate.
- Click Add channel, then enter the port and the line in Port/Line.
- Click (Start).
The Console creates the channels. For a device with the identifier dev1, port 0, line
1 gives dev1_di_0_1, with the index channel dev1_di_time.
Python does not create channels. Create them first.
import synnax as sy
from synnax import ni
dev = client.devices.retrieve(key="<device key>")
time = client.channels.create(
name="dev1_di_time", is_index=True, data_type=sy.DataType.TIMESTAMP
)
limit = client.channels.create(
name="limit_switch", index=time.key, data_type=sy.DataType.UINT8
)
task = ni.DigitalReadTask(
name="Limit switches",
device=dev.key,
sample_rate=100,
stream_rate=10,
channels=[ni.DIChannel(port=0, line=1, channel=limit.key)],
)
client.tasks.configure(task)
task.start()Python creates the task on the embedded Driver of the Core. For a device on another Driver, use the Console or TypeScript.
TypeScript does not create channels. Create them first.
import { ni } from "@synnaxlabs/client";
const dev = await client.devices.retrieve({ key: "<device key>" });
const time = await client.channels.create({
name: "dev1_di_time",
isIndex: true,
dataType: "timestamp",
});
const limit = await client.channels.create({
name: "limit_switch",
index: time.key,
dataType: "uint8",
});
const task = await client.tasks.create({
name: "Limit switches",
rack: dev.rack,
type: "ni_digital_read",
config: ni.digitalReadConfigZ.parse({
device: dev.key,
sampleRate: 100,
streamRate: 10,
channels: [{ port: 0, line: 1, channel: limit.key }],
}),
});
await task.start();Task options
Channel reference
Each channel has a channel, the Synnax channel that records the value as uint8. The
table shows the Console label of each setting, with its Python field under it.
Troubleshooting
- Cause
Two channels use the same line.
- Fix
Change the port or the line of one of them.
For other problems, see Configure an NI device and Troubleshoot hardware.