NI analog read task
Read voltages, currents, temperatures, and other sensor signals from NI devices into channels.
An NI analog read task reads the analog inputs of NI devices into channels. Each channel has a type, such as voltage, current, thermocouple, or bridge, and NI-DAQmx converts the signal to the units of that type. For example, one task can record pressure transducers on an NI 9205 and thermocouples on an NI 9211 in the same chassis.
Before you start, you need configured devices.
Channels and timing
Each channel reads one port of one device. A task can use the modules of one chassis, and all of them must be on the same Driver. The task samples every channel on the device clock, at the Sample rate. See timing.
Only one running task can use the analog inputs of a module. A second task on the same module fails to start with an NI-DAQmx error that says the resource is reserved.
Create an NI analog read task
Console
Python
TypeScript
- In the devices toolbar, right-click a device and select Create analog read task.
- Set Sample rate and Stream rate.
- Click Add channel. In Source, select the Device and the Port.
- In Signal, select the Channel type, then set its fields. See the channel reference.
- Click (Start).
The Console creates the channels. For a device with the identifier dev1, port 0 gives
dev1_ai_0, and the built-in temperature sensor gives dev1_ai_temp. Each device has
an index channel, such as dev1_ai_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_ai_time", is_index=True, data_type=sy.DataType.TIMESTAMP
)
pressure = client.channels.create(
name="tank_pressure", index=time.key, data_type=sy.DataType.FLOAT32
)
task = ni.AnalogReadTask(
name="Tank sensors",
device=dev.key,
sample_rate=1000,
stream_rate=25,
channels=[
ni.AIVoltageChannel(
port=0, min_val=-10, max_val=10, channel=pressure.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. If you open the task in the Console and click Start, the Console replaces your channels with its own.
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_ai_time",
isIndex: true,
dataType: "timestamp",
});
const pressure = await client.channels.create({
name: "tank_pressure",
index: time.key,
dataType: "float32",
});
const task = await client.tasks.create({
name: "Tank sensors",
rack: dev.rack,
type: "ni_analog_read",
config: ni.analogReadConfigZ.parse({
sampleRate: 1000,
streamRate: 25,
channels: [
{
type: "ai_voltage",
device: dev.key,
port: 0,
minVal: -10,
maxVal: 10,
channel: pressure.key,
},
],
}),
});
await task.start();If you open the task in the Console and click Start, the Console replaces your channels with its own.
Tare channels
Tare sets the current value of a channel to zero. The task must be running.
- In the channel list, click Tare on a channel. To tare several channels, select them, right-click, and select Tare.
- The values of those channels start from zero.
Task options
Channel reference
Every channel has a channel, the Synnax channel that records the value, a device,
the key of the device (Device), and a port (Port). The built-in temperature
sensor has no port. In Python, a channel with no device uses the device of the task.
Each table shows the Console label of a setting, with its Python field under it. The
Notes column lists the values that code uses, such as MetersPerSecondSquared. The
Console shows the same values as symbols, such as m/s². Every type except the
temperature types also has Custom scaling.
Electrical
Temperature
Bridge
Force
Pressure
Torque
Vibration and sound
Custom scaling
Channels with Custom scaling convert the raw value before the Driver writes it. In
the Console, the options are in the Scale section of the channel. In code, set
custom_scale to one of these scales:
Every scale except None also has Prescaled units (pre_scaled_units, Volts)
and Scaled units (scaled_units).
Troubleshooting
- Cause
The device cannot sample that slowly.
- Fix
Raise the Sample rate to at least the minimum in the description.
- The task does not start, with an error that says the resource is reserved.
- Cause
Another running task uses the analog inputs of the same module.
- Fix
Stop the other task, or move its channels into this task.
- Cause
Two channels use the same port of one device.
- Fix
Change the port of one of them.
- Cause
A Python channel has no
device, and the task has nodeviceeither.- Fix
Set one of them.
- Cause
The Driver cannot send the samples fast enough. The task shows “Failed to read data”, with this text in the description.
- Fix
Lower the Stream rate, so that each batch holds more samples.
For other problems, see Configure an NI device and Troubleshoot hardware.