rdpoor/rigol-grab

usbtmc AssertionError

Opened this issue · 6 comments

I'm getting the following issue running on macOS 10.14.4 with Python 3.7 on a Rigol DS1054Z

  File "rigol_grab.py", line 69, in <module>
    grabber.grab(filename=opts.filename, auto_open=opts.auto_open)
  File "rigol_grab.py", line 24, in grab
    buf = self.rigol().query_binary_values(':DISP:DATA? ON,0,PNG', datatype='B')
  File "/Users/work/.virtualenv/rigol-grab/lib/python3.7/site-packages/pyvisa/resources/messagebased.py", line 663, in query_binary_values
    header_fmt, expect_termination)
  File "/Users/work/.virtualenv/rigol-grab/lib/python3.7/site-packages/pyvisa/resources/messagebased.py", line 472, in read_binary_values
    block = self._read_raw()
  File "/Users/work/.virtualenv/rigol-grab/lib/python3.7/site-packages/pyvisa/resources/messagebased.py", line 386, in _read_raw
    chunk, status = self.visalib.read(self.session, size)
  File "/Users/work/.virtualenv/rigol-grab/lib/python3.7/site-packages/pyvisa-py/highlevel.py", line 345, in read
    ret = self.sessions[session].read(count)
  File "/Users/work/.virtualenv/rigol-grab/lib/python3.7/site-packages/pyvisa-py/usb.py", line 111, in read
    usb.USBError)
  File "/Users/work/.virtualenv/rigol-grab/lib/python3.7/site-packages/pyvisa-py/sessions.py", line 477, in _read
    current = reader()
  File "/Users/work/.virtualenv/rigol-grab/lib/python3.7/site-packages/pyvisa-py/usb.py", line 105, in <lambda>
    return self._read(lambda: self.interface.read(count),
  File "/Users/work/.virtualenv/rigol-grab/lib/python3.7/site-packages/pyvisa-py/protocols/usbtmc.py", line 338, in read
    response = BulkInMessage.from_bytes(resp)
  File "/Users/work/.virtualenv/rigol-grab/lib/python3.7/site-packages/pyvisa-py/protocols/usbtmc.py", line 108, in from_bytes
    assert msgid == MsgID.dev_dep_msg_in
AssertionError

When I inspect this msgid is 65 and the data is:

b'Author\x00RIGOL\xe7\x88\x8c\xc9\x00\x00\x00\x11tEXtSource\x00DSZ series?Z\x1d\x97\x00\x00\x00)tEXtDescription'

Same problem happening here for me. Scope is DS1054Z with software version 00.04.04.SP3; Mac is on Mojave 10.14.6. Happy to help troubleshoot if I can.

All: I missed the April 2 report from @Cabalist -- my apologies. @jgarbers: thanks for the nudge. Will debug when I catch my breath.

@Cabalist and @jgarbers : I've made some changes that may or may not fix the AssertionError. In particular, I've switched from the visa package to the pyvisa package.

So please pull the latest master version and type the following in a shell. Let me know what happens:

$ git fetch
$ pipenv shell
$ pyvisa-info
$ python rigol_grab.py -v -a

Thanks @rdpoor for the fix, but unfortunately I can't report success here... the script reports "
Could not find Rigol. Check USB?...quitting" when run per your instructions.

Checking the logic in your rigol method that resulted in this error, it looks like my device isn't providing a name that includes the VID_PID substring you expect. I modified the script to display the names that it does find, and my DS1045Z reports this:

USB0::6833::1230::DS1ZA193816892::0::INSTR

I confirmed that name is indeed coming from the scope by unplugging it, in which case the script does not find any names at all.

If I disable the name check in your code and just press ahead with the first and only name found, the script does end up failing with the same AssertionError originally reported by @Cabalist.

Hope this is helpful and please let me know if there's anything else I can try on this end. Thanks for your time and effort!

Here is the pyvisa-info output:

Machine Details:
   Platform ID:    Darwin-18.7.0-x86_64-i386-64bit
   Processor:      i386

Python:
   Implementation: CPython
   Executable:     /Users/jgarbers/.virtualenvs/rigol-grab-0auSBGhB-/Users/jgarbers/.pyenv/shims/python/bin/python3.7
   Version:        3.7.4
   Compiler:       Clang 10.0.1 (clang-1001.0.46.4)
   Bits:           64bit
   Build:          Jul  9 2019 18:13:23 (#default)
   Unicode:        UCS4

PyVISA Version: 1.10.1

Backends:
   ni:
      Version: 1.10.1 (bundled with PyVISA)
      Binary library: Not found
   py:
      Version: 0.3.1
      ASRL INSTR:
         Please install PySerial (>=3.0) to use this resource type.
         No module named 'serial.tools'
      USB INSTR: Available via PyUSB (1.0.2). Backend: libusb1
      USB RAW: Available via PyUSB (1.0.2). Backend: libusb1
      TCPIP INSTR: Available 
      TCPIP SOCKET: Available 
      GPIB INSTR:
         Please install linux-gpib to use this resource type.
         No module named 'gpib'

I don't know what's going on down in the depths of PyVISA, but as a bit of additional debugging information, I added a line to the from_bytes method to show the received message that failed the assertion. In this case, the failed message is

Author\x00RIGOL\xe7\x88\x8c\xc9\x00\x00\x00\x11tEXtSource\x00DSZ series?Z\x1d\x97\x00\x00\x00)tEXtDescription

which looks like a sort of "get info" response. If I'm reading it right, the code is expecting to unpack a 0x02 byte (dev_dep_msg_in) from the message, and getting the 'A' (0x41) from 'Author' instead.

Again I have no idea what the protocol is here but thought this might provide a clue. Thanks!

Good sleuthing -- thanks for the info. One thing that's odd is that your VID-PID string is in decimal -- I've always seen it in hex, so naturally my simple minded find method fails.

As for the assertion error, no clue (yet). It may be worth noting that I have a slightly newer clang and slightly older ni library. I'll see if I can figure out how to upgrade my ni library and see what changes. And I'll try adding the from_bytes to see how mine differs.

(rigol_grab) [~/Projects/Rigol/rigol_grab]$ pyvisa-info

Machine Details:
   Platform ID:    Darwin-18.7.0-x86_64-i386-64bit
   Processor:      i386

Python:
   Implementation: CPython
   Executable:     /Users/r/.local/share/virtualenvs/rigol_grab-3CvMwpSs/bin/python3.7
   Version:        3.7.1
   Compiler:       Clang 6.0 (clang-600.0.57)
   Bits:           64bit
   Build:          Oct 20 2018 03:13:28 (#v3.7.1:260ec2c36a)
   Unicode:        UCS4

PyVISA Version: 1.9.1

Backends:
   ni:
      Version: 1.9.1 (bundled with PyVISA)
      #1: /Library/Frameworks/visa.framework/visa:
         found by: auto
         bitness: 32, 64
         Vendor: National Instruments
         Impl. Version: 18874368
         Spec. Version: 5244928
   py:
      Version: 0.3.1
      ASRL INSTR:
         Please install PySerial (>=3.0) to use this resource type.
         No module named 'serial'
      USB INSTR: Available via PyUSB (1.0.2). Backend: libusb1
      USB RAW: Available via PyUSB (1.0.2). Backend: libusb1
      TCPIP INSTR: Available 
      TCPIP SOCKET: Available 
      GPIB INSTR:
         Please install linux-gpib to use this resource type.
         No module named 'gpib'