A Python API for interacting with NI-DAQmx
=========== ================================================================================================================================= Info Contains a Python API for interacting with NI-DAQmx. See
GitHub_ for the latest source. Author National Instruments =========== =================================================================================================================================
The nidaqmx package contains an API (Application Programming Interface) for interacting with the NI-DAQmx driver. The package is implemented in Python. This package was created and is supported by NI. The package is implemented as a complex, highly object-oriented wrapper around the NI-DAQmx C API using the
ctypes_ Python library.
nidaqmx 0.5 supports all versions of the NI-DAQmx driver that ships with the C API. The C API is included in any version of the driver that supports it. The nidaqmx package does not require installation of the C header files.
Some functions in the nidaqmx package may be unavailable with earlier versions of the NI-DAQmx driver. Visit the
ni.com/downloads_ to upgrade your version of NI-DAQmx.
nidaqmx supports only the Windows operating system.
nidaqmx supports CPython 2.7, 3.4+, PyPy2, and PyPy3.
Running nidaqmx requires NI-DAQmx or NI-DAQmx Runtime. Visit the
ni.com/downloads_ to download the latest version of NI-DAQmx.
nidaqmx can be installed with
$ python -m pip install nidaqmx
Or easy_install from
$ python -m easy_install nidaqmx
You also can download the project source and run::
$ python setup.py install
The following is a basic example of using an nidaqmx.task.Task object. This example illustrates how the single, dynamic nidaqmx.task.Task.read method returns the appropriate data type.
.. code-block:: python
import nidaqmx with nidaqmx.Task() as task: ... task.aichannels.addaivoltagechan("Dev1/ai0") ... task.read() ... -0.07476920729381246 with nidaqmx.Task() as task: ... task.aichannels.addaivoltagechan("Dev1/ai0") ... task.read(numberofsamplesperchannel=2) ... [0.26001373311970705, 0.37796597238117036] from nidaqmx.constants import LineGrouping with nidaqmx.Task() as task: ... task.dichannels.adddichan( ... "cDAQ2Mod4/port0/line0:1", linegrouping=LineGrouping.CHANPERLINE) ... task.read(numberofsamplesperchannel=2) ... [[False, True], [True, True]]
A single, dynamic nidaqmx.task.Task.write method also exists.
.. code-block:: python
import nidaqmx from nidaqmx.types import CtrTime with nidaqmx.Task() as task: ... task.cochannels.addcopulsechantime("Dev1/ctr0") ... sample = CtrTime(hightime=0.001, lowtime=0.001) ... task.write(sample) ... 1 with nidaqmx.Task() as task: ... task.aochannels.addaovoltagechan("Dev1/ao0") ... task.write([1.1, 2.2, 3.3, 4.4, 5.5], autostart=True) ... 5
Consider using the nidaqmx.stream_readers and nidaqmx.stream_writers classes to increase the performance of your application, which accept pre-allocated NumPy arrays.
Following is an example of using an nidaqmx.system.System object.
.. code-block:: python
import nidaqmx.system system = nidaqmx.system.System.local() system.driverversion DriverVersion(majorversion=16L, minorversion=0L, updateversion=0L) for device in system.devices: ... print(device) ... Device(name=Dev1) Device(name=Dev2) Device(name=cDAQ1) import collections isinstance(system.devices, collections.Sequence) True device = system.devices['Dev1'] device == nidaqmx.system.Device('Dev1') True isinstance(device.aiphysicalchans, collections.Sequence) True physchan = device.aiphysicalchans['ai0'] physchan PhysicalChannel(name=Dev1/ai0) physchan == nidaqmx.system.PhysicalChannel('Dev1/ai0') True physchan.aitermcfgs [, , ] from enum import Enum isinstance(physchan.aiterm_cfgs, Enum) True
The nidaqmx package is supported by NI. For support for nidaqmx, open a request through the NI support portal at
To report a bug or submit a feature request, please use the
GitHub issues page_.
Please include all of the following information when opening an issue:
$ python -c "import sys; print(sys.version)"
$ python -m pip list
this KB article_ to determine the version of NI-DAQmx you have installed.
Documentation is available
Refer to the
NI-DAQmx Help_ for API-agnostic information about NI-DAQmx or measurement concepts.
NI-DAQmx Help installs only with the full version of NI-DAQmx.
nidaqmx is licensed under an MIT-style license (see
LICENSE_). Other incorporated projects may be licensed under different licenses. All licenses allow for non-commercial and commercial use.