Skip to content

Conversation

brianignacio5
Copy link
Collaborator

Description

This pull request adds robust device reconnection support to the TypeScript example, improving the user experience when a serial device is unexpectedly disconnected. The main changes include tracking device info for reconnection, implementing a callback for device loss, and refactoring the console reading loop to support automatic reconnection.

Device reconnection and management:

  • Added tracking of deviceInfo to store USB vendor and product IDs, enabling identification and reconnection to the same device after disconnection. [1] [2] [3]
  • Implemented a device lost callback in the Transport class and set it up in the UI logic, allowing the app to detect when the device is lost and attempt to reconnect automatically. [1] [2] [3]

Console reading and reconnection logic:

  • Refactored the console reading loop into a separate startConsoleReading function, which handles errors and waits for reconnection if the device is lost.
  • Added logic to attempt reconnection by searching for previously authorized devices matching the original device's USB IDs, updating the transport, and restarting the console read loop upon successful reconnection.

These changes make the application more resilient to device disconnects, providing a smoother workflow for users interacting with serial devices.

Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

@brianignacio5 brianignacio5 self-assigned this Oct 15, 2025
Copy link

Download the artifacts for this pull request:

@tyeth
Copy link

tyeth commented Oct 15, 2025

Hey Brian 👋
This doesn't reconnect for me on Windows as in general usb reconnections take over 1second (it's as bad as 3seconds on my slowest laptop). serialLib.getPorts returns [].
If I run the developer tools and break at the reconnection, then allow it to check the available ports after hearing the usb reconnection noise in windows - about 1s after rebooting device, then the reconnection works correctly. Nice work!
Makes me think it would be worth adding a retry check of the available ports (maybe once per second up to 5times then bail).
Also worth adding a subsequent message on failure as currently nothing is emitted after this (the attempt is over)

[DEVICE LOST] Device disconnected. Click 'Reconnect' to restore connection...
[CONSOLE] Connection lost, waiting for reconnection...
[RECONNECT] Attempting to reconnect...
image

Oh and I didn't see the reconnect button at all, but maybe I merged/rebased it out 😂

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants