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

Fix to use endpoints MaxPacketSize instead of hardcoded RECV_CHUNK size #417

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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