Retry opening the display COM port instead of exiting on first failure - #1057
Open
axectly wants to merge 1 commit into
Open
Retry opening the display COM port instead of exiting on first failure#1057axectly wants to merge 1 commit into
axectly wants to merge 1 commit into
Conversation
openSerial() gave up and stopped the whole program as soon as the port could
not be opened. The program resets the screen at startup, which disconnects and
reconnects the device: its COM port is gone for a few seconds and can come back
under a different name, so an autostart at boot can lose that race and leave the
screen frozen until the user starts the program again:
[DEBUG] Detected screen turned ON
[DEBUG] Auto detected COM port: COM4
[ERROR] Cannot open COM port COM4: could not open port 'COM4': FileNotFoundError(2, ...)
Retry for a few seconds before giving up. Also keep self.com_port as configured
instead of overwriting it with the detected port, so that with COM_PORT: AUTO
the port is detected again at every attempt: the screen may come back on another
port than the one found before. This applies to the reconnection in WriteLine()
too, which reopens the port through the same function.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
openSerial()stops the whole program as soon as the COM port cannot be opened:That single attempt is easy to lose at boot. The program resets the screen at startup (
RESET_ON_STARTUP), which disconnects and reconnects the device, so its COM port disappears for a few seconds and can come back under a different name. When the program is started automatically at logon, it can hit exactly that window and exit, leaving the screen showing nothing until the user starts it again by hand.Real log of an autostart at boot, on Windows 11 with a Turing 5" (rev C):
The port was there again seconds later, and starting the program manually worked.
The same single-attempt logic is used for reconnection at runtime:
WriteLine()closes and reopens the port onSerialException, through this same function.Changes
openSerial()retries (10 attempts, 1 second apart) before giving up. Failed attempts are logged as warnings; giving up still logs an error and exits as before.self.com_portkeeps the configured value ("AUTO"or a port name) instead of being overwritten by the detected port. WithAUTO, the port is therefore detected again at every attempt — which matters here, because the screen may come back on a different port than the one detected a moment earlier. Nothing else in the codebase readsself.com_port.Testing
serial.Serial: opening succeeds after 3 failed attempts, and when every attempt fails the program still exits cleanly with the error message instead of hanging.🤖 Generated with Claude Code