-
Notifications
You must be signed in to change notification settings - Fork 22
Address a potential issue in the PybricksHubUSB.write_gatt_char method
#109
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -837,10 +837,20 @@ async def write_gatt_char(self, uuid: str, data, response: bool) -> None: | |
| raise ValueError("Response is required for USB") | ||
|
|
||
| self._ep_out.write(bytes([PybricksUsbOutEpMessageType.COMMAND]) + data) | ||
| # FIXME: This needs to race with hub disconnect, and could also use a | ||
| # timeout, otherwise it blocks forever. Pyusb doesn't currently seem to | ||
| # have any disconnect callback. | ||
| reply = await self._response_queue.get() | ||
|
|
||
| try: | ||
| # FIXME: race_disconnect() doesn't work properly for USB connections since | ||
| # pyusb doesn't provide a reliable way to detect disconnects. The disconnect | ||
| # event from the USB stack may not be received in time to cancel the wait | ||
| # operation. We should implement a proper USB disconnect detection mechanism. | ||
| reply = await asyncio.wait_for( | ||
| self.race_disconnect(self._response_queue.get()), | ||
| timeout=1.0, | ||
| ) | ||
| except asyncio.TimeoutError: | ||
| if self.connection_state_observable.value != ConnectionState.CONNECTED: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point. Since |
||
| raise RuntimeError("Hub disconnected while waiting for response") | ||
| raise asyncio.TimeoutError("Timeout waiting for USB response") | ||
1e0ng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # REVISIT: could look up status error code and convert to string, | ||
| # although BLE doesn't do that either. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.