Skip to content

Commit

Permalink
Fix to use endpoints MaxPacketSize instead of hardcoded RECV_CHUNK size
Browse files Browse the repository at this point in the history
This was found using a Rigol DS1074Z scope which has a limited MaxPacketSize of 64.
  • Loading branch information
sessl3r committed Mar 6, 2024
1 parent 13bda1d commit 6b3c851
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
PyVISA-py Changelog
===================

0.7.2 (unreleased)
------------------

- fix usbtmc to use MaxPacketSize reported by endpoint

0.7.1 (26/10/2023)
------------------

Expand Down
15 changes: 6 additions & 9 deletions pyvisa_py/protocols/usbtmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,6 @@ def close(self):


class USBTMC(USBRaw):
# Maximum number of bytes per transfer (for sending and receiving).
RECV_CHUNK = 1024**2

find_devices = staticmethod(find_tmc_devices)

def __init__(self, vendor=None, product=None, serial_number=None, **kwargs):
Expand Down Expand Up @@ -403,7 +400,7 @@ def _abort_bulk_in(self, btag):
return

# Read remaining data from Bulk-IN endpoint.
self.usb_recv_ep.read(self.RECV_CHUNK, abort_timeout_ms)
self.usb_recv_ep.read(self.usb_recv_ep.wMaxPacketSize, abort_timeout_ms)

# Send CHECK_ABORT_BULK_IN_STATUS until it completes.
# According to USBTMC 1.00 4.2.1.5:
Expand Down Expand Up @@ -443,7 +440,7 @@ def write(self, data):
# Set the EOM flag on the last transfer only.
# Send at least one transfer (possibly empty).
while (end == 0) or (end < size):
begin, end = end, begin + self.RECV_CHUNK
begin, end = end, begin + self.usb_send_ep.wMaxPacketSize

self._btag = (self._btag % 255) + 1

Expand All @@ -455,12 +452,12 @@ def write(self, data):
return size

def read(self, size):
recv_chunk = self.RECV_CHUNK
if size > 0 and size < recv_chunk:
recv_chunk = size

header_size = 12
max_padding = 511
recv_chunk = self.usb_recv_ep.wMaxPacketSize - header_size

if size > 0 and size < recv_chunk:
recv_chunk = size

eom = False

Expand Down

0 comments on commit 6b3c851

Please sign in to comment.