0.60

ReferenceHardwareNational InstrumentsAnalog write task

NI analog write task

Write command channel values to the analog outputs of an NI device.

An NI analog write task writes the values of command channels to the analog outputs of one NI device. For example, a setpoint on a schematic can drive a proportional valve from ao0 of a USB-6343.

Each output has a command channel and a state channel. Each command writes the last value of every output of the task in one call.

Before you start, you need a configured device.

Create an NI analog write task

Enterprise
  1. In the devices toolbar, right-click the device and select Create analog write task.
  2. Set State update rate.
  3. Click Add channel. In Source, select the Port.
  4. In Signal, select the Channel type, then set its fields. See the channel reference.
  5. Click (Start).

The Console creates the channels. For a device with the identifier dev1, port 0 gives the command channel dev1_ao_0_cmd with the index dev1_ao_0_cmd_time, and the state channel dev1_ao_0_state with the index dev1_ao_state_time.

Task options

Console label Python field Default Notes
Device device The key of the device.
State update rate state_rate 10 Hz Up to 50,000 Hz in the Console.
Data saving data_saving_disabled On See data saving.
Auto start auto_start Off Starts the task each time the Driver starts.

Channel reference

Every channel has a port (Port), a cmd_channel, and a state_channel.

Each table shows the Console label of a setting, with its Python field under it. Voltage and current channels also have Custom scaling.

Voltage

Python AOVoltageChannelTypeScript ao_voltageNI-DAQmx

Outputs a voltage.

Setting Default Notes
Range min_val, max_val 0 to 1 In volts.

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:

Console option Python class Fields
None NoneScale No scaling. This is the default.
Linear LinearScale Slope (slope, 1) and Y-intercept (y_intercept, 0).
Map MapScale Pre-scaled min and max to Scaled min and max (pre_scaled_min, pre_scaled_max, scaled_min, scaled_max).
Polynomial PolynomialScale Forward coefficients (forward_coeffs) and Reverse coefficients (reverse_coeffs), from c0 up.
Table TableScale Pre-scaled and Scaled pairs (pre_scaled_vals, scaled_vals). A CSV file can fill them.

Every scale except None also has Prescaled units (pre_scaled_units, Volts) and Scaled units (scaled_units).

Troubleshooting

  • The outputs stop changing after a command.
    Cause

    A command was outside the Range of its channel. NI-DAQmx rejects it with no message, and because each command writes every output, all later commands fail too. The state channels still show the commands that were not written.

    Fix

    Send a value inside the range to that channel. The task then writes again.

  • Port ... has already been used on another channel
    Cause

    Two channels use the same port.

    Fix

    Change the port of one of them.

For other problems, see Configure an NI device and Troubleshoot hardware.