This document provides an overview of the National Instrument tools to use Python alongside the NI hardware and software platforms, including PXI, CompactDAQ, CompactRIO, LabVIEW, TestStand, and VeriStand. For each Python tool, refer to the linked documentation for installation instructions, supported environments, API reference, and examples.
Open source developers and NI have made Python integration with NI hardware easy by creating modules that abstract the lower-level ctypes function calls into simplified APIs. The following links lead to documentation resources for Python wrappers that have been created for NI hardware drivers.
The nimi-python repository is a collection of Python modules that provide an interface to the underlying NI modular instrument drivers. Currently, NI offers Python support through this package for PXI oscilloscopes, waveform generators, DMMs, SMUs, power supplies, switches, and digital pattern instruments. These instruments use the following drivers:
Modular Instrument | Driver | Python Module |
---|---|---|
NI-SCOPE | niscope | |
NI-FGEN | nifgen | |
NI-DMM | nidmm | |
NI-DCPower | nidcpower | |
NI-SWITCH | niswitch | |
NI-Digital Pattern Driver | nidigital |
The nidaqmx package contains an API for interacting with the NI-DAQmx driver required to communicate your NI data acquisition (DAQ) device. 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.
The pyVirtualBench library provides an interface to the underlying VirtualBench driver by wrapping the C API.
Note: pyVirtualBench is a third-party wrapper and is not directly supported by NI.
The NI FPGA Interface Python API is used for communication between processor and FPGA within NI reconfigurable I/O (RIO) hardware such as NI CompactRIO, NI Single-Board RIO, NI FlexRIO, and NI R Series multifunction RIO.
With the FPGA Interface Python API, developers can use LabVIEW FPGA to program the FPGA within NI hardware and communicate to it from Python running on a host computer. This gives engineers and scientists with Python expertise the ability to take advantage of compiled LabVIEW FPGA bitfiles and have the option to reuse existing Python code.
Learn more about FPGA Interface Python API
The nivision library is a NI image/vision processing library that makes the functionality of NI Vision available in the Python programming language. It is available for multiple platforms including Windows and the CompactRIO.
Note: nivision is a third-party wrapper and is not directly supported by NI.
Learn more about nivision
The nixnet package contains an API for interacting with the NI-XNET driver. NI-XNET is the driver software technology behind NI-XNET CAN, LIN, and FlexRay PCI, PXI, and NI C Series interfaces. The nixnet package and NI-XNET are supported by NI.
Learn more about nixnet
PyVISA is a Python package that contains the API for interacting with the NI-VISA driver. NI-VISA enables you to control measurement instruments independently of the interface (e.g. GPIB, RS232, USB, Ethernet) and is the driver software technology behind NI serial, GPIB, and Ethernet PCI, PXI, USB, and NI C Series interfaces.
Note: PyVISA is a third-party wrapper and is not directly supported by NI.
While Python modules with intuitive APIs exist for hardware communication with many devices, developers frequently rely on C APIs provided with most hardware drivers to integrate their Python code with hardware. The same methodology can be applied to using NI hardware with Python via the ctypes module. This solution provides an intuitive way to integrate Python scripts with most hardware components.
In addition to using the ctypes module to access a hardware driver's C API, LabVIEW can generate DLLs composed of hardware API functions that can be called from Python. This same procedure allows developers to abstract a sequence of hardware interactions into a single function call stored in the DLL file.
LabVIEW 2018 introduces the Python Node, which provides native capability to intuitively call a Python script from a LabVIEW Block Diagram. It uses LabVIEW primitives, providing a way to interoperate between the languages with low latency.
Starting with TestStand 2019, the included Python Adapter offers an integrated, configuration-based experience for calling Python code modules from your test sequences. The adapter is built on the same design principles as other TestStand adapters, providing a development experience familiar to existing TestStand developers.
Starting with VeriStand 2018, the niveristand package contains an API that interfaces with VeriStand systems. This package was created and is supported by NI.
Learn more about niveristand
Starting with DIAdem 2020, Python is available in the SCRIPT module as an alternative scripting language to VBS. You only need to enable Python in the DIAdem SCRIPT settings as the script language if you prefer to use this language. As with VBS, you can alternatively record scripts in Python syntax. The Python editor integrated in the SCRIPT panel offers the usual auto-completion and a tooltip with syntax information and a short command description.