Skip to content

Make usb sensor timeout more robust #211

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

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 13 additions & 1 deletion validitysensor/usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,29 @@ def cancel(self):

def wait_int(self):
self.cancel = False
max_retries = 3 # Number of retry attempts before giving up
retry_count = 0
timeout_ms = 500 # Increased timeout from 100ms to 500ms

while True:
try:
resp = self.dev.read(131, 1024, timeout=100)
resp = self.dev.read(131, 1024, timeout=timeout_ms)
resp = bytes(resp)
self.trace('<int< %s' % hexlify(resp).decode())
return resp
except USBError as e:
if e.errno == errno.ETIMEDOUT:
if self.cancel:
raise CancelledException()

# Add retry logic for transient timeouts
retry_count += 1
if retry_count <= max_retries:
self.trace(f'USB timeout, retrying ({retry_count}/{max_retries})...')
continue
else:
self.trace(f'USB timeout after {max_retries} retries, giving up')
raise
else:
raise e

Expand Down