Python Forum

Full Version: PyVisa Query Command fails
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi
I am restoring an Electro-Metrics EMC-30 receiver. This is a Mil-Spec EMC test receiver that includes a GPIB bus. This is an old piece of kit.
I have built versions of the usbGpib adapter by Xyphro UsbGpib Adapter.
I have been writing and testing very simple test scripts in python with pyVisa.

Write commands sent over the GPIB interface work. When I send a command the receiver responds correctly.

Query commands (write/read) fail for reasons I don't understand.

The following is the code for my test program:
[inline]
# EMC30 simple test
# ver 0.2 date 29 Apr 25
# The purpose of this script is to test manually entered query commands

import pyvisa
import time

print("###### Simple GPIB test for emc30")
print("# Manually enter query commands")
print("# Show the list of Resources")
rm = pyvisa.ResourceManager()
print(rm.list_resources())
rs = rm.list_resources()

print("# Opening the usb:gpib adapter")
emc30 = rm.open_resource(rs[0], send_end=True,)
time.sleep(1)

# get the user input
qy = input("Enter the query command:")
print(emc30.query_ascii_values(qy) )

emc30.clear()
rm.close()
[/inline]

This is a generic test program. It accepts any query command and returns the response.
I always get an error response as follows:

Output:
###### Simple GPIB test for emc30 # Manually enter query commands # Show the list of Resources ('USB0::0x03EB::0x2065::GPIB_01_34230313836351610051::INSTR',) # Opening the usb:gpib adapter Enter the query command:FR Query the command: FR
Error:
Traceback (most recent call last): File "C:\Users\Darren\Documents\Electronics\emc30_cmd_qry.py", line 26, in <module> print(emc30.read()) ~~~~~~~~~~^^ File "C:\Users\Darren\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyvisa\resources\messagebased.py", line 485, in read message = self._read_raw().decode(enco) ~~~~~~~~~~~~~~^^ File "C:\Users\Darren\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyvisa\resources\messagebased.py", line 441, in _read_raw chunk, status = self.visalib.read(self.session, size) ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Darren\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyvisa\ctwrapper\functions.py", line 2336, in read ret = library.viRead(session, buffer, count, byref(return_count)) File "C:\Users\Darren\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyvisa\ctwrapper\highlevel.py", line 226, in _return_handler return self.handle_return_value(session, ret_value) # type: ignore ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Darren\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyvisa\highlevel.py", line 251, in handle_return_value raise errors.VisaIOError(rv) pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
I think this error is telling me the reply is not being received (timing out).
I have had these query commands working before, so I don't think this is a problem with the EMC-30.

How should I go about troubleshooting this issue? My Python knowledge is poor.
What does the receiver use for read and write termination? You may need to set these for emc30. The pyvisa manual says this is a common cause for the timeout error you see.

https://pyvisa.readthedocs.io/en/latest/...ation.html