Skip to content

Timeout error breaks communication #206

@robsan00

Description

@robsan00

I have a problem with restoring from an error case where a query runs into a timeout. I am working under Ubuntu, executing the same script under Windows using NI-visa shows no problems.

Here an example script:

import visa

dev_name = "USB0::0x14EB::0x0090::<censored>::INSTR"
resource_manager = visa.ResourceManager()
instrument = resource_manager.open_resource(dev_name)

print(instrument.query_ascii_values("system:error?", converter="s"))

instrument.timeout = 5000  # 5 s
try:
    print(instrument.query_ascii_values("query?", converter="f"))
except Exception as e:
    print("expected timeout", e)

try:
    print(instrument.query_ascii_values("system:error?", converter="s"))
except Exception as e:
    print("unexpected error", e)

Under Ubuntu using pyvisa-py I get:

['+0', '"No error"\n']
expected timeout VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
unexpected error VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.

If I try to execute the script again, nothing works anymore, the serial communication seems to be broken:

Traceback (most recent call last):
  File "test_script.py", line 5, in <module>
    instrument = resource_manager.open_resource(dev_name)
  File "/home/<censored>/venv/python3/lib/python3.6/site-packages/pyvisa/highlevel.py", line 1763, in open_resource
    res.open(access_mode, open_timeout)
  File "/home/<censored>/venv/python3/lib/python3.6/site-packages/pyvisa/resources/resource.py", line 216, in open
    self.session, status = self._resource_manager.open_bare_resource(self._resource_name, access_mode, open_timeout)
  File "/home/<censored>/venv/python3/lib/python3.6/site-packages/pyvisa/highlevel.py", line 1720, in open_bare_resource
    return self.visalib.open(self.session, resource_name, access_mode, open_timeout)
  File "/home/<censored>/venv/python3/lib/python3.6/site-packages/pyvisa-py/highlevel.py", line 194, in open
    sess = cls(session, resource_name, parsed, open_timeout)
  File "/home/<censored>/venv/python3/lib/python3.6/site-packages/pyvisa-py/sessions.py", line 213, in __init__
    self.after_parsing()
  File "/home/<censored>/venv/python3/lib/python3.6/site-packages/pyvisa-py/usb.py", line 201, in after_parsing
    self.parsed.serial_number)
  File "/home/<censored>/venv/python3/lib/python3.6/site-packages/pyvisa-py/protocols/usbtmc.py", line 256, in __init__
    super(USBTMC, self).__init__(vendor, product, serial_number, **kwargs)
  File "/home/<censored>/venv/python3/lib/python3.6/site-packages/pyvisa-py/protocols/usbtmc.py", line 166, in __init__
    **device_filters))
  File "/home/<censored>/venv/python3/lib/python3.6/site-packages/usb/core.py", line 1249, in device_iter
    if _interop._all(tests) and (custom_match is None or custom_match(d)):
  File "/home/<censored>/venv/python3/lib/python3.6/site-packages/pyvisa-py/protocols/usbutil.py", line 191, in cm
    if not fnmatch(getattr(dev, attr).lower(), pattern.lower()):
  File "/home/<censored>/venv/python3/lib/python3.6/site-packages/usb/core.py", line 830, in serial_number
    self._serial_number = util.get_string(self, self.iSerialNumber)
  File "/home/<censored>/venv/python3/lib/python3.6/site-packages/usb/util.py", line 314, in get_string
    raise ValueError("The device has no langid")
ValueError: The device has no langid

I have to switch the device off and on again, to restore communication.
Executing the same script under Windows (using NI-visa) works out just fine (also executing it multiple times).

Executing SCPI commands like "*RST" or "*CLS" after the timeout error, don't seem to help either.

Do I have to do any special clean-up in case of a timeout (where NI-visa is more lenient than pyvisa-py)?

The device I am working with, is a Pendulum CNT-90.
Excerpt from pip freeze:

pyusb==1.0.2
PyVISA==1.10.0
PyVISA-py==0.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions