0

I need some advice on how to deal with USB timeout errors.

I am working on an app that is communicating with my Anritsu instrument over USB-GPIB port. The app works fine, I read out results periodically with fixed interval. However from time to time I accidentally can end up calling Read_data function while the instrument is in the process of reading. This throws Timeout error and the app halts. When I restart the app, pyvisa finds the instrument and connects to it. First command is to read the *IDN?, but on this first read I get the following error:

('USB0::1003::8293::ANRITSU_0_0000::0::INSTR',)
Found VNA USB0::1003::8293::ANRITSU_0_0000::0::INSTR
Attached
[2022年09月17日 23:14:31,349] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
 File "/usr/local/share/pynq-venv/lib/python3.8/site-packages/pyvisa_py/protoco ls/usbtmc.py", line 256, in write
 return self.usb_send_ep.write(data)
 File "/usr/local/share/pynq-venv/lib/python3.8/site-packages/usb/core.py", lin e 408, in write
 return self.device.write(self, data, timeout)
 File "/usr/local/share/pynq-venv/lib/python3.8/site-packages/usb/core.py", lin e 989, in write
 return fn(
 File "/usr/local/share/pynq-venv/lib/python3.8/site-packages/usb/backend/libus b1.py", line 837, in bulk_write
 return self.__write(self.lib.libusb_bulk_transfer,
 File "/usr/local/share/pynq-venv/lib/python3.8/site-packages/usb/backend/libus b1.py", line 938, in __write
 _check(retval)
 File "/usr/local/share/pynq-venv/lib/python3.8/site-packages/usb/backend/libus b1.py", line 602, in _check
 raise USBTimeoutError(_strerror(ret), ret, _libusb_errno[ret])
 usb.core.USBTimeoutError: [Errno 110] Operation timed out
 
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
 File "/usr/local/share/pynq-venv/lib/python3.8/site-packages/flask/app.py", li ne 2070, in wsgi_app
 response = self.full_dispatch_request()
 File "/usr/local/share/pynq-venv/lib/python3.8/site-packages/flask/app.py", li ne 1508, in full_dispatch_request
 self.try_trigger_before_first_request_functions()
 File "/usr/local/share/pynq-venv/lib/python3.8/site-packages/flask/app.py", li ne 1560, in try_trigger_before_first_request_functions
 self.ensure_sync(func)()
 File "/home/xilinx/Anritsu_GPIB/VNA/routes.py", line 44, in intialize_VNA
 print(anritsu.VNA.query('*IDN?'))
 File "/usr/local/share/pynq-venv/lib/python3.8/site-packages/pyvisa/resources/ messagebased.py", line 642, in query
 self.write(message)
 File "/usr/local/share/pynq-venv/lib/python3.8/site-packages/pyvisa/resources/ messagebased.py", line 197, in write
 count = self.write_raw(message.encode(enco))
 File "/usr/local/share/pynq-venv/lib/python3.8/site-packages/pyvisa/resources/ messagebased.py", line 157, in write_raw
 return self.visalib.write(self.session, message)[0]
 File "/usr/local/share/pynq-venv/lib/python3.8/site-packages/pyvisa_py/highlev el.py", line 543, in write
 written, status_code = self.sessions[session].write(data)
 File "/usr/local/share/pynq-venv/lib/python3.8/site-packages/pyvisa_py/usb.py" , line 179, in write
 count = self.interface.write(data)
 File "/usr/local/share/pynq-venv/lib/python3.8/site-packages/pyvisa_py/protoco ls/usbtmc.py", line 436, in write
 bytes_sent += raw_write(data)
 File "/usr/local/share/pynq-venv/lib/python3.8/site-packages/pyvisa_py/protoco ls/usbtmc.py", line 258, in write
 raise ValueError(str(e))
ValueError: [Errno 110] Operation timed out

This persists until I do a complete reboot. I cannot find a way to clear this error. Does anyone have an advice on how to go about debugging this issue.

Thanks.

asked Sep 17, 2022 at 23:42
2
  • just a small clarification. Here is where the error is triggered: File "/home/xilinx/Anritsu_GPIB/VNA/routes.py", line 44, in intialize_VNA print(anritsu.VNA.query('*IDN?')) Commented Sep 17, 2022 at 23:48
  • the anritsu is an instance of my Instrument class that is basically just encapsulating the pyvisa resource object and containing my methods for data conversion. There is not much to it. On the instantiation (in the init) is where the resource is attached and IDN query is called. Commented Sep 17, 2022 at 23:55

1 Answer 1

0

When you encounter Operation timed out it is usually one of the following two cases:

  1. The instrument is busy. Perhaps your instrument is still working on something else when you restart the app? I think this one is probably not the case.
  2. The instrument is in a bad state, because it received a bad command earlier. This is the most likely problem, since a reboot solves it.

I'm not familiar with the Anritsu equipment, but I would suggest one of the following ways to avoid querying before the instrument is ready:

First, many machines support the GPIB *OPC? query, which means "Operation Complete". After you trigger the job/measurement to start, you can loop over the *OPC? query until you get a good response. Then you know the machine is ready to report, and you can read_data. This sometimes requires you to catch the GPIB timeout and try again (depending on the machine response).

Second, most machines put updates in their status bytes, which can be read without interrupting the instrument. Use the GPIB *STB? query to get the current status byte of the instrument. You'll have to read the manual for your particular instrument to understand what each bit means. Often, there is a bit for errors and another to show that the test is in-progress or complete.

Third, if you can't find any way to know in advance if the instrument is ready, you can query the instrument and hope (like you are doing now). If the machine becomes non-responsive because of an error state, you can reset it using the GPIB *RST command. It should have the same effect as a reboot, but you can program it directly into your code.

answered Sep 21, 2022 at 17:30
Sign up to request clarification or add additional context in comments.

4 Comments

Sorry for my late reply. I am still working on this, but I was occupied last few days. I would like to clarify one thing regarding your Third point. You wrote "If the machine becomes non-responsive because of an error state, you can reset it using the GPIB *RST command." When I said the reboot clears the error, i meant the reboot of the host machine not the instrument itself. To clear this error I must reboot the PC running the app. I have a hunch that there is some unresolved exception in pyUSB but i do not know how to go about figuring it out.
Without reboot of the host PC (running a version of ubuntu18.04 i think) , even when I restart the instrument or the app itself, the pyVisa cannot complete any read or write operation successfully. It always throws the error from the first post.
That's very interesting, it sounds like the instrument itself is working ok, but the issue lies on your controller PC. I wonder if ubuntu is having some trouble with the USB port.
Exactly. I never had issues with Anritsu VISA implementation. Somehow there is some lingering error that is still present when I restart the python app.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.