Solution
To solve this issue, when defining the task use the following syntax:
add_ao_voltage_chan
(
physical_channel,
name_to_assign_to_channel=u'',
min_val=-10.0,
max_val=10.0,
units=<VoltageUnits.VOLTS: 10348>,
custom_scale_name=u'')
With parameters:
- physical_channel (str) – Specifies the names of the physical channels to use to create virtual channels. The DAQmx physical channel constant lists all physical channels on devices and modules installed in the system.
- name_to_assign_to_channel (Optional[str]) – Specifies a name to assign to the virtual channel this function creates. If you do not specify a value for this input, NI-DAQmx uses the physical channel name as the virtual channel name.
- min_val (Optional[float]) – Specifies in units the minimum value you expect to generate.
- max_val (Optional[float]) – Specifies in units the maximum value you expect to generate.
- units (Optional[nidaqmx.constants.VoltageUnits]) – Specifies the units to use to generate voltage.
- custom_scale_name (Optional[str]) – Specifies the name of a custom scale for the channel. If you want the channel to use a custom scale, specify the name of the custom scale to this input and set units to FROM_CUSTOM_SCALE.
Be sure to define min_val and max_val, these parameters are -10 and +10 by default. If you are using a DAQ device that can not generate ± 10 V (example:
USB-6009) you'll receive error -200077.
Example:
import nidaqmx
with nidaqmx.Task() as task:
task.ao_channels.add_ao_voltage_chan('Dev1/ao0','mychannel',-5,5)
print('1 Channel 1 Sample Write: ')
print(task.write(1.0))
task.stop()