nidaqmx


Namenidaqmx JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/ni/nidaqmx-python
SummaryNI-DAQmx Python API
upload_time2024-11-08 17:24:39
maintainerZach Hindes
docs_urlNone
authorNI
requires_python<4.0,>=3.8
licenseMIT
keywords nidaqmx nidaq daqmx daq
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            +------------+-----------------------------------------------------------+
| **Info**   | Contains a Python API for interacting with NI-DAQmx. See  | 
|            | `GitHub <https://github.com/ni/nidaqmx-python/>`_ for the |
|            | latest source.                                            |
+------------+-----------------------------------------------------------+
| **Author** | National Instruments                                      |
+------------+-----------------------------------------------------------+

.. contents:: Table of Contents
   :depth: 1
   :backlinks: none

About
=====

The **nidaqmx** package allows you to develop instrumentation, acquisition, and 
control applications with NI data acquisition (DAQ) devices in Python.

Documentation
-------------

You can find the latest API documentation for the **nidaqmx** package on
`Read the Docs <http://nidaqmx-python.readthedocs.io/en/stable>`_.

Refer to the
`NI-DAQmx User Manual <https://www.ni.com/docs/en-US/bundle/ni-daqmx/>`_ for
an overview of NI-DAQmx, key concepts, and measurement fundamentals. The
NI-DAQmx Help also installs locally with the full version of NI-DAQmx. Refer to
`this Knowledge Base (KB) <http://digital.ni.com/express.nsf/bycode/exagg4>`_
for more information.

Implementation
--------------

The package is implemented in Python as an object-oriented wrapper around the
NI-DAQmx C API using the
`ctypes <https://docs.python.org/3/library/ctypes.html>`_ Python library.

Supported NI-DAQmx Driver Versions
----------------------------------

**nidaqmx** supports all versions of NI-DAQmx. Some functions in the **nidaqmx**
package may be unavailable with earlier versions of the NI-DAQmx driver. Refer
to the Installation section for details on how to install the latest version of
the NI-DAQmx driver.

Operating System Support
------------------------

**nidaqmx** supports Windows and Linux operating systems where the NI-DAQmx
driver is supported. Refer to
`NI Hardware and Operating System Compatibility <https://www.ni.com/r/hw-support>`_
for which versions of the driver support your hardware on a given operating
system.

Python Version Support
----------------------

**nidaqmx** supports CPython 3.8+ and PyPy3.

Installation
============

You can use `pip <http://pypi.python.org/pypi/pip>`_ to download **nidaqmx** from
`PyPI <https://pypi.org/project/nidaqmx/>`_ and install it::

  $ python -m pip install nidaqmx

Automatic Driver Installation
-----------------------------

Running **nidaqmx** requires NI-DAQmx to be installed. The **nidaqmx** module
ships with a command-line interface (CLI) to streamline the installation
experience. You can install the NI-DAQmx driver using the following command::

  $ python -m nidaqmx installdriver

On Windows, this command will download and launch an online streaming installer
from ni.com. On Linux, this will download the repository registration package
for your Linux distribution and install the driver using your package manager.

Manual Driver Installation
--------------------------

Visit `ni.com/downloads <http://www.ni.com/downloads/>`_ to download the latest
version of NI-DAQmx. None of the recommended **Additional items** are required
for **nidaqmx** to function, and they can be removed to minimize installation
size. It is recommended you continue to install the **NI Certificates** package
to allow your Operating System to trust NI built binaries, improving your
software and hardware installation experience.

Getting Started
===============
In order to use the **nidaqmx** package, you must have at least one DAQ
(`Data Acquisition <https://www.ni.com/en/shop/data-acquisition.html>`_) device
installed on your system. Both physical and simulated devices are supported. The
examples below use an X Series DAQ device (e.g.: PXIe-6363, PCIe-6363, or
USB-6363). You can use **NI MAX** or **NI Hardware Configuration Utility** to
verify and configure your devices.

Finding and configuring device name in **NI MAX**:

.. image:: https://raw.githubusercontent.com/ni/nidaqmx-python/ca9b8554e351a45172a3490a4716a52d8af6e95e/max_device_name.png
  :alt: NI MAX Device Name
  :align: center
  :width: 800px

Finding and configuring device name in **NI Hardware Configuration Utility**:

.. image:: https://raw.githubusercontent.com/ni/nidaqmx-python/ca9b8554e351a45172a3490a4716a52d8af6e95e/hwcu_device_name.png
  :alt: NI HWCU Device Name
  :align: center
  :width: 800px

Python Examples
===============

You can find a variety of examples in the GitHub repository in the
`nidaqmx-python examples <https://github.com/ni/nidaqmx-python/tree/master/examples>`_
directory. For best results, use the examples corresponding to the version of
**nidaqmx** that you are using. For example, if you are using version 1.0.0,
check out the
`examples directory in the 1.0.0 tag <https://github.com/ni/nidaqmx-python/tree/1.0.0/examples>`_.
Newer examples may demonstrate features that are not available in older versions
of **nidaqmx**.

Key Concepts in NI-DAQmx
=========================

Tasks
-----
A task is a collection of one or more virtual channels with timing, triggering, and other properties.
Refer to `NI-DAQmx Task <https://www.ni.com/docs/en-US/bundle/ni-daqmx/page/tasksnidaqmx.html>`_ for more information.

Example code to create a task:

.. code-block:: python

  >>> import nidaqmx
  >>> with nidaqmx.Task() as task:
  ...     pass

Virtual Channels
----------------
Virtual channels, or sometimes referred to generically as channels, are software entities that encapsulate the physical channel
along with other channel specific information (e.g.: range, terminal configuration, and custom scaling) that formats the data.
A physical channel is a terminal or pin at which you can measure or generate an analog or digital signal. A single physical channel
can include more than one terminal, as in the case of a differential analog input channel or a digital port of eight lines.
Every physical channel on a device has a unique name (for instance, cDAQ1Mod4/ai0, Dev2/ao5, and Dev6/ctr3) that follows the
NI-DAQmx physical channel naming convention.
Refer to `NI-DAQmx Channel <https://www.ni.com/docs/en-US/bundle/ni-daqmx/page/chans.html>`_ for more information.

Example code that adds an analog input channel to a task, configures the range, and reads data:

.. code-block:: python

  >>> import nidaqmx
  >>> with nidaqmx.Task() as task:
  ...     task.ai_channels.add_ai_voltage_chan("Dev1/ai0", min_val=-10.0, max_val=10.0)
  ...     task.read()
  ...
  AIChannel(name=Dev1/ai0)
  -0.14954069643238624

Example code that adds multiple analog input channels to a task, configures their range, and reads data:

.. code-block:: python

  >>> import nidaqmx
  >>> with nidaqmx.Task() as task:
  ...     task.ai_channels.add_ai_voltage_chan("Dev1/ai0", min_val=-5.0, max_val=5.0)
  ...     task.ai_channels.add_ai_voltage_chan("Dev1/ai1", min_val=-10.0, max_val=10.0)
  ...     task.read()
  ...
  AIChannel(name=Dev1/ai0)
  AIChannel(name=Dev1/ai1)
  [-0.07477034821619312, 0.8642841883602405]

Timing
------
You can use software timing or hardware timing to control when a signal is acquired or generated.
With hardware timing, a digital signal, such as a clock on your device, controls the rate of acquisition or generation.
With software timing, the rate at which the samples are acquired or generated is determined by the software and operating system
instead of by the measurement device. A hardware clock can run much faster than a software loop.
A hardware clock is also more accurate than a software loop.
Refer to `Timing, Hardware Versus Software <https://www.ni.com/docs/en-US/bundle/ni-daqmx/page/hardwresoftwretiming.html>`_ for more information.

Example code to acquire finite amount of data using hardware timing:

.. code-block:: python

  >>> import nidaqmx
  >>> from nidaqmx.constants import AcquisitionType, READ_ALL_AVAILABLE
  >>> with nidaqmx.Task() as task:
  ...     task.ai_channels.add_ai_voltage_chan("Dev1/ai0")
  ...     task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=10)
  ...     data = task.read(READ_ALL_AVAILABLE)
  ...     print("Acquired data: [" + ", ".join(f"{value:f}" for value in data) + "]")
  ...
  AIChannel(name=Dev1/ai0)
  Acquired data: [-0.149693, 2.869503, 4.520249, 4.704886, 2.875912, -0.006104, -2.895596, -4.493698, -4.515671, -2.776574]

TDMS Logging
------------
Technical Data Management Streaming (TDMS) is a binary file format that allows for high-speed data logging.
When you enable TDMS data logging, NI-DAQmx can stream data directly from the device buffer to the hard disk.
Refer to `TDMS Logging <https://www.ni.com/docs/en-US/bundle/ni-daqmx/page/datalogging.html>`_ for more information.

Example code to acquire finite amount of data and log it to a TDMS file:

.. code-block:: python

  >>> import nidaqmx
  >>> from nidaqmx.constants import AcquisitionType, LoggingMode, LoggingOperation, READ_ALL_AVAILABLE
  >>> with nidaqmx.Task() as task:
  ...     task.ai_channels.add_ai_voltage_chan("Dev1/ai0")
  ...     task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=10)
  ...     task.in_stream.configure_logging("TestData.tdms", LoggingMode.LOG_AND_READ, operation=LoggingOperation.CREATE_OR_REPLACE)
  ...     data = task.read(READ_ALL_AVAILABLE)
  ...     print("Acquired data: [" + ", ".join(f"{value:f}" for value in data) + "]")
  ...
  AIChannel(name=Dev1/ai0)
  Acquired data: [-0.149693, 2.869503, 4.520249, 4.704886, 2.875912, -0.006104, -2.895596, -4.493698, -4.515671, -2.776574]

To read the TDMS file, you can use the **npTDMS** third-party module.
Refer to `npTDMS <https://pypi.org/project/npTDMS/>`_ for detailed usage.

Example code to read the TDMS file created from example above and display the data:

.. code-block:: python

  >>> from nptdms import TdmsFile
  >>> with TdmsFile.read("TestData.tdms") as tdms_file:
  ...   for group in tdms_file.groups():
  ...     for channel in group.channels():
  ...       data = channel[:]
  ...       print("data: [" + ", ".join(f"{value:f}" for value in data) + "]")
  ...
  data: [-0.149693, 2.869503, 4.520249, 4.704886, 2.875912, -0.006104, -2.895596, -4.493698, -4.515671, -2.776574]

Plot Data
---------
To visualize the acquired data as a waveform, you can use the **matplotlib.pyplot** third-party module.
Refer to `Pyplot tutorial <https://matplotlib.org/stable/tutorials/pyplot.html#sphx-glr-tutorials-pyplot-py>`_ for detailed usage.

Example code to plot waveform for acquired data using **matplotlib.pyplot** module:

.. code-block:: python

  >>> import nidaqmx
  >>> from nidaqmx.constants import AcquisitionType, READ_ALL_AVAILABLE
  >>> import matplotlib.pyplot as plt
  >>> with nidaqmx.Task() as task:
  ...   task.ai_channels.add_ai_voltage_chan("Dev1/ai0")
  ...   task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=50)
  ...   data = task.read(READ_ALL_AVAILABLE)
  ...   plt.plot(data)
  ...   plt.ylabel('Amplitude')
  ...   plt.title('Waveform')
  ...   plt.show()
  ...
  AIChannel(name=Dev1/ai0)
  [<matplotlib.lines.Line2D object at 0x00000141D7043970>]
  Text(0, 0.5, 'Amplitude')
  Text(0.5, 1.0, 'waveform')

.. image:: https://raw.githubusercontent.com/ni/nidaqmx-python/ca9b8554e351a45172a3490a4716a52d8af6e95e/waveform.png
  :alt: Waveform
  :align: center
  :width: 400px

For more information on how to use **nidaqmx** package, refer to **Usage** section below.

.. _usage-section:

Usage
=====
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.ai_channels.add_ai_voltage_chan("Dev1/ai0")
  ...     task.read()
  ...
  -0.07476920729381246
  >>> with nidaqmx.Task() as task:
  ...     task.ai_channels.add_ai_voltage_chan("Dev1/ai0")
  ...     task.read(number_of_samples_per_channel=2)
  ...
  [0.26001373311970705, 0.37796597238117036]
  >>> from nidaqmx.constants import LineGrouping
  >>> with nidaqmx.Task() as task:
  ...     task.di_channels.add_di_chan(
  ...         "cDAQ2Mod4/port0/line0:1", line_grouping=LineGrouping.CHAN_PER_LINE)
  ...     task.read(number_of_samples_per_channel=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.co_channels.add_co_pulse_chan_time("Dev1/ctr0")
  ...     sample = CtrTime(high_time=0.001, low_time=0.001)
  ...     task.write(sample)
  ...
  1
  >>> with nidaqmx.Task() as task:
  ...     task.ao_channels.add_ao_voltage_chan("Dev1/ao0")
  ...     task.write([1.1, 2.2, 3.3, 4.4, 5.5], auto_start=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.driver_version
  DriverVersion(major_version=16L, minor_version=0L, update_version=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.ai_physical_chans, collections.Sequence)
  True
  >>> phys_chan = device.ai_physical_chans['ai0']
  >>> phys_chan
  PhysicalChannel(name=Dev1/ai0)
  >>> phys_chan == nidaqmx.system.PhysicalChannel('Dev1/ai0')
  True
  >>> phys_chan.ai_term_cfgs
  [<TerminalConfiguration.RSE: 10083>, <TerminalConfiguration.NRSE: 10078>, <TerminalConfiguration.DIFFERENTIAL: 10106>]
  >>> from enum import Enum
  >>> isinstance(phys_chan.ai_term_cfgs[0], Enum)
  True

Bugs / Feature Requests
=======================

To report a bug or submit a feature request, please use the
`GitHub issues page <https://github.com/ni/nidaqmx-python/issues>`_.

Information to Include When Asking for Help
-------------------------------------------

Please include **all** of the following information when opening an issue:

- Detailed steps on how to reproduce the problem and full traceback, if
  applicable.
- The python version used::

  $ python -c "import sys; print(sys.version)"

- The versions of the **nidaqmx** and numpy packages used::

  $ python -m pip list

- The version of the NI-DAQmx driver used. Follow
  `this KB article <http://digital.ni.com/express.nsf/bycode/ex8amn>`_
  to determine the version of NI-DAQmx you have installed.
- The operating system and version, for example Windows 7, CentOS 7.2, ...

License
=======

**nidaqmx** is licensed under an MIT-style license (see
`LICENSE <https://github.com/ni/nidaqmx-python/blob/master/LICENSE>`_).
Other incorporated projects may be licensed under different licenses. All
licenses allow for non-commercial and commercial use.

**gRPC Features**
For driver APIs that support it, passing a GrpcSessionOptions instance as a
parameter is subject to the NI General Purpose EULA
(`see NILICENSE <https://github.com/ni/nidaqmx-python/blob/master/NILICENSE>`_).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ni/nidaqmx-python",
    "name": "nidaqmx",
    "maintainer": "Zach Hindes",
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": "zach.hindes@ni.com",
    "keywords": "nidaqmx, nidaq, daqmx, daq",
    "author": "NI",
    "author_email": "opensource@ni.com",
    "download_url": "https://files.pythonhosted.org/packages/fc/87/37ce5ba7a0ca78598873ac7223d2597b08aef6d9168ae040bf3d963e36e4/nidaqmx-1.0.2.tar.gz",
    "platform": null,
    "description": "+------------+-----------------------------------------------------------+\n| **Info**   | Contains a Python API for interacting with NI-DAQmx. See  | \n|            | `GitHub <https://github.com/ni/nidaqmx-python/>`_ for the |\n|            | latest source.                                            |\n+------------+-----------------------------------------------------------+\n| **Author** | National Instruments                                      |\n+------------+-----------------------------------------------------------+\n\n.. contents:: Table of Contents\n   :depth: 1\n   :backlinks: none\n\nAbout\n=====\n\nThe **nidaqmx** package allows you to develop instrumentation, acquisition, and \ncontrol applications with NI data acquisition (DAQ) devices in Python.\n\nDocumentation\n-------------\n\nYou can find the latest API documentation for the **nidaqmx** package on\n`Read the Docs <http://nidaqmx-python.readthedocs.io/en/stable>`_.\n\nRefer to the\n`NI-DAQmx User Manual <https://www.ni.com/docs/en-US/bundle/ni-daqmx/>`_ for\nan overview of NI-DAQmx, key concepts, and measurement fundamentals. The\nNI-DAQmx Help also installs locally with the full version of NI-DAQmx. Refer to\n`this Knowledge Base (KB) <http://digital.ni.com/express.nsf/bycode/exagg4>`_\nfor more information.\n\nImplementation\n--------------\n\nThe package is implemented in Python as an object-oriented wrapper around the\nNI-DAQmx C API using the\n`ctypes <https://docs.python.org/3/library/ctypes.html>`_ Python library.\n\nSupported NI-DAQmx Driver Versions\n----------------------------------\n\n**nidaqmx** supports all versions of NI-DAQmx. Some functions in the **nidaqmx**\npackage may be unavailable with earlier versions of the NI-DAQmx driver. Refer\nto the Installation section for details on how to install the latest version of\nthe NI-DAQmx driver.\n\nOperating System Support\n------------------------\n\n**nidaqmx** supports Windows and Linux operating systems where the NI-DAQmx\ndriver is supported. Refer to\n`NI Hardware and Operating System Compatibility <https://www.ni.com/r/hw-support>`_\nfor which versions of the driver support your hardware on a given operating\nsystem.\n\nPython Version Support\n----------------------\n\n**nidaqmx** supports CPython 3.8+ and PyPy3.\n\nInstallation\n============\n\nYou can use `pip <http://pypi.python.org/pypi/pip>`_ to download **nidaqmx** from\n`PyPI <https://pypi.org/project/nidaqmx/>`_ and install it::\n\n  $ python -m pip install nidaqmx\n\nAutomatic Driver Installation\n-----------------------------\n\nRunning **nidaqmx** requires NI-DAQmx to be installed. The **nidaqmx** module\nships with a command-line interface (CLI) to streamline the installation\nexperience. You can install the NI-DAQmx driver using the following command::\n\n  $ python -m nidaqmx installdriver\n\nOn Windows, this command will download and launch an online streaming installer\nfrom ni.com. On Linux, this will download the repository registration package\nfor your Linux distribution and install the driver using your package manager.\n\nManual Driver Installation\n--------------------------\n\nVisit `ni.com/downloads <http://www.ni.com/downloads/>`_ to download the latest\nversion of NI-DAQmx. None of the recommended **Additional items** are required\nfor **nidaqmx** to function, and they can be removed to minimize installation\nsize. It is recommended you continue to install the **NI Certificates** package\nto allow your Operating System to trust NI built binaries, improving your\nsoftware and hardware installation experience.\n\nGetting Started\n===============\nIn order to use the **nidaqmx** package, you must have at least one DAQ\n(`Data Acquisition <https://www.ni.com/en/shop/data-acquisition.html>`_) device\ninstalled on your system. Both physical and simulated devices are supported. The\nexamples below use an X Series DAQ device (e.g.: PXIe-6363, PCIe-6363, or\nUSB-6363). You can use **NI MAX** or **NI Hardware Configuration Utility** to\nverify and configure your devices.\n\nFinding and configuring device name in **NI MAX**:\n\n.. image:: https://raw.githubusercontent.com/ni/nidaqmx-python/ca9b8554e351a45172a3490a4716a52d8af6e95e/max_device_name.png\n  :alt: NI MAX Device Name\n  :align: center\n  :width: 800px\n\nFinding and configuring device name in **NI Hardware Configuration Utility**:\n\n.. image:: https://raw.githubusercontent.com/ni/nidaqmx-python/ca9b8554e351a45172a3490a4716a52d8af6e95e/hwcu_device_name.png\n  :alt: NI HWCU Device Name\n  :align: center\n  :width: 800px\n\nPython Examples\n===============\n\nYou can find a variety of examples in the GitHub repository in the\n`nidaqmx-python examples <https://github.com/ni/nidaqmx-python/tree/master/examples>`_\ndirectory. For best results, use the examples corresponding to the version of\n**nidaqmx** that you are using. For example, if you are using version 1.0.0,\ncheck out the\n`examples directory in the 1.0.0 tag <https://github.com/ni/nidaqmx-python/tree/1.0.0/examples>`_.\nNewer examples may demonstrate features that are not available in older versions\nof **nidaqmx**.\n\nKey Concepts in NI-DAQmx\n=========================\n\nTasks\n-----\nA task is a collection of one or more virtual channels with timing, triggering, and other properties.\nRefer to `NI-DAQmx Task <https://www.ni.com/docs/en-US/bundle/ni-daqmx/page/tasksnidaqmx.html>`_ for more information.\n\nExample code to create a task:\n\n.. code-block:: python\n\n  >>> import nidaqmx\n  >>> with nidaqmx.Task() as task:\n  ...     pass\n\nVirtual Channels\n----------------\nVirtual channels, or sometimes referred to generically as channels, are software entities that encapsulate the physical channel\nalong with other channel specific information (e.g.: range, terminal configuration, and custom scaling) that formats the data.\nA physical channel is a terminal or pin at which you can measure or generate an analog or digital signal. A single physical channel\ncan include more than one terminal, as in the case of a differential analog input channel or a digital port of eight lines.\nEvery physical channel on a device has a unique name (for instance, cDAQ1Mod4/ai0, Dev2/ao5, and Dev6/ctr3) that follows the\nNI-DAQmx physical channel naming convention.\nRefer to `NI-DAQmx Channel <https://www.ni.com/docs/en-US/bundle/ni-daqmx/page/chans.html>`_ for more information.\n\nExample code that adds an analog input channel to a task, configures the range, and reads data:\n\n.. code-block:: python\n\n  >>> import nidaqmx\n  >>> with nidaqmx.Task() as task:\n  ...     task.ai_channels.add_ai_voltage_chan(\"Dev1/ai0\", min_val=-10.0, max_val=10.0)\n  ...     task.read()\n  ...\n  AIChannel(name=Dev1/ai0)\n  -0.14954069643238624\n\nExample code that adds multiple analog input channels to a task, configures their range, and reads data:\n\n.. code-block:: python\n\n  >>> import nidaqmx\n  >>> with nidaqmx.Task() as task:\n  ...     task.ai_channels.add_ai_voltage_chan(\"Dev1/ai0\", min_val=-5.0, max_val=5.0)\n  ...     task.ai_channels.add_ai_voltage_chan(\"Dev1/ai1\", min_val=-10.0, max_val=10.0)\n  ...     task.read()\n  ...\n  AIChannel(name=Dev1/ai0)\n  AIChannel(name=Dev1/ai1)\n  [-0.07477034821619312, 0.8642841883602405]\n\nTiming\n------\nYou can use software timing or hardware timing to control when a signal is acquired or generated.\nWith hardware timing, a digital signal, such as a clock on your device, controls the rate of acquisition or generation.\nWith software timing, the rate at which the samples are acquired or generated is determined by the software and operating system\ninstead of by the measurement device. A hardware clock can run much faster than a software loop.\nA hardware clock is also more accurate than a software loop.\nRefer to `Timing, Hardware Versus Software <https://www.ni.com/docs/en-US/bundle/ni-daqmx/page/hardwresoftwretiming.html>`_ for more information.\n\nExample code to acquire finite amount of data using hardware timing:\n\n.. code-block:: python\n\n  >>> import nidaqmx\n  >>> from nidaqmx.constants import AcquisitionType, READ_ALL_AVAILABLE\n  >>> with nidaqmx.Task() as task:\n  ...     task.ai_channels.add_ai_voltage_chan(\"Dev1/ai0\")\n  ...     task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=10)\n  ...     data = task.read(READ_ALL_AVAILABLE)\n  ...     print(\"Acquired data: [\" + \", \".join(f\"{value:f}\" for value in data) + \"]\")\n  ...\n  AIChannel(name=Dev1/ai0)\n  Acquired data: [-0.149693, 2.869503, 4.520249, 4.704886, 2.875912, -0.006104, -2.895596, -4.493698, -4.515671, -2.776574]\n\nTDMS Logging\n------------\nTechnical Data Management Streaming (TDMS) is a binary file format that allows for high-speed data logging.\nWhen you enable TDMS data logging, NI-DAQmx can stream data directly from the device buffer to the hard disk.\nRefer to `TDMS Logging <https://www.ni.com/docs/en-US/bundle/ni-daqmx/page/datalogging.html>`_ for more information.\n\nExample code to acquire finite amount of data and log it to a TDMS file:\n\n.. code-block:: python\n\n  >>> import nidaqmx\n  >>> from nidaqmx.constants import AcquisitionType, LoggingMode, LoggingOperation, READ_ALL_AVAILABLE\n  >>> with nidaqmx.Task() as task:\n  ...     task.ai_channels.add_ai_voltage_chan(\"Dev1/ai0\")\n  ...     task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=10)\n  ...     task.in_stream.configure_logging(\"TestData.tdms\", LoggingMode.LOG_AND_READ, operation=LoggingOperation.CREATE_OR_REPLACE)\n  ...     data = task.read(READ_ALL_AVAILABLE)\n  ...     print(\"Acquired data: [\" + \", \".join(f\"{value:f}\" for value in data) + \"]\")\n  ...\n  AIChannel(name=Dev1/ai0)\n  Acquired data: [-0.149693, 2.869503, 4.520249, 4.704886, 2.875912, -0.006104, -2.895596, -4.493698, -4.515671, -2.776574]\n\nTo read the TDMS file, you can use the **npTDMS** third-party module.\nRefer to `npTDMS <https://pypi.org/project/npTDMS/>`_ for detailed usage.\n\nExample code to read the TDMS file created from example above and display the data:\n\n.. code-block:: python\n\n  >>> from nptdms import TdmsFile\n  >>> with TdmsFile.read(\"TestData.tdms\") as tdms_file:\n  ...   for group in tdms_file.groups():\n  ...     for channel in group.channels():\n  ...       data = channel[:]\n  ...       print(\"data: [\" + \", \".join(f\"{value:f}\" for value in data) + \"]\")\n  ...\n  data: [-0.149693, 2.869503, 4.520249, 4.704886, 2.875912, -0.006104, -2.895596, -4.493698, -4.515671, -2.776574]\n\nPlot Data\n---------\nTo visualize the acquired data as a waveform, you can use the **matplotlib.pyplot** third-party module.\nRefer to `Pyplot tutorial <https://matplotlib.org/stable/tutorials/pyplot.html#sphx-glr-tutorials-pyplot-py>`_ for detailed usage.\n\nExample code to plot waveform for acquired data using **matplotlib.pyplot** module:\n\n.. code-block:: python\n\n  >>> import nidaqmx\n  >>> from nidaqmx.constants import AcquisitionType, READ_ALL_AVAILABLE\n  >>> import matplotlib.pyplot as plt\n  >>> with nidaqmx.Task() as task:\n  ...   task.ai_channels.add_ai_voltage_chan(\"Dev1/ai0\")\n  ...   task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=50)\n  ...   data = task.read(READ_ALL_AVAILABLE)\n  ...   plt.plot(data)\n  ...   plt.ylabel('Amplitude')\n  ...   plt.title('Waveform')\n  ...   plt.show()\n  ...\n  AIChannel(name=Dev1/ai0)\n  [<matplotlib.lines.Line2D object at 0x00000141D7043970>]\n  Text(0, 0.5, 'Amplitude')\n  Text(0.5, 1.0, 'waveform')\n\n.. image:: https://raw.githubusercontent.com/ni/nidaqmx-python/ca9b8554e351a45172a3490a4716a52d8af6e95e/waveform.png\n  :alt: Waveform\n  :align: center\n  :width: 400px\n\nFor more information on how to use **nidaqmx** package, refer to **Usage** section below.\n\n.. _usage-section:\n\nUsage\n=====\nThe following is a basic example of using an **nidaqmx.task.Task** object.\nThis example illustrates how the single, dynamic **nidaqmx.task.Task.read**\nmethod returns the appropriate data type.\n\n.. code-block:: python\n\n  >>> import nidaqmx\n  >>> with nidaqmx.Task() as task:\n  ...     task.ai_channels.add_ai_voltage_chan(\"Dev1/ai0\")\n  ...     task.read()\n  ...\n  -0.07476920729381246\n  >>> with nidaqmx.Task() as task:\n  ...     task.ai_channels.add_ai_voltage_chan(\"Dev1/ai0\")\n  ...     task.read(number_of_samples_per_channel=2)\n  ...\n  [0.26001373311970705, 0.37796597238117036]\n  >>> from nidaqmx.constants import LineGrouping\n  >>> with nidaqmx.Task() as task:\n  ...     task.di_channels.add_di_chan(\n  ...         \"cDAQ2Mod4/port0/line0:1\", line_grouping=LineGrouping.CHAN_PER_LINE)\n  ...     task.read(number_of_samples_per_channel=2)\n  ...\n  [[False, True], [True, True]]\n\nA single, dynamic **nidaqmx.task.Task.write** method also exists.\n\n.. code-block:: python\n\n  >>> import nidaqmx\n  >>> from nidaqmx.types import CtrTime\n  >>> with nidaqmx.Task() as task:\n  ...     task.co_channels.add_co_pulse_chan_time(\"Dev1/ctr0\")\n  ...     sample = CtrTime(high_time=0.001, low_time=0.001)\n  ...     task.write(sample)\n  ...\n  1\n  >>> with nidaqmx.Task() as task:\n  ...     task.ao_channels.add_ao_voltage_chan(\"Dev1/ao0\")\n  ...     task.write([1.1, 2.2, 3.3, 4.4, 5.5], auto_start=True)\n  ...\n  5\n\nConsider using the **nidaqmx.stream_readers** and **nidaqmx.stream_writers**\nclasses to increase the performance of your application, which accept pre-allocated\nNumPy arrays.\n\nFollowing is an example of using an **nidaqmx.system.System** object.\n\n.. code-block:: python\n\n  >>> import nidaqmx.system\n  >>> system = nidaqmx.system.System.local()\n  >>> system.driver_version\n  DriverVersion(major_version=16L, minor_version=0L, update_version=0L)\n  >>> for device in system.devices:\n  ...     print(device)\n  ...\n  Device(name=Dev1)\n  Device(name=Dev2)\n  Device(name=cDAQ1)\n  >>> import collections\n  >>> isinstance(system.devices, collections.Sequence)\n  True\n  >>> device = system.devices['Dev1']\n  >>> device == nidaqmx.system.Device('Dev1')\n  True\n  >>> isinstance(device.ai_physical_chans, collections.Sequence)\n  True\n  >>> phys_chan = device.ai_physical_chans['ai0']\n  >>> phys_chan\n  PhysicalChannel(name=Dev1/ai0)\n  >>> phys_chan == nidaqmx.system.PhysicalChannel('Dev1/ai0')\n  True\n  >>> phys_chan.ai_term_cfgs\n  [<TerminalConfiguration.RSE: 10083>, <TerminalConfiguration.NRSE: 10078>, <TerminalConfiguration.DIFFERENTIAL: 10106>]\n  >>> from enum import Enum\n  >>> isinstance(phys_chan.ai_term_cfgs[0], Enum)\n  True\n\nBugs / Feature Requests\n=======================\n\nTo report a bug or submit a feature request, please use the\n`GitHub issues page <https://github.com/ni/nidaqmx-python/issues>`_.\n\nInformation to Include When Asking for Help\n-------------------------------------------\n\nPlease include **all** of the following information when opening an issue:\n\n- Detailed steps on how to reproduce the problem and full traceback, if\n  applicable.\n- The python version used::\n\n  $ python -c \"import sys; print(sys.version)\"\n\n- The versions of the **nidaqmx** and numpy packages used::\n\n  $ python -m pip list\n\n- The version of the NI-DAQmx driver used. Follow\n  `this KB article <http://digital.ni.com/express.nsf/bycode/ex8amn>`_\n  to determine the version of NI-DAQmx you have installed.\n- The operating system and version, for example Windows 7, CentOS 7.2, ...\n\nLicense\n=======\n\n**nidaqmx** is licensed under an MIT-style license (see\n`LICENSE <https://github.com/ni/nidaqmx-python/blob/master/LICENSE>`_).\nOther incorporated projects may be licensed under different licenses. All\nlicenses allow for non-commercial and commercial use.\n\n**gRPC Features**\nFor driver APIs that support it, passing a GrpcSessionOptions instance as a\nparameter is subject to the NI General Purpose EULA\n(`see NILICENSE <https://github.com/ni/nidaqmx-python/blob/master/NILICENSE>`_).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "NI-DAQmx Python API",
    "version": "1.0.2",
    "project_urls": {
        "Documentation": "https://nidaqmx-python.readthedocs.io",
        "Homepage": "https://github.com/ni/nidaqmx-python",
        "Repository": "https://github.com/ni/nidaqmx-python"
    },
    "split_keywords": [
        "nidaqmx",
        " nidaq",
        " daqmx",
        " daq"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7a3d568be4e6e42c164d948f6bc7c0e1206ccc2ad5970f0fc0ea852db6d66b9b",
                "md5": "a00bff24415e1d70deab794c17478dff",
                "sha256": "8e7386765cdd185e0126cfc2e17734a3a10b5bebebe47763092c7f9f35f0d847"
            },
            "downloads": -1,
            "filename": "nidaqmx-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a00bff24415e1d70deab794c17478dff",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 500255,
            "upload_time": "2024-11-08T17:24:35",
            "upload_time_iso_8601": "2024-11-08T17:24:35.216672Z",
            "url": "https://files.pythonhosted.org/packages/7a/3d/568be4e6e42c164d948f6bc7c0e1206ccc2ad5970f0fc0ea852db6d66b9b/nidaqmx-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fc8737ce5ba7a0ca78598873ac7223d2597b08aef6d9168ae040bf3d963e36e4",
                "md5": "b0c0c2aa7d3592daa8a233e51e67c318",
                "sha256": "d71639cd30125c091489de15ad87cc08d5ff267f27791d6f91ce95453cdc1ea6"
            },
            "downloads": -1,
            "filename": "nidaqmx-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "b0c0c2aa7d3592daa8a233e51e67c318",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 457695,
            "upload_time": "2024-11-08T17:24:39",
            "upload_time_iso_8601": "2024-11-08T17:24:39.175911Z",
            "url": "https://files.pythonhosted.org/packages/fc/87/37ce5ba7a0ca78598873ac7223d2597b08aef6d9168ae040bf3d963e36e4/nidaqmx-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-08 17:24:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ni",
    "github_project": "nidaqmx-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "nidaqmx"
}
        
NI
Elapsed time: 0.55517s