Using visa to interface with GPIB always gives me VisaIOError

7.6k views Asked by At

I'm trying to import visa in Python and interface with GPIB to control a device. The name of device I'm using is "GPIB0::9::INSTR", and I think there should be no problem with this.

I ran the following code in 2.7.3 Python Shell

>>> from visa import *
>>> a = instrument("GPIB0::9", timeout = 20)
>>> a.write("*IDN?")
>>> print a.read()

Traceback (most recent call last):
  File "<pyshell#53>", line 1, in <module>
    print a.read()
  File "C:\Python27\lib\site-packages\pyvisa\visa.py", line 433, in read
    return self._strip_term_chars(self.read_raw())
  File "C:\Python27\lib\site-packages\pyvisa\visa.py", line 407, in read_raw
    chunk = vpp43.read(self.vi, self.chunk_size)
  File "C:\Python27\lib\site-packages\pyvisa\vpp43.py", line 840, in read
    visa_library().viRead(vi, buffer, count, byref(return_count))
  File "C:\Python27\lib\site-packages\pyvisa\vpp43.py", line 398, in check_status
    raise visa_exceptions.VisaIOError, status
VisaIOError: VI_ERROR_TMO: Timeout expired before operation completed.

Above is the error the system gave me. Actually at the beginning, I set the Timeout to be 3, it shows this errot. But after I changed the value to be 20 as shown above, it still didn't work.

Can somebody help me?

3

There are 3 answers

0
2342G456DI8 On BEST ANSWER

For each one specific instruments, it will have its own command to control them. Please refer to the device's user manual.

0
atf On
import visa

rm = visa.ResourceManager()
devices = rm.list_resources()
comm_channel = rm.open_resource(devices[0])     #assuming you only have 1 address to worry about

print(comm_channel.query("*IDN?"))

This exploits PYVisa's module and the many functions it has to offer with connecting/writing/reading to and from a USB/GPIB device.

0
P3trus On

There are different problems that could lead to a timeout. First you should check if your device supports the *IDN?query. It is a IEEE-488.2 standard command, so chances are high it is supported (if not check your manual for commands that are).

Then you should check you're communication settings, specifically the termination character and the EOI.

If you're using the wrong termination character, visa will keep on reading and finally time out.

Note: You can use pyvisa's ask function if you're using a queryable command (it is a combined write and read).

import visa

# If you've got just one gpib card installed, you can ommit the 0.
# ASsuming the EOI line should be asserted and a termination character
# of '\n'
instrument = visa.instrument('GPIB::9', term_chars='\n', send_end=True)
# use ask to write the command and read back the response
print instrument.ask('*IDN?')