question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

usbtmc assertion failure

See original GitHub issue

Linux, Python3 - talking to a Rigol ds1102e scope. Most operations complete ok. Trying to get the channel data from the scope. ie: rawdata = inst.query_binary_values(“:WAV:DATA? CHAN1”)[10:] Which is on the order of 1024 n-bit values. (I think - not really sure)

usbtmc.py croaks.

  File "./test.py", line 42, in <module>
    main()
  File "./test.py", line 29, in main
    rawdata = inst.query_binary_values(":WAV:DATA? CHAN1")[10:]
  File "/usr/local/lib/python3.4/dist-packages/pyvisa/resources/messagebased.py", line 458, in query_binary_values
    block = self.read_raw()
  File "/usr/local/lib/python3.4/dist-packages/pyvisa/resources/messagebased.py", line 283, in read_raw
    chunk, status = self.visalib.read(self.session, size)
  File "/usr/local/lib/python3.4/dist-packages/pyvisa-py/highlevel.py", line 297, in read
    return self.sessions[session].read(count)
  File "/usr/local/lib/python3.4/dist-packages/pyvisa-py/usb.py", line 107, in read
    usb.USBError)
  File "/usr/local/lib/python3.4/dist-packages/pyvisa-py/sessions.py", line 312, in _read
    current = reader()
  File "/usr/local/lib/python3.4/dist-packages/pyvisa-py/usb.py", line 101, in <lambda>
    return self._read(lambda: self.interface.read(1),
  File "/usr/local/lib/python3.4/dist-packages/pyvisa-py/protocols/usbtmc.py", line 327, in read
    response = BulkInMessage.from_bytes(resp)
  File "/usr/local/lib/python3.4/dist-packages/pyvisa-py/protocols/usbtmc.py", line 95, in from_bytes
    assert msgid == MsgID.dev_dep_msg_in
AssertionError

Here are the setup details:

python3 -m visa info
Machine Details:
   Platform ID:    Linux-3.13.0-45-generic-i686-with-Ubuntu-14.04-trusty
   Processor:      i686

Python:
   Implementation: CPython
   Executable:     /usr/bin/python3
   Version:        3.4.0
   Compiler:       GCC 4.8.2
   Bits:           32bit
   Build:          Apr 11 2014 13:05:18 (#default)
   Unicode:        UCS4

PyVISA Version: 1.6.3

Backends:
   ni:
      Version: 1.6.3 (bundled with PyVISA)
      #1: /usr/lib/i386-linux-gnu/libvisa.so.0.0.0:
         found by: auto
         bitness: 32
         Could not get more info:
            VI_ERROR_NSUP_ATTR (-1073807331): The specified attribute is not defined or supported by the referenced object.
   py:
      Version: 0.1
      TCPIP INSTR: Available 
      USB INSTR: Available via PyUSB (1.0.0b2). Backend: libusb1
      ASRL INSTR: Available via PySerial (N/A)

Thanks for PyVisa-py - I’ve gotten further with it than with librevisa. Let me know if you need any more details.

Jason H.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
agricolabcommented, Jan 4, 2018

Linux, Python3 - talking to a Siglent SDG 805 Signal Generator. Identical issue. The SDG runs fine under Win10 with NI-VISA, that’s why i am necromancing this issue.

I can write to the device without problems. But reading from it, i run, as reported above, in an issue with the assertion. I can also confirm that this is linked to message partitioning by the device. The first message part is 64 Byte long. The second usually shorter, which appears to cause the assertion error. It seems USBTMC.read() is called twice by messagebased.read_raw() from pyvisa, and this function would indeed concatenate partitioned messages.

As NI-VISA as a backend works, and as pyvisa can concatenate partitioned messages, i therefore decided to tweak pyvisa-py. I solved the issue (for my machine and device) by adding an additional quirky message class constructor for BulkInMessage in usbtmc.py, and calling it whenever the assertion fails. In addition, my device added trailing zeros, which needed to be removed, even if the rest of the message would conform. My working expansion is below:

    @classmethod
    def from_bytes(cls, data):       
        msgid, btag, btaginverse = struct.unpack_from('BBBx', data)
        # throw away trailing zeros
        while data[-1] is 0:
            data =  data[:-1]
        # if message in correct format, proceed as usual
        try:        
            assert msgid == MsgID.dev_dep_msg_in
            transfer_size, transfer_attributes = struct.unpack_from('<LBxxx', data, 4)
            data = data[12:]
            return cls(msgid, btag, btaginverse, transfer_size, transfer_attributes, data)
        # otherwise, construct a correct response from the quirky device        
        except AssertionError as e:
            return BulkInMessage.from_quirky(data)        
    
    @classmethod
    def from_quirky(cls, data):  
        'constructs a correct response for quirky devices'
        msgid, btag, btaginverse = struct.unpack_from('BBBx', data)    
        # check whether it contains a ';' and if throw away the first 12 bytes            
        if ';' in str(data):
            transfer_size, transfer_attributes = struct.unpack_from('<LBxxx', data, 4)            
            data = data[12:]                                                    
        else:                 
            transfer_size = 0
            transfer_attributes = 1                    
        return cls(msgid, btag, btaginverse, transfer_size, transfer_attributes, data)

I am uncertain, how this could conflict with other devices. I will likely be able to test it in February with a RIGOL DG 1062Z and a RIGOL 1052E

0reactions
jondoesntgitcommented, Apr 22, 2019

I see, thank you!

I also found that there were a bunch of extra b’\x00’ bytes in the data strings, that I removed with a data = data.rstrip(b'\x00'), for future reference.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Universal Serial Bus Test and Measurement Class, Subclass ...
INTELLECTUAL PROPERTY DISCLAIMER. THIS SPECIFICATION IS PROVIDED “AS IS” WITH NO WARRANTIES WHATSOEVER INCLUDING.
Read more >
757 – g_variant_unref assertion failed - sigrok
Apparently only occurs on Win* . Tested with last nightly sigrok-cli build: "$ sigrok-cli -i olimex_stm32-h103_usb_hid.sr -P ...
Read more >
Migrate Harmony 1 project to Harmony 3
Hi, i have a project developed in harmony 1.06 that implements an USB device of the USBTMC instruments Class devices. For a disk...
Read more >
PWS4205, PWS4305, PWS4323, PWS4602, and PWS4721 ...
In order for the PC to recognize the power supply, a USBTMC driver must be ... enables the power-on status clear and prevents...
Read more >
Instruction Manual (Remote Control)
Includes the list of error messages replied by the DP-G Series in response ... To use a USB interface, USBTMC device driver software...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found