Python Resources for NI Hardware and Software

Overview

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.

Contents

Using Python APIs for NI Hardware

Open source developers and National Instruments 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.

Python APIs for PXI Modular Instruments

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

PXI Oscilloscope

NI-SCOPE

niscope

PXI Waveform Generator

NI-FGEN

nifgen

PXI Digital Multimeter

NI-DMM

nidmm

PXI Pprogrammable Power Supply

PXI Source Measure Unit

NI-DCPower

nidcpower

PXI Switch

NI-SWITCH

niswitch

PXI Digital Pattern Instrument

NI-Digital Pattern Driver

nidigital


Learn more about nimi-python

Python API for DAQ Hardware

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.

 

Python API for VirtualBench

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.

 

Python API for RIO Hardware

The National Instruments FPGA Interface Python API is used for communication between processor and FPGA within NI reconfigurable I/O (RIO) hardware such as NI CompactRIONI Single-Board RIONI 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

Python API for Vision Applications

The nivision library is a National Instruments 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

Python API for CAN, LIN, and FlexRay Hardware

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

Python API for Traditional, Benchtop Instruments

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.

Learn more about PyVISA

Calling NI Hardware DLLs Using ctypes

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 National Instruments hardware with Python via the ctypes module. This solution provides an intuitive way to integrate Python scripts with most hardware components.

LabVIEW DLLs

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.

Learn how to generate a DLL and call it from Python

Integrating Python into LabVIEW

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. 

Calling Python from TestStand

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.

Using Python for VeriStand

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