Skip to content

Improper message length issues with Rigol DS1102E #472

@aWZHY0yQH81uOYvH

Description

@aWZHY0yQH81uOYvH

I have a Rigol DS1102E connected over USB using the pyvisa-py backend. I am unable to receive waveform data correctly. This manifests in a few ways.

In normal memory depth mode, the scope should return 16384 bytes of data with an IEEE header.

scope.timeout = 10000 # required or hangs forever
scope.write(':ACQ:MEMD NORMAL')
scope.write(':RUN')
data = scope.query_binary_values(':WAV:DATA? CHAN1', datatype = 'B')
# timeout exception

I think this used to give the exception show below. It seems to be very inconsistent.

I can get some data using read_raw

scope.write(':WAV:DATA? CHAN1')
data = scope.read_raw()
len(data) # 16384

But this sometimes doesn't work (throws the exception shown below), and it returns the incorrect amount of data (should be 16394 bytes including the header).

#470 seems to fix this issue. query_binary_values works as expected with that patch, and read_raw returns the correct amount of data.

However, if I request more data by switching into long memory mode (should return 1048576 samples),

scope.write(':ACQ:MEMD LONG')
scope.write(':RUN')
data = scope.query_binary_values(':WAV:DATA? CHAN1', datatype = 'B')

I get the following exception, where it appears to be trying to parse a zero-length packet.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/me/.local/venv/lib/python3.12/site-packages/pyvisa/resources/messagebased.py", line 750, in query_binary_values
    return self.read_binary_values(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/.local/venv/lib/python3.12/site-packages/pyvisa/resources/messagebased.py", line 574, in read_binary_values
    block = self._read_raw(chunk_size)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/.local/venv/lib/python3.12/site-packages/pyvisa/resources/messagebased.py", line 441, in _read_raw
    chunk, status = self.visalib.read(self.session, size)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/.local/venv/lib/python3.12/site-packages/pyvisa_py/highlevel.py", line 513, in read
    data, status_code = self.sessions[session].read(count)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/.local/venv/lib/python3.12/site-packages/pyvisa_py/usb.py", line 168, in read
    return self._read(
           ^^^^^^^^^^^
  File "/Users/me/.local/venv/lib/python3.12/site-packages/pyvisa_py/sessions.py", line 792, in _read
    current = reader()
              ^^^^^^^^
  File "/Users/me/.local/venv/lib/python3.12/site-packages/pyvisa_py/usb.py", line 152, in _usb_reader
    return self.interface.read(count)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/.local/venv/lib/python3.12/site-packages/pyvisa_py/protocols/usbtmc.py", line 481, in read
    response = BulkInMessage.from_bytes(resp)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/.local/venv/lib/python3.12/site-packages/pyvisa_py/protocols/usbtmc.py", line 114, in from_bytes
    msgid, btag, btaginverse = struct.unpack_from("BBBx", data)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct.error: unpack_from requires a buffer of at least 4 bytes for unpacking 4 bytes at offset 0 (actual buffer size is 0)

Sometimes it takes a very long time for this to finally show up. It used to happen much faster; not sure what is different now.

Attempting to use read_raw results in the same error.

Using @Jimmyvandenbergh's #470, I get a timeout error using query_binary_values and get a bunch of 20480-byte blocks using read_raw. Attempting to use scope.read_bytes(1048586) also results in a timeout error.

From the GitHub issues, it seems like a lot of Rigol/Siglent instruments are triggering this zero-length packet exception, so not sure if what I'm encountering is the same bug as the others. #470 fixes this but appears to be losing data somewhere given the timeout exceptions.

Output of pyvisa-info

Machine Details:
   Platform ID:    macOS-14.6.1-x86_64-i386-64bit
   Processor:      i386

Python:
   Implementation: CPython
   Executable:     /Users/me/.local/venv/bin/python3.12
   Version:        3.12.7
   Compiler:       Clang 15.0.0 (clang-1500.3.9.4)
   Architecture:   ('x86', 64)
   Build:          Oct  1 2024 02:05:46 (#main)
   Unicode:        UCS4

PyVISA Version: 1.14.1

Backends:
   ivi:
      Version: 1.14.1 (bundled with PyVISA)
      Binary library: Not found
   py:
      Version: 0.7.2
      USB INSTR: Available via PyUSB (1.2.1). Backend: libusb1
      USB RAW: Available via PyUSB (1.2.1). Backend: libusb1
      TCPIP INSTR: Available 
         Resource discovery:
         - VXI-11: ok
         - hislip: ok
      TCPIP SOCKET: Available 
      ASRL INSTR:
         Please install PySerial (>=3.0) to use this resource type.
         No module named 'serial'
      VICP INSTR:
         Please install PyVICP to use this resource type.
      GPIB INSTR:
         Please install linux-gpib (Linux) or gpib-ctypes (Windows, Linux) to use this resource type. Note that installing gpib-ctypes will give you access to a broader range of functionalities.
         No module named 'gpib'
      GPIB INTFC:
         Please install linux-gpib (Linux) or gpib-ctypes (Windows, Linux) to use this resource type. Note that installing gpib-ctypes will give you access to a broader range of functionalities.
         No module named 'gpib'


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