Python GPIB etc. support with PyVISA¶
Controlling GPIB, RS232, and USB instruments¶
|Date:||February 27, 2017|
|Maintainer:||Florian Bauer <email@example.com>|
|Downloads:||See the PyVISA project page.|
The PyVISA package enables you to control all kinds of measurement equipment through various busses (GPIB, RS232, USB) with Python programs. As an example, reading self-identification from a Keithley Multimeter with GPIB number 12 is as easy as three lines of Python code:
import visa keithley = visa.instrument("GPIB::12") print keithley.ask("*IDN?")
(That’s the whole program; really!) It is tailored to work on both Windows and Linux, and with arbitrary adapters (e.g. National Instruments, Agilent, Tektronix, Stanford Research Systems). In order to achieve this, PyVISA relies on an external library file which is bundled with hardware and software of those vendors. (So only in rare cases you have to purchase it separately.)
PyVISA implements convenient and Pythonic programming in two layers:
- An object-oriented Python module has been created simply called
visa. It is the recommended way to use PyVISA. See the PyVISA manual for more information.
- Additionally, there is the lower level module
vpp43, which directly calls the VISA functions from Python. See the PyVISA low-level implementation for more information. This is only for people who need full control or the official VISA functions for some reason.
PyVISA is free open-source software. The PyVISA project page contains the bug tracker and the download area.
Projects using PyVISA so far:
- pyvLab – program to control VISA-talking instruments
The programming of measurement instruments can be real pain. There are many different protocols, sent over many different interfaces and bus systems (GPIB, RS232, USB). For every programming language you want to use, you have to find libraries that support both your device and its bus system.
In order to ease this unfortunate situation, the VISA  specification was defined in the middle of the 90ies. Today VISA is implemented on all significant operating systems. A couple of vendors offer VISA libraries, partly with free download. These libraries work together with arbitrary peripherical devices, although they may be limited to certain interface devices, such as the vendor’s GPIB card.
|||Virtual Instrument Software Architecture|
The VISA specification has explicit bindings to Visual Basic, C, and G (LabVIEW’s graphical language). However, you can use VISA with any language capable of calling functions in a DLL. Python is such a language.
VISA and Python¶
Python has a couple of features that make it very interesting for measurement controlling:
- Python is an easy-to-learn scripting language with short development cycles.
- It represents a high abstraction level , which perfectly blends with the abstraction level of measurement programs.
- It has a very rich set of native libraries, including numerical and plotting modules for data analysis and visualisation.
- A large set of books (in many languages) and on-line publications is available.
- You can download it for free at http://www.python.org.
|||For example, you don’t need to care about the underlying operating system with all its peculiarities.|