Skip to content
This repository was archived by the owner on Feb 2, 2026. It is now read-only.

Raise timeout exception if <4 bytes received#32

Open
vslotman wants to merge 1 commit intopython-ivi:masterfrom
vslotman:receive_timeout
Open

Raise timeout exception if <4 bytes received#32
vslotman wants to merge 1 commit intopython-ivi:masterfrom
vslotman:receive_timeout

Conversation

@vslotman
Copy link

Sometimes timeouts are not handled nicely, resulting in the following stacktrace:

print self.dev.ask('*IDN?')
File "/usr/local/lib/python2.7/dist-packages/usbtmc/usbtmc.py", line 635, in ask
return self.read(num, encoding)
File "/usr/local/lib/python2.7/dist-packages/usbtmc/usbtmc.py", line 618, in read
return self.read_raw(num).decode(encoding).rstrip('\r\n')
File "/usr/local/lib/python2.7/dist-packages/usbtmc/usbtmc.py", line 547, in read_raw
msgid, btag, btaginverse, transfer_size, transfer_attributes, data = self.unpack_dev_dep_resp_header(resp)
File "/usr/local/lib/python2.7/dist-packages/usbtmc/usbtmc.py", line 468, in unpack_dev_dep_resp_header
msgid, btag, btaginverse = self.unpack_bulk_in_header(data)
File "/usr/local/lib/python2.7/dist-packages/usbtmc/usbtmc.py", line 464, in unpack_bulk_in_header
msgid, btag, btaginverse = struct.unpack_from('BBBx', data)
error: unpack_from requires a buffer of at least 4 bytes

@alexforencich
Copy link
Contributor

I have seen this issue before; but have not been able to get to the bottom of it as it only appears sporadically when communicating with some particular pieces of hardware. Are you sure this is the correct approach here? And are you sure that this isn't a result of a firmware implementation bug in the device in question? And speaking of which, what devices are you running in to this issue with?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants