Search This Blog

Apr 7, 2015

Using pyvisa to control instrument via GPIB

1. Introduction

We have met several issues which related with power on/off operation. The failure rate is extremely low which is not efficiency for manual operation. So we would like to setup an automatic testing environment. The GPIB(General Purpose Interface Bus) is the way to control the instrument. This article shows how to control the Agilent E3631A (Triple Output DC Power Supply).

2. GPIB Interface

Here is the Agilent 82357A USB/GPIB Interface in our hand. Following link shows the detailed information.

3. Pyvisa installation

Pyvisa is a Python package for support of the “Virtual Instrument Software Architecture” (VISA), in order to control measurement devices and test equipment via GPIB, RS232, Ethernet or USB.
To install the pyvisa by using pip:
$ pip install pyvisa
Detailed information can be found in

4. NI driver installation

Pyvisa has been tested with NI-VISA 3.2, which needs us to install its driver.
Download and install NIVISA541full.exe from following link

5. Agilent driver installation.

The GPIB interface is Agilent product, which needs its driver installed.
Download and install the latest IOLibSuite_17_0_19013.exe from following link.

6. Using HP Agilent 82357A/82357B GPIB in NI
In order to use the NI VISA drivers and both the HP Agilent and NI GPIB devices, you will need to enable:
  • NIVISATulip.dll
  • NI 488.2 from within the Agilent libraries
Complete the steps in the following document to enable NIVISATulip.dll:
KnowledgeBase 20KG1C7Z: Can I Use Both National Instruments (GPIB) and Agilent/HP (HPIB) Controllers in the Same System? (
Complete the following steps to enable NI 488.2 from within Agilent Connection Expert 15.x and 16.x:
  • Select Tools»Agilent 488 from the pulldown menu.
  • Select the Agilent 488 Options tab.
  • Check Enable Agilent GPIB cards for 488 programs.

7. Agilent E3631A spec download

Download spec from
Here is part of the command list:
APPLy {P6V|P25V|N25V}[,{|DEF|MIN|MAX}[,{ |DEF|MIN|MAX}]]
    APPLy? [{P6V|P25V|N25V}]
    [:STATe] {OFF|ON}
    :TRACk[:STATe] {OFF|ON}

8. Pyvisa tutorial

From pyvisa official website, we can find the tutorial
Here is the example code to control E3631A output.
import visa

rm = visa.ResourceManager()
res = rm.list_resources()
print("Find following resources: ")
print("Opening " + res[-1])

inst = rm.open_resource(res[-1])

# When sending command to E3631A, The "Rmt" and "Adrs" icon are on on the display
# panel. All input from panel are inactived, util you press "Store/Local" button.


inst.write("INST P6V") # Select +6V output
inst.write("VOLT 2.0") # Set output voltage to 3.0 V
inst.write("CURR 1.0") # Set output current to 1.0 A

# The APPLy command provides the most straightforward method to program the
# power supply over the remote interface.
#  inst.write("APPL P6V, 3.0, 1.0")

# power on/off
inst.write("OUTP OFF")
inst.write("OUTP ON")