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

Fixed bug in USBTMC code which caused issues when packets were longer than max usb packet size #449

Merged
merged 7 commits into from
Oct 1, 2024
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ PyVISA-py Changelog
------------------

- add read_stb method for TCPIP HiSLIP client PR #429
- fix usbtmc implementation to respect section 3.3 of the spec PR #449
Read now reads from usb until a "short packet" has been read
(see specification), and only expects a header on the first packet received.
- add support for VI_ATTR_SUPPRESS_END_EN for USB resources PR #449

0.7.2 (07/03/2024)
------------------
Expand Down
10 changes: 8 additions & 2 deletions pyvisa_py/protocols/usbtmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,19 @@
try:
resp = raw_read(recv_chunk + header_size + max_padding)
response = BulkInMessage.from_bytes(resp)
received.extend(response.data)

Check warning on line 482 in pyvisa_py/protocols/usbtmc.py

View check run for this annotation

Codecov / codecov/patch

pyvisa_py/protocols/usbtmc.py#L482

Added line #L482 was not covered by tests
while len(resp) == self.usb_recv_ep.wMaxPacketSize:
# USBTMC Section 3.3 specifies that the first usb packet
# must contain the header. the remaining packets do not need
# the header the message is finished when a "short packet"
# is sent (one whose length is less than wMaxPacketSize)
resp = raw_read(recv_chunk + header_size + max_padding)
received.extend(resp)

Check warning on line 489 in pyvisa_py/protocols/usbtmc.py

View check run for this annotation

Codecov / codecov/patch

pyvisa_py/protocols/usbtmc.py#L488-L489

Added lines #L488 - L489 were not covered by tests
except (usb.core.USBError, ValueError):
# Abort failed Bulk-IN operation.
self._abort_bulk_in(self._btag)
raise

received.extend(response.data)

# Detect EOM only when device sends all expected bytes.
if len(response.data) >= response.transfer_size:
eom = response.transfer_attributes & 1
Expand Down
7 changes: 3 additions & 4 deletions pyvisa_py/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,10 +796,9 @@
if current:
out.extend(current)
end_indicator_received = end_indicator_checker(current)
if end_indicator_received:
if not suppress_end_en:
# RULE 6.1.1
return bytes(out), StatusCode.success
if end_indicator_received and not suppress_end_en:
# RULE 6.1.1
return bytes(out), StatusCode.success

Check warning on line 801 in pyvisa_py/sessions.py

View check run for this annotation

Codecov / codecov/patch

pyvisa_py/sessions.py#L801

Added line #L801 was not covered by tests
else:
if termination_char_en and (term_char in current):
# RULE 6.1.2
Expand Down
5 changes: 0 additions & 5 deletions pyvisa_py/usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,6 @@ def _usb_reader():

supress_end_en, _ = self.get_attribute(ResourceAttribute.suppress_end_enabled)

if supress_end_en:
raise ValueError(
"VI_ATTR_SUPPRESS_END_EN == True is currently unsupported by pyvisa-py"
)

term_char, _ = self.get_attribute(ResourceAttribute.termchar)
term_char_en, _ = self.get_attribute(ResourceAttribute.termchar_enabled)

Expand Down
Loading