How To Acquire Analog Input Voltage From NI 9251 Using NIDAQmx Python API

Updated Aug 22, 2024

Environment

Hardware

  • NI-9251

Programming Language

  • Python

This article will explain how to acquire analog input voltage from NI-9251 using NI-DAQmx API.

Note: The NI-9251 is no longer sold by NI.

The following steps will cover the main parts of the Python code.
  1. Import fundamental modules.                                                                                                                                                                                                                                                                               image.png
    • The time module contains sleep function for pausing from an acquisition to another.
    • The nidaqmx module contains the functions for configuring and reading the tasks.
    • The nidaqmx.system module contains the functions for visualizing NI devices connected locally.
    • The AcquisitionType class contains the constants for definiting the sample mode acquisition.
    • The sys and os modules contains the function exit(0) to terminate the application in case of an error
          or in case of keyboard interrupt.
  2. Create the task and define the desired channel, minimum and maximum range.                                                                                                      image.png
    • For the NI-9251 module it is mandatory to explicit its minimum and maximum range [-4.32, 4.32] V as described in the specifications, because add_ai_voltage_chan class assumes the default range [-5, 5] V when this argument is not defined.
  3. Configure timing and sample mode acquisition.                                                                                                                                                                                             image.png
    • For the NI-9251 module it is mandatory to explicit the timing and sample mode acquisition. In this example the configuration consists of 10 samples per channel in a continous acquisition.
  4. Start the task and read the samples, the acquisition can be interrupted by the user pressing Ctrl+C.                                                                                              

image.png