PyVisa USBError after one run

Viewed 5

I'm using PiVisa on a Raspberry Pi 4B with Python 3.7 and a PyVisa version 1.10.0. I do habe a problem with the connection(?) to my Digital Multimeter. On a fresh start the code is working fine, but after that, I do get a USBError error every second run. I enabled the log option, but nothing much for me to see there.

Also I prefer to stay at this version of PyVisa and Python, so the old code can still run. The pi is in offline mode as well, so simple update does not work for me and connect him into the internet as well.

import pyvisa
import time
import visa

visa.log_to_screen()
rm = pyvisa.ResourceManager('@py') #Use the pyvisa-py backend
myInstrument = rm.open_resource('MY:ADDRESS')
myInstrument.timeout = 0
myInstrument.read_termination = '\n'
myInstrument.write_termination = '\n'

print(pyvisa.__version__)

# Enable remote commands
myInstrument.write("SYSTem:REMote")

myInstrument.write("MEAS:VOLT:DC? AUTO")
time.sleep(1)

for i in range(1):
    fullReadingLine = myInstrument.query("READ?")
    print(f"Value: {fullReadingLine} ")
    time.sleep(0.5)

myInstrument.close()
rm.close()

Here is the log output from the console.

pi@raspberrypi:~/Documents/new_testTool $ python3 pyvisa-test.py
2022-08-31 22:11:50,205 - pyvisa - DEBUG - SerialSession was correctly imported.
2022-08-31 22:11:50,248 - pyvisa - DEBUG - USBSession and USBRawSession were correctly imported.
2022-08-31 22:11:50,257 - pyvisa - DEBUG - TCPIPSession was correctly imported.
2022-08-31 22:11:50,259 - pyvisa - DEBUG - GPIBSession was not imported No module named 'gpib'.
2022-08-31 22:11:50,260 - pyvisa - DEBUG - Created library wrapper for unset
2022-08-31 22:11:50,260 - pyvisa - DEBUG - Created ResourceManager with session 4293804
2022-08-31 22:11:50,261 - pyvisa - DEBUG - MY:ADDRESS - opening ...
2022-08-31 22:11:50,534 - pyvisa - DEBUG - MY:ADDRESS - is open with session 7581094
1.10.0
2022-08-31 22:11:51,538 - pyvisa - DEBUG - USB0::2733::309::037282696::0::INSTR - reading 20480 bytes (last status <StatusCode.success_max_count_read: 1073676294>)
Value: 8.60307000E-03
2022-08-31 22:11:52,339 - pyvisa - DEBUG - MY:ADDRESS - closing
2022-08-31 22:11:52,340 - pyvisa - DEBUG - MY:ADDRESS - is closed
2022-08-31 22:11:52,340 - pyvisa - DEBUG - Closing ResourceManager (session: 4293804)
2022-08-31 22:11:52,341 - pyvisa - DEBUG - MY:ADDRESS - closing
pi@raspberrypi:~/Documents/new_testTool $ python3 pyvisa-test.py
2022-08-31 22:22:03,881 - pyvisa - DEBUG - SerialSession was correctly imported.
2022-08-31 22:22:03,922 - pyvisa - DEBUG - USBSession and USBRawSession were correctly imported.
2022-08-31 22:22:03,931 - pyvisa - DEBUG - TCPIPSession was correctly imported.
2022-08-31 22:22:03,933 - pyvisa - DEBUG - GPIBSession was not imported No module named 'gpib'.
2022-08-31 22:22:03,933 - pyvisa - DEBUG - Created library wrapper for unset
2022-08-31 22:22:03,934 - pyvisa - DEBUG - Created ResourceManager with session 9517076
2022-08-31 22:22:03,934 - pyvisa - DEBUG - MY:ADDRESS - opening ...
2022-08-31 22:22:04,204 - pyvisa - DEBUG - MY:ADDRESS - is open with session 5006259
1.10.0
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/pyvisa-py/protocols/usbtmc.py", line 225, in write
    return self.usb_send_ep.write(data)
  File "/home/pi/.local/lib/python3.7/site-packages/usb/core.py", line 387, in write
    return self.device.write(self, data, timeout)
  File "/home/pi/.local/lib/python3.7/site-packages/usb/core.py", line 948, in write
    self.__get_timeout(timeout)
  File "/home/pi/.local/lib/python3.7/site-packages/usb/backend/libusb1.py", line 824, in bulk_write
    timeout)
  File "/home/pi/.local/lib/python3.7/site-packages/usb/backend/libusb1.py", line 920, in __write
    _check(retval)
  File "/home/pi/.local/lib/python3.7/site-packages/usb/backend/libusb1.py", line 595, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 110] Operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pyvisa-test.py", line 21, in <module>
    fullReadingLine = myInstrument.query("READ?")
  File "/home/pi/.local/lib/python3.7/site-packages/pyvisa/resources/messagebased.py", line 594, in query
    self.write(message)
  File "/home/pi/.local/lib/python3.7/site-packages/pyvisa/resources/messagebased.py", line 224, in write
    count = self.write_raw(message.encode(enco))
  File "/home/pi/.local/lib/python3.7/site-packages/pyvisa/resources/messagebased.py", line 202, in write_raw
    return self.visalib.write(self.session, message)
  File "/home/pi/.local/lib/python3.7/site-packages/pyvisa-py/highlevel.py", line 368, in write
    ret = self.sessions[session].write(data)
  File "/home/pi/.local/lib/python3.7/site-packages/pyvisa-py/usb.py", line 126, in write
    count = self.interface.write(data)
  File "/home/pi/.local/lib/python3.7/site-packages/pyvisa-py/protocols/usbtmc.py", line 314, in write
    bytes_sent += raw_write(data)
  File "/home/pi/.local/lib/python3.7/site-packages/pyvisa-py/protocols/usbtmc.py", line 227, in write
    raise ValueError(str(e))
ValueError: [Errno 110] Operation timed out
2022-08-31 22:22:06,267 - pyvisa - DEBUG - MY:ADDRESS - closing
2022-08-31 22:22:06,268 - pyvisa - DEBUG - MY:ADDRESS - is closed
2022-08-31 22:22:06,301 - pyvisa - DEBUG - Closing ResourceManager (session: 9517076)
pi@raspberrypi:~/Documents/new_testTool $

0 Answers
Related