NI-DAQmx Python API

1.4.1 · active · verified Thu Apr 16

The `nidaqmx` package provides a Python API for interacting with the NI-DAQmx driver, enabling development of instrumentation, acquisition, and control applications with NI data acquisition (DAQ) devices. It acts as a highly object-oriented wrapper around the NI-DAQmx C API. The library is actively maintained with frequent releases, with the current stable version being 1.4.1.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to perform a single-point analog voltage acquisition. It initializes a DAQmx task, adds an analog input voltage channel, and reads a single sample. Replace 'Dev1/ai0' with the actual physical channel name of your NI DAQ device, which can be found and configured in NI MAX. Ensure the NI-DAQmx driver is installed before running.

import nidaqmx
import os

# Replace 'Dev1/ai0' with the actual physical channel name of your DAQ device.
# You can find device names in NI MAX. For demonstration, we use an env var.
# For a simulated device, you might use 'SimulatedDAQ/ai0' after configuring it in NI MAX.
PHYSICAL_CHANNEL = os.environ.get('NIDAQMX_DEV_CHANNEL', 'Dev1/ai0')

try:
    with nidaqmx.Task() as task:
        task.ai_channels.add_ai_voltage_chan(PHYSICAL_CHANNEL)
        print(f'Reading voltage from {PHYSICAL_CHANNEL}...')
        data = task.read()
        print(f'Acquired data: {data} V')
except nidaqmx.errors.DaqError as e:
    print(f"NI-DAQmx Error: {e}")
    print("Please ensure your NI-DAQmx driver is installed and your device/channel name is correct in NI MAX.")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →