PyVISA: Control your instruments with Python

PyVISA

PyVISA is a Python package that enables you to control all kinds of measurementdevices independently of the interface (e.g. GPIB, RS232, USB, Ethernet). Asan example, reading self-identification from a Keithley Multimeter with GPIBnumber 12 is as easy as three lines of Python code:

>>>importpyvisa>>>rm=pyvisa.ResourceManager()>>>rm.list_resources()('ASRL1::INSTR', 'ASRL2::INSTR', 'GPIB0::12::INSTR')>>>inst=rm.open_resource('GPIB0::12::INSTR')>>>print(inst.query("*IDN?"))

(That’s the whole program; really!) It works on Windows, Linux and Mac;with arbitrary adapters (e.g. National Instruments, Agilent, Tektronix,Stanford Research Systems).

General overview

The programming of measurement instruments can be real pain. There are manydifferent protocols, sent over many different interfaces and bus systems(e.g. GPIB, RS232, USB, Ethernet). For every programming language you wantto use, you have to find libraries that support both your device and its bussystem.

In order to ease this unfortunate situation, the Virtual Instrument SoftwareArchitecture (VISA) specification was defined in the middle of the 90ies.VISA is a standard for configuring, programming, and troubleshootinginstrumentation systems comprising GPIB, VXI, PXI, Serial, Ethernet, and/orUSB interfaces.

Today VISA is implemented on all significant operating systems. A coupleof vendors offer VISA libraries, partly with free download. These librarieswork together with arbitrary peripherical devices, although they may belimited to certain interface devices, such as the vendor’s GPIB card.

The VISA specification has explicit bindings to Visual Basic, C, and G(LabVIEW’s graphical language). Python can be used to call functions from aVISA shared library (.dll,.so,.dylib) allowing to directly leverage thestandard implementations. In addition, Python can be used to directly accessmost bus systems used by instruments which is why one can envision to implementthe VISA standard directly in Python (see thePyVISA-Py project for moredetails). PyVISA is both a Python wrapper for VISA shared libraries butcan also serve as a front-end for other VISA implementation such asPyVISA-Py.