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.
pip install nidaqmxVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade to `nidaqmx==1.4.0` or later for Python 3.9+ compatibility. Always check `requires_python` in PyPI for the specific version you install.
Download and install the latest NI-DAQmx driver from ni.com/downloads. On Windows, you can also try `python -m nidaqmx installdriver` as a convenience command, but direct installation is recommended.
Utilize `nidaqmx.stream_readers` classes (e.g., `AnalogMultiChannelReader`) with pre-allocated NumPy arrays for improved performance in continuous acquisition scenarios.
Always use a `with nidaqmx.Task() as task:` block to ensure tasks are properly initialized and closed, even in case of exceptions. If not using `with`, call `task.close()` explicitly.
Increase the DAQmx task buffer size (`task.timing.cfg_samp_clk_timing(..., samps_per_chan=...)`), read data more frequently, or switch to `nidaqmx.stream_readers` with NumPy arrays for better performance. Ensure you're not trying to read all available samples if the buffer is continuously filling.
Wrap DAQmx task operations in a `with nidaqmx.Task() as task:` statement. This ensures proper resource management and task closure, even if errors occur. If not using `with`, ensure `task.close()` is called manually in a `finally` block.
Ensure all previous DAQmx tasks are properly closed. Restarting the Python script or even the system can sometimes resolve this if a task was not gracefully terminated. Check NI MAX to see if any tasks are running or if the device is reserved.
Increase the size of the buffer (e.g., the NumPy array) you are providing to the read method, ensuring it can accommodate `number_of_samples_per_channel` across all channels being read. Also, ensure the array shape is correct if `verify_array_shape` is enabled on `stream_readers`.