NI Analog Read Task
Learn how to acquire analog data from NI devices with Synnax.
For the task lifecycle, see Task Basics.
Task Configuration Reference
Channel Types Reference
Accelerometer (ai_accel)
ai_accel) Accelerometer 4-Wire DC Voltage (ai_accel_4_wire_dc_voltage)
ai_accel_4_wire_dc_voltage) Accelerometer Charge (ai_accel_charge)
ai_accel_charge) Bridge (ai_bridge)
ai_bridge) Charge (ai_charge)
ai_charge) Current (ai_current)
ai_current) Current RMS (ai_current_rms)
ai_current_rms) Force Bridge Polynomial (ai_force_bridge_polynomial)
ai_force_bridge_polynomial) Force Bridge Table (ai_force_bridge_table)
ai_force_bridge_table) Force Bridge Two-Point Linear (ai_force_bridge_two_point_lin)
ai_force_bridge_two_point_lin) Force IEPE (ai_force_iepe)
ai_force_iepe) Frequency Voltage (ai_freq_voltage)
ai_freq_voltage) Microphone (ai_microphone)
ai_microphone) Pressure Bridge Polynomial (ai_pressure_bridge_polynomial)
ai_pressure_bridge_polynomial) Pressure Bridge Table (ai_pressure_bridge_table)
ai_pressure_bridge_table) Pressure Bridge Two-Point Linear (ai_pressure_bridge_two_point_lin)
ai_pressure_bridge_two_point_lin) Resistance (ai_resistance)
ai_resistance) RTD (ai_rtd)
ai_rtd) Strain Gauge (ai_strain_gauge)
ai_strain_gauge) Temperature Built-In Sensor (ai_temp_builtin)
ai_temp_builtin) Thermistor IEX (ai_thermistor_iex)
ai_thermistor_iex) Thermistor VEX (ai_thermistor_vex)
ai_thermistor_vex) Thermocouple (ai_thermocouple)
ai_thermocouple) Torque Bridge Polynomial (ai_torque_bridge_polynomial)
ai_torque_bridge_polynomial) Torque Bridge Table (ai_torque_bridge_table)
ai_torque_bridge_table) Torque Bridge Two-Point Linear (ai_torque_bridge_two_point_lin)
ai_torque_bridge_two_point_lin) Velocity IEPE (ai_velocity_iepe)
ai_velocity_iepe) Voltage (ai_voltage)
ai_voltage) Voltage RMS (ai_voltage_rms)
ai_voltage_rms) Voltage with Excitation (ai_voltage_with_excit)
ai_voltage_with_excit)Important Rules
- One task per module -> Only one running task can claim a module at a time.
- Stream rate -> For sample rates under 50 Hz, set the stream rate equal to the sample rate. Above that, keep the stream rate under 50 Hz.
How-To
Console
Python
TypeScript
Configure and run task
import synnax as sy
from synnax import ni
client = sy.Synnax()
# Retrieve devices
v_dev = client.devices.retrieve(name="Mod1_Voltage")
c_dev = client.devices.retrieve(name="Mod2_Current")
tc_dev = client.devices.retrieve(name="Mod1_TC")
# Create index and data channels
ai_time = client.channels.create(
name="ai_time",
is_index=True,
data_type=sy.DataType.TIMESTAMP,
retrieve_if_name_exists=True,
)
voltage_chan = client.channels.create(
name="voltage_chan",
index=ai_time.key,
data_type=sy.DataType.FLOAT32,
retrieve_if_name_exists=True,
)
current_chan = client.channels.create(
name="current_chan",
index=ai_time.key,
data_type=sy.DataType.FLOAT32,
retrieve_if_name_exists=True,
)
temp_chan = client.channels.create(
name="temp_chan",
index=ai_time.key,
data_type=sy.DataType.FLOAT32,
retrieve_if_name_exists=True,
)
# Create and configure task
task = ni.AnalogReadTask(
name="NI Analog Read Task",
sample_rate=sy.Rate.HZ * 100,
stream_rate=sy.Rate.HZ * 25,
channels=[
ni.AIVoltageChannel(
channel=voltage_chan.key,
device=v_dev.key,
port=0,
min_val=-10.0,
max_val=10.0,
terminal_config="Diff",
),
ni.AICurrentChannel(
channel=current_chan.key,
device=c_dev.key,
port=0,
min_val=0.004,
max_val=0.02,
shunt_resistor_loc="Internal",
ext_shunt_resistor_val=249.0,
),
ni.AIThermocoupleChannel(
channel=temp_chan.key,
device=tc_dev.key,
port=0,
units="DegC",
thermocouple_type="J",
cjc=ni.BuiltInCJC(),
),
],
)
client.tasks.configure(task)
# Start task and read data
with task.run():
with client.open_streamer(["voltage_chan", "current_chan", "temp_chan"]) as streamer:
for _ in range(10):
frame = streamer.read()
print(frame)
Edit task configuration
# Retrieve existing task
task = client.tasks.retrieve(name="NI Analog Read Task")
task = ni.AnalogReadTask(internal=task)
# Update task-level configuration
task.config.auto_start = True
task.config.stream_rate = int(sy.Rate.HZ * 50)
# Update voltage channel configuration
task.config.channels[0].port = 1
task.config.channels[0].min_val = -5.0
task.config.channels[0].max_val = 5.0
# Update current channel configuration
task.config.channels[1].port = 2
task.config.channels[1].min_val = 0.002
task.config.channels[1].max_val = 0.01
# Update thermocouple channel configuration
task.config.channels[2].port = 3
task.config.channels[2].thermocouple_type = "K"
# Apply changes
client.tasks.configure(task) Configure and run task
import { Synnax } from "@synnaxlabs/client";
const client = new Synnax();
// Retrieve devices
const [vDev] = await client.devices.retrieve({ names: ["Mod1_Voltage"] });
const [cDev] = await client.devices.retrieve({ names: ["Mod2_Current"] });
const [tcDev] = await client.devices.retrieve({ names: ["Mod1_TC"] });
// Create index and data channels
const aiTime = await client.channels.create(
{
name: "ai_time",
isIndex: true,
dataType: "timestamp",
},
{ retrieveIfNameExists: true },
);
const voltageChan = await client.channels.create(
{
name: "voltage_chan",
index: aiTime.key,
dataType: "float32",
},
{ retrieveIfNameExists: true },
);
const currentChan = await client.channels.create(
{
name: "current_chan",
index: aiTime.key,
dataType: "float32",
},
{ retrieveIfNameExists: true },
);
const tempChan = await client.channels.create(
{
name: "temp_chan",
index: aiTime.key,
dataType: "float32",
},
{ retrieveIfNameExists: true },
);
// Create and configure task
const task = await client.tasks.create({
name: "NI Analog Read Task",
rack: vDev.rack,
type: "ni_analog_read",
config: {
sampleRate: 100,
streamRate: 25,
channels: [
{
type: "ai_voltage",
channel: voltageChan.key,
device: vDev.key,
port: 0,
minVal: -10.0,
maxVal: 10.0,
terminalConfig: "Diff",
},
{
type: "ai_current",
channel: currentChan.key,
device: cDev.key,
port: 0,
minVal: 0.004,
maxVal: 0.02,
shuntResistorLoc: "Internal",
extShuntResistorVal: 249.0,
},
{
type: "ai_thermocouple",
channel: tempChan.key,
device: tcDev.key,
port: 0,
units: "DegC",
thermocoupleType: "J",
cjc: { source: "built_in" },
},
],
},
});
// Start task
await task.start();
// Read data
const streamer = await client.openStreamer([
"voltage_chan",
"current_chan",
"temp_chan",
]);
for (let i = 0; i < 10; i++) {
const frame = await streamer.read();
console.log(frame);
}
// Stop task
await task.stop();
await streamer.close(); Edit task configuration
import { ni } from "@synnaxlabs/client";
// Retrieve existing task
const task = await client.tasks.retrieve({ name: "NI Analog Read Task" });
// Parse the configuration into its typed form
const config = ni.analogReadConfigZ.parse(task.config);
// Update task-level configuration
config.autoStart = true;
config.streamRate = 50;
// Update voltage channel configuration
const voltage = config.channels[0] as ni.AIVoltageChannel;
voltage.port = 1;
voltage.minVal = -5.0;
voltage.maxVal = 5.0;
// Update current channel configuration
const current = config.channels[1] as ni.AICurrentChannel;
current.port = 2;
current.minVal = 0.002;
current.maxVal = 0.01;
// Update thermocouple channel configuration
const thermocouple = config.channels[2] as ni.AIThermocoupleChannel;
thermocouple.port = 3;
thermocouple.thermocoupleType = "K";
// Apply changes
await client.tasks.create({
key: task.key,
rack: task.rack,
name: task.name,
type: task.type,
config,
});