Python Instrument Control

By | March 3, 2015

Python is becoming more established for scientific data analysis and processing, but what python instrument control options are there?

For me the benchmark instrument control software has to be LabView. It’s incredibly expensive and certainly has it’s quirks, but I’ve found that it can often make interfacing with hardware relatively painless.

I’ve recently been exploring alternatives to Matlab for scientific analysis and processing, so I was curious to see what the state of affairs was for python instrument control.

Read about my 3 Python Alternatives to Matlab.

My Requirements For Instrument Control

For me any python instrument control package would need:

  • Standard hardware interfacing (E.g. GPIB, RS232, USB)
  • NIDAQ interfacing
  • Ability to easily build a virtual rack
  • Easy live plotting of data

The most important of these of course is the ability to interface with the measurement hardware, so let’s see what python instrument control packages are available.

In a future post I’ll investigate the options for completely replacing LabVIEW with python.

Python Instrument Control Packages

The most important part of any python instrument control software has to be the packages for interfacing with the measurement equipment itself.

Thankfully there are a couple of fairly well maintained python packages that cover most of your interfacing needs.

PyVISA

PyVISA is a python package for the Virtual Instrument Software Architecture (VISA). It’s actually a wrapper for the National Instruments VISA library, which you will have to install separately.

PyVISA allows python to relatively painlessly interface with:

  • GPIB
  • RS232
  • USB
  • Ethernet

This example (taken from the PyVISA documentation) communicates with a Keithley multimeter on GPIB address 12:

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

PyVISA seems to be an active, regularly updated package with fairly good documentation page. Unfortunately the VISA architecture does not include the popular NIDAQ card interface. For that we need PyDAQmx (below).

PyDAQmx

Whilst PyVISA will allow you to communicate with most hardware, it unfortunately is not capable of communicating with the popular and commonly found NI-DAQ card.

Thankfully there is an additional package, PyDAQmx, which acts as a wrapper to the NI-DAQ driver and allows your python scripts to communicate with the the DAQ card.

One thought on “Python Instrument Control

  1. Ali Eftekhari

    hello, I am using the following; it returns all devices that are connected to the COM ports but it doesn’t return the USB devices. Am I missing something? Thanks!
    import visa
    rm = visa.ResourceManager()
    rm.list_resources()

Comments are closed.