Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usb timeouts on OS X 10.11.6 #27

Open
mikest opened this issue Sep 9, 2016 · 12 comments
Open

usb timeouts on OS X 10.11.6 #27

mikest opened this issue Sep 9, 2016 · 12 comments

Comments

@mikest
Copy link

mikest commented Sep 9, 2016

hello,

i'm getting the following traceback from python when trying to send data to a Rigol mso1104z:

>>> import usbtmc
>>> usbtmc.list_devices()
[<DEVICE ID 1ab1:04ce on Bus 020 Address 013>]
>>> ins = usbtmc.Instrument(0x1ab1, 0x04ce)
>>> print(ins.ask("*IDN?"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "usbtmc/usbtmc.py", line 608, in ask
    return self.read(num, encoding)
  File "usbtmc/usbtmc.py", line 591, in read
    return self.read_raw(num).decode(encoding).rstrip('\r\n')
  File "usbtmc/usbtmc.py", line 514, in read_raw
    self.bulk_out_ep.write(req)
  File "build/bdist.macosx-10.11-x86_64/egg/usb/core.py", line 387, in write
  File "build/bdist.macosx-10.11-x86_64/egg/usb/core.py", line 948, in write
  File "build/bdist.macosx-10.11-x86_64/egg/usb/backend/libusb1.py", line 824, in bulk_write
  File "build/bdist.macosx-10.11-x86_64/egg/usb/backend/libusb1.py", line 920, in __write
  File "build/bdist.macosx-10.11-x86_64/egg/usb/backend/libusb1.py", line 595, in _check
usb.core.USBError: [Errno 60] Operation timed out

happy to collect more data if it will help.

@mikest
Copy link
Author

mikest commented Sep 9, 2016

tried Cedric's timeout pull request and got a different error:

>>> import usbtmc
>>> usbtmc.Instrument(0x1ab1, 0x04ce)
<usbtmc.usbtmc.Instrument object at 0x101f86f90>
>>> ins = usbtmc.Instrument(0x1ab1, 0x04ce)
>>> print(ins.ask("*IDN?"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "usbtmc/usbtmc.py", line 608, in ask
    return self.read(num, encoding)
  File "usbtmc/usbtmc.py", line 591, in read
    return self.read_raw(num).decode(encoding).rstrip('\r\n')
  File "usbtmc/usbtmc.py", line 516, in read_raw
    resp = self.bulk_in_ep.read(read_len+USBTMC_HEADER_SIZE+3, timeout = int(self.timeout*1000))
  File "build/bdist.macosx-10.11-x86_64/egg/usb/core.py", line 402, in read
  File "build/bdist.macosx-10.11-x86_64/egg/usb/core.py", line 988, in read
  File "build/bdist.macosx-10.11-x86_64/egg/usb/backend/libusb1.py", line 833, in bulk_read
  File "build/bdist.macosx-10.11-x86_64/egg/usb/backend/libusb1.py", line 936, in __read
  File "build/bdist.macosx-10.11-x86_64/egg/usb/backend/libusb1.py", line 595, in _check
usb.core.USBError: [Errno 60] Operation timed out

@mikest
Copy link
Author

mikest commented Sep 9, 2016

tried running code against a DP832 programable power supply. got same timeout issue. seems like maybe there is some OS X funny business going on?

@alexforencich
Copy link
Contributor

OS X funny business would not surprise me at all. Have you tried with any other computers for comparison?

@alexforencich
Copy link
Contributor

alexforencich commented Sep 15, 2016

Oh, can you try that with Cedric's timeout code and an explicit line termination like this?

print(ins.ask("*IDN?\n"))

or

print(ins.ask("*IDN?\r\n"))

It's possible that the instrument firmware is expecting a new line char. Some instruments are programmed properly and are fine with no extra chars, some need a little help.

@mikest
Copy link
Author

mikest commented Sep 16, 2016

same timeout

>>> print(ins.ask("*IDN?\r\n"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.11-x86_64/egg/usbtmc/usbtmc.py", line 607, in ask
  File "build/bdist.macosx-10.11-x86_64/egg/usbtmc/usbtmc.py", line 587, in write
  File "build/bdist.macosx-10.11-x86_64/egg/usbtmc/usbtmc.py", line 483, in write_raw
  File "build/bdist.macosx-10.11-x86_64/egg/usb/core.py", line 387, in write
  File "build/bdist.macosx-10.11-x86_64/egg/usb/core.py", line 948, in write
  File "build/bdist.macosx-10.11-x86_64/egg/usb/backend/libusb1.py", line 824, in bulk_write
  File "build/bdist.macosx-10.11-x86_64/egg/usb/backend/libusb1.py", line 920, in __write
  File "build/bdist.macosx-10.11-x86_64/egg/usb/backend/libusb1.py", line 595, in _check
usb.core.USBError: [Errno 60] Operation timed out
>>>

got the same error :/

@luqasz
Copy link

luqasz commented Apr 18, 2017

Same error here. Tried both IDN commands and I have this exception:

/Users/lkostka/.virtualenvs/tmc/lib/python2.7/site-packages/usbtmc/usbtmc.pyc in ask(self, message, num, encoding)
    628                 self.lock()
    629             self.write(message, encoding)
--> 630             return self.read(num, encoding)
    631         finally:
    632             if self.advantest_quirk and not was_locked:

/Users/lkostka/.virtualenvs/tmc/lib/python2.7/site-packages/usbtmc/usbtmc.pyc in read(self, num, encoding)
    611     def read(self, num=-1, encoding='utf-8'):
    612         "Read string from instrument"
--> 613         return self.read_raw(num).decode(encoding).rstrip('\r\n')
    614
    615     def ask(self, message, num=-1, encoding='utf-8'):

/Users/lkostka/.virtualenvs/tmc/lib/python2.7/site-packages/usbtmc/usbtmc.pyc in read_raw(self, num)
    530                     self.bulk_out_ep.write(req, timeout=int(self.timeout*1000))
    531
--> 532                 resp = self.bulk_in_ep.read(read_len+USBTMC_HEADER_SIZE+3, timeout=int(self.timeout*1000))
    533
    534                 if sys.version_info >= (3, 2):

/Users/lkostka/.virtualenvs/tmc/lib/python2.7/site-packages/usb/core.pyc in read(self, size_or_buffer, timeout)
    400         For details, see the Device.read() method.
    401         """
--> 402         return self.device.read(self, size_or_buffer, timeout)
    403
    404     def clear_halt(self):

/Users/lkostka/.virtualenvs/tmc/lib/python2.7/site-packages/usb/core.pyc in read(self, endpoint, size_or_buffer, timeout)
    986                 intf.bInterfaceNumber,
    987                 buff,
--> 988                 self.__get_timeout(timeout))
    989
    990         if isinstance(size_or_buffer, array.array):

/Users/lkostka/.virtualenvs/tmc/lib/python2.7/site-packages/usb/backend/libusb1.pyc in bulk_read(self, dev_handle, ep, intf, buff, timeout)
    831                            intf,
    832                            buff,
--> 833                            timeout)
    834
    835     @methodtrace(_logger)

/Users/lkostka/.virtualenvs/tmc/lib/python2.7/site-packages/usb/backend/libusb1.pyc in __read(self, fn, dev_handle, ep, intf, buff, timeout)
    934         # do not assume LIBUSB_ERROR_TIMEOUT means no I/O.
    935         if not (transferred.value and retval == LIBUSB_ERROR_TIMEOUT):
--> 936             _check(retval)
    937         return transferred.value
    938

/Users/lkostka/.virtualenvs/tmc/lib/python2.7/site-packages/usb/backend/libusb1.pyc in _check(ret)
    593             raise NotImplementedError(_strerror(ret))
    594         else:
--> 595             raise USBError(_strerror(ret), ret, _libusb_errno[ret])
    596
    597     return ret

USBError: [Errno 60] Operation timed out
(tmc)--- workspace/tmc » pip list
Package                            Version
---------------------------------- -------
appdirs                            1.4.3
appnope                            0.1.0
backports.shutil-get-terminal-size 1.0.0
decorator                          4.0.11
enum34                             1.1.6
ipython                            5.3.0
ipython-genutils                   0.2.0
packaging                          16.8
pathlib2                           2.2.1
pexpect                            4.2.1
pickleshare                        0.7.4
pip                                9.0.1
prompt-toolkit                     1.0.14
ptyprocess                         0.5.1
Pygments                           2.2.0
pyparsing                          2.2.0
python-usbtmc                      0.8
pyusb                              1.0.0
scandir                            1.5
setuptools                         35.0.0
simplegeneric                      0.8.1
six                                1.10.0
traitlets                          4.3.2
wcwidth                            0.1.7
wheel                              0.24.0

However device is detected.

In [2]: usbtmc.list_devices()
Out[2]: [<DEVICE ID 1ab1:04ce on Bus 020 Address 002>]

@nickovs
Copy link

nickovs commented Jul 4, 2017

I'm having the same problem. I have no problem finding my Rigol DS1054z scope on the USB but all commands time out when reading the response. pyUSB 1.0.0, python-usbtmc 0.8 on macOS 10.12.5.

@alexforencich
Copy link
Contributor

Rigol firmware does not implement usbtmc correctly. I am seriously considering removing all of the Rigol quirks from the code (they apply primarily to the 1052E, but not the 1000Z, which both share the same VID and PID so it is infeasible to determine which set of quirks to apply) and then just adding a disclaimer that Rigol devices may not work correctly. The Linux kernel driver has the same problem.

@luqasz
Copy link

luqasz commented Oct 25, 2017

Rigol firmware does not implement usbtmc correctly. I am seriously considering removing all of the Rigol quirks from the code (they apply primarily to the 1052E, but not the 1000Z, which both share the same VID and PID so it is infeasible to determine which set of quirks to apply) and then just adding a disclaimer that Rigol devices may not work correctly. The Linux kernel driver has the same problem.

Maybe leave code with quirks but let users use that one when they need. Default code will be without quirks and for those pesky rigol write a warning and how to use a wrapper class of some kind. Maybe that helps.

I wonder how would scope work with TCP connection. Maybe swapping USB with TCP will work.

@jbrumf
Copy link

jbrumf commented Oct 25, 2017

Just a suggestion: How about removing the Rigol quirks from usbtmc.py, but provide a subclass rigol.py that overrides the read_raw method with the quirks. That way, it cleans up usbtmc.py, and only DS1052E users use the subclass.

@alexforencich
Copy link
Contributor

alexforencich commented Oct 25, 2017

Not a bad idea, you would just need a subclass for basically every rigol instrument line as each one seems to implement USBTMC in their own special way. For example, the current code does not work AT ALL with the DS1000Z series units, with or without quirks.

@lcvisser
Copy link

lcvisser commented Jun 15, 2021

For whoever comes here in the future: I had the same issue with a Thorlabs device, but both on Mac OS and Linux (Debian). Thorlabs tech support mailed me a modified version of the usbtmc module that resolved the issue for me. Here's the diff:

% diff -w usbtmc.py ThorInstrument.py
487a488,490
>         if self.device.idVendor == 0x1313:
>             self.device.ctrl_transfer(bmRequestType=0xA1, bRequest=USB488_REN_CONTROL, wValue=0x0001, wIndex=0x0000, data_or_wLength=1)
> 
489a493
>         time.sleep(0.1)
491c495
< 
---
>         time.sleep(0.1)
497a502,506
>         if self.device.idVendor == 0x1313:			
>             self.device.ctrl_transfer(bmRequestType=0xA1, bRequest=USB488_GOTO_LOCAL, wValue=0x0000, wIndex=0x0000, data_or_wLength=1)
>             self.device.ctrl_transfer(bmRequestType=0xA1, bRequest=USB488_REN_CONTROL, wValue=0x0000, wIndex=0x0000, data_or_wLength=1)
>             time.sleep(0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants