{"id":9139,"library":"nidaqmx","title":"NI-DAQmx Python API","description":"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.","status":"active","version":"1.4.1","language":"en","source_language":"en","source_url":"https://github.com/ni/nidaqmx-python","tags":["hardware","data acquisition","daq","ni","national instruments","instrumentation","measurement"],"install":[{"cmd":"pip install nidaqmx","lang":"bash","label":"Install nidaqmx Python package"},{"cmd":"python -m nidaqmx installdriver","lang":"bash","label":"Install NI-DAQmx driver (Windows only, optional helper)"}],"dependencies":[{"reason":"Required for the Python API to function; must be installed separately. The `nidaqmx` package is a wrapper around the C API provided by this driver.","package":"NI-DAQmx driver","optional":false},{"reason":"Used for efficient handling of acquired data, especially with stream readers for performance-critical applications.","package":"numpy","optional":true},{"reason":"A dependency that was updated in recent versions.","package":"hightime","optional":true},{"reason":"Updated in recent versions, crucial for certain type definitions.","package":"nitypes","optional":true},{"reason":"Dependency related to command-line interface utilities shipped with the package.","package":"click","optional":true}],"imports":[{"note":"Standard import for the main package.","symbol":"nidaqmx","correct":"import nidaqmx"},{"note":"The primary class for DAQ operations.","symbol":"Task","correct":"from nidaqmx import Task"},{"note":"Provides enums for various DAQmx settings (e.g., AcquisitionType, TerminalConfiguration).","symbol":"constants","correct":"from nidaqmx import constants"}],"quickstart":{"code":"import nidaqmx\nimport os\n\n# Replace 'Dev1/ai0' with the actual physical channel name of your DAQ device.\n# You can find device names in NI MAX. For demonstration, we use an env var.\n# For a simulated device, you might use 'SimulatedDAQ/ai0' after configuring it in NI MAX.\nPHYSICAL_CHANNEL = os.environ.get('NIDAQMX_DEV_CHANNEL', 'Dev1/ai0')\n\ntry:\n    with nidaqmx.Task() as task:\n        task.ai_channels.add_ai_voltage_chan(PHYSICAL_CHANNEL)\n        print(f'Reading voltage from {PHYSICAL_CHANNEL}...')\n        data = task.read()\n        print(f'Acquired data: {data} V')\nexcept nidaqmx.errors.DaqError as e:\n    print(f\"NI-DAQmx Error: {e}\")\n    print(\"Please ensure your NI-DAQmx driver is installed and your device/channel name is correct in NI MAX.\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"Python 3.9 support was temporarily removed in `1.4.0.dev0` but restored in subsequent `1.4.0.dev1` and `1.4.0` releases. While current versions (`1.4.1`) support Python 3.9+, users on specific pre-release versions of 1.4.0 might have encountered compatibility issues with Python 3.9.","severity":"breaking","affected_versions":"1.4.0.dev0"},{"fix":"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.","message":"The `nidaqmx` Python package requires a separate installation of the NI-DAQmx driver. The Python package is a wrapper around this driver, and will not function without it.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Utilize `nidaqmx.stream_readers` classes (e.g., `AnalogMultiChannelReader`) with pre-allocated NumPy arrays for improved performance in continuous acquisition scenarios.","message":"For continuous or high-speed data acquisition, directly using `task.read()` in a loop can lead to performance issues and `DaqError` exceptions (e.g., 'application is not able to keep up with the hardware acquisition').","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"Failing to explicitly close `nidaqmx.Task` objects can lead to `DaqResourceWarning` messages and potential resource leaks or conflicts. This is especially true if not using the `with` statement.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"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.","cause":"The Python application cannot process or retrieve data from the DAQ device's buffer fast enough, leading to buffer overflows.","error":"nidaqmx.errors.DaqError: The application is not able to keep up with the hardware acquisition. Increasing the buffer size, reading the data more frequently, or specifying a fixed number of samples to read instead of reading all available samples might correct the problem. Status Code: -200279"},{"fix":"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.","cause":"An `nidaqmx.Task` object was created but its `close()` method was not explicitly called before the object was garbage collected, potentially leading to resource leaks.","error":"nidaqmx.errors.DaqResourceWarning: Task of name \"_unnamedTask<0>\" was not explicitly closed before it was destructed."},{"fix":"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.","cause":"Another application or an existing (possibly unclosed) DAQmx task is currently holding exclusive access to the DAQ device or a specific channel.","error":"nidaqmx.errors.DaqError: The specified resource is reserved. The operation could not be completed as specified."},{"fix":"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`.","cause":"The buffer allocated for reading data (e.g., a NumPy array passed to `read_many_sample`) is not large enough to hold the number of samples requested.","error":"nidaqmx.errors.DaqError: Buffer is too small to fit read data. Status Code: -200229"}]}