fix(telemetrix): a dropped serial link reads as disconnected - #181
Merged
Merged
Conversation
Once the USB link drops, telemetrix-aio's serial write catches the SerialException, sleeps a second and returns None. With close_loop_on_shutdown=False (what we pass) it neither raises nor stops its loop, so the worker thread stays alive, is_connected stays True, and every later write "succeeds" while the rig does nothing. An experiment on an infinite Loop just stops moving, with nothing in the log. The one thing that does die with the port is telemetrix's report reader task. is_running now also requires that task to be alive (unless a deliberate shutdown ended it), so the existing is_connected path marks the board DISCONNECTED, logs the cause, and the GUI's pause-on-drop dialog fires on the next write. An Arduino that resets without the USB link dropping (motor noise, brownout) is still undetected; that needs a heartbeat.
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
An experiment on an infinite
Loopdriving an Arduino would run for a while, then the hardware stopped responding. Nothing was logged.When the USB serial link drops, telemetrix-aio's
TelemetrixAioSerial.write()catches theSerialException, closes the port, waits one second and returnsNone. We passclose_loop_on_shutdown=False, so it never raises and never stops its event loop. The worker thread stays alive,TelemetrixBoard.is_connectedstaysTrue, and every laterdigital_writelooks like it worked while nothing reaches the board.The one thing that does fail with the port is telemetrix's report reader (
the_task). It dies on the firstin_waitingpoll, and its exception is stored on a task that nothing ever reads, so it is never logged either.Fix
TelemetrixThread.is_runningnow also requires the report reader to be alive. A reader that ended because of a deliberateshutdown()still counts as alive. A newlink_errorproperty gives the reason.is_connectedalready checksis_runningbefore every read and write, so after a drop:Telemetrix link lost (OSError(6, 'Device not configured')) - marking as disconnectedDISCONNECTED, and the next write raisesBoard not connectedMainWindow._on_hardware_connection_changepauses the running experiment and shows the hardware-disconnection dialog (existing behavior)Not covered
An Arduino that resets without the USB link dropping (motor noise, brownout) keeps the port open, so writes still go through and the reset board ignores them. Catching that needs a heartbeat to the board.
Testing
test_dropped_serial_link_reads_as_disconnected: fails onmain, passes here._arduino_report_dispatcherandTelemetrixAioSerialwith a port that drops partway through a run: the board reports disconnected while the thread is still alive, and the next write raises.tests/: 4759 passed. Plugin suites were not run locally.