2. Alternative GPIB drivers¶
If PyVISA is not installed, wanglib
provides two alternative GPIB
interfaces that emulate the behavior of visa.instrument
.
2.1. Prologix controllers with wanglib.prologix
¶
This module enables you to control various instruments over GPIB using
low-cost Prologix controllers. The interface aims to emulate that
of PyVISA, such that wanglib.prologix.instrument
objects
can be a drop-in replacement for visa.instrument()
.
For example, the canonical PyVISA three-liner
>>> import visa
>>> keithley = visa.instrument("GPIB::12")
>>> print keithley.ask("*IDN?")
is just one line longer with wanglib.prologix
:
>>> from wanglib import prologix
>>> plx = prologix.prologix_USB('/dev/ttyUSBgpib')
>>> keithley = plx.instrument(12)
>>> print keithley.ask("*IDN?")
This extra verbosity is necessary to specify which GPIB controller to
use. Here we are using a Prologix GPIB-USB controller at
/dev/ttyUSBgpib
. If we later switch to using a Prologix
GPIB-Ethernet controller, we would instead use
>>> plx = prologix.prologix_ethernet('128.223.xxx.xxx')
for our plx
controller object (replace the ``xxx``es
with the controller’s actual ip address, found using the
Prologix Netfinder tool).
-
class
wanglib.prologix.
PrologixEthernet
(ip)¶ Interface to a Prologix GPIB-Ethernet controller.
To instantiate, use the
prologix_ethernet
factory:>>> plx = prologix.prologix_ethernet('128.223.xxx.xxx')
Replace the ``xxx``es with the controller’s actual ip address, found using the Prologix Netfinder tool.
-
addr
¶ The Prologix controller can calk to one instrument at a time. This sets the GPIB address of the currently addressed instrument.
Use this attribute to set or check which instrument is currently selected:
>>> plx.addr 9 >>> plx.addr = 12 >>> plx.addr 12
-
ask
(query, *args, **kwargs)¶ Write to the bus, then read response.
-
auto
¶ Boolean. Read-after-write setting.
The Prologix ‘read-after-write’ setting can automatically address instruments to talk after writing to them. This is usually convenient, but some instruments do poorly with it.
-
instrument
(addr, **kwargs)¶ Factory function for
instrument
objects.>>> plx.instrument(12)
is equivalent to
>>> instrument(plx, 12)
- addr – the GPIB address for an instrument
- attached to this controller.
-
readall
()¶
-
savecfg
¶ Boolean. Determines whether the controller should save its settings in EEPROM.
It is usually best to turn this off, since it will reduce wear on the EEPROM in applications that involve talking to more than one instrument.
-
version
()¶ Check the Prologix firmware version.
-
write
(command, lag=0.1)¶
-
-
class
wanglib.prologix.
PrologixUSB
(port='/dev/ttyUSBgpib', log=False)¶ Interface to a Prologix GPIB-USB controller.
To instantiate, specify the virtual serial port where the controller is plugged in:
>>> plx = prologix.prologix_USB('/dev/ttyUSBgpib')
On Windows, you could use something like
>>> plx = prologix.prologix_USB('COM1')
-
addr
¶ The Prologix controller can calk to one instrument at a time. This sets the GPIB address of the currently addressed instrument.
Use this attribute to set or check which instrument is currently selected:
>>> plx.addr 9 >>> plx.addr = 12 >>> plx.addr 12
-
ask
(query, *args, **kwargs)¶ Write to the bus, then read response.
-
auto
¶ Boolean. Read-after-write setting.
The Prologix ‘read-after-write’ setting can automatically address instruments to talk after writing to them. This is usually convenient, but some instruments do poorly with it.
-
instrument
(addr, **kwargs)¶ Factory function for
instrument
objects.>>> plx.instrument(12)
is equivalent to
>>> instrument(plx, 12)
- addr – the GPIB address for an instrument
- attached to this controller.
-
readall
()¶
-
savecfg
¶ Boolean. Determines whether the controller should save its settings in EEPROM.
It is usually best to turn this off, since it will reduce wear on the EEPROM in applications that involve talking to more than one instrument.
-
version
()¶ Check the Prologix firmware version.
-
write
(command, lag=0.1)¶
-
-
class
wanglib.prologix.
instrument
(controller, addr, delay=0.1, auto=True)¶ Represents an instrument attached to a Prologix controller.
Pass the controller instance and GPIB address to the constructor. This creates a GPIB instrument at address 12:
>>> plx = prologix_USB() >>> inst = instrument(plx, 12)
A somewhat nicer way to do the second step would be to use the
instrument()
factory method of the Prologix controller:>>> inst = plx.instrument(12)
Once we have our instrument object
inst
, we can use theask()
andwrite()
methods to send GPIB queries and commands.-
ask
(command)¶ Send a query the instrument, then read its response.
Equivalent to
write()
thenread()
.For example, get the ‘ID’ string from an EG&G model 5110 lock-in:
>>> inst.ask('ID') '5110'
Is the same as:
>>> inst.write('ID?') >>> inst.read() '5110'
-
delay
= 0.1¶
-
read
()¶ Read a response from an instrument.
-
write
(command)¶ Write a command to the instrument.
-
-
wanglib.prologix.
prologix_USB
(port='/dev/ttyUSBgpib', log=False)¶ Factory for a Prologix GPIB-USB controller.
To instantiate, specify the virtual serial port where the controller is plugged in:
>>> plx = prologix.prologix_USB('/dev/ttyUSBgpib')
On Windows, you could use something like
>>> plx = prologix.prologix_USB('COM1')
-
wanglib.prologix.
prologix_ethernet
(ip)¶ Factory function for a Prologix GPIB-Ethernet controller.
To instantiate, specify the IP address of the controller:
>>> plx = prologix.prologix_ethernet('128.223.xxx.xxx')
2.2. linux_gpib compatibility layer: wanglib.linux_gpib
¶
Utilities for computers using linux-gpib.
linux-gpib (http://linux-gpib.sourceforge.net/) is an open-source driver for various GPIB cards. It includes two python modules:
- the low-level gpib module
- an object-oriented Gpib module.
The Gpib module defines a Gpib class representing individual instruments. This module modifies that class to make it behave a little more like PyVISA’s instrument class, for better compatibility with the rest of wanglib.
This will only work if your linux-gpib installation has been patched with the following enhancement:
http://sourceforge.net/tracker/?func=detail&aid=3437534&group_id=42378&atid=432942
This should apply to any linux-gpib released since January 2012.