-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Serial monitor suspends and resumes when (un)plugging other serial port #9785
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
Comments
Hi @matthijskooijman , |
Nope, I have not done anything yet other than investigate and report above. |
Great, I'm on it |
Fixes arduino#9785 and probably many others This commit strongly simplyfies the serial list code Pluggable discovery introduced a bug since BoardPort.toString() started reporting only the name of the port, not the complete name_vid_pid needed to match liblistserial output. Adding .toCompleteString() almost solves the bogus disconnection part alone, but resolveDeviceByVendorIdProductId() uses "0x" prefixes VID/PID, breaking it again. In addition, all the logic used to match a board with its bootloader (to obtain a serial number on 32u4 boards) has been completely removed since it is currently useless (and unused).
PR submitted #9862. |
Fixes #9785 and probably many others This commit strongly simplyfies the serial list code Pluggable discovery introduced a bug since BoardPort.toString() started reporting only the name of the port, not the complete name_vid_pid needed to match liblistserial output. Adding .toCompleteString() almost solves the bogus disconnection part alone, but resolveDeviceByVendorIdProductId() uses "0x" prefixes VID/PID, breaking it again. In addition, all the logic used to match a board with its bootloader (to obtain a serial number on 32u4 boards) has been completely removed since it is currently useless (and unused).
I've noticed an issue where the serial port gets closed unexpectedly by the serial monitor. To reproduce:
This problem does not seem to occur always, but often, because there's a race condition involved.
Under the hood, what happens is:
SerialDiscovery
refreshes the list of serial portsAbstractMonitor
checks to see if the port is still there (or if it went away, to see if it returned).AbstractMonitor
requests a list halfway through the refresh done bySerialDiscovery
. This should be fixed by adding some synchronized statements.SerialDiscovery
incorrectly matches full port strings returned by liblistserials (including vidpid, e.g./dev/ttyACM0_16D0_0F44
) againstBoardPort.toString()
(which returns just the port path without the vidpid). This means that whenever the port list changes, it treats all ports as being disconnected and reconnected as new, unique, ports.AbstractMonitor
then requests a list of (online) serial ports, this will return the empty list, causing the monitor to close.The minimal fix, I suspect, would be:
serialBoardPorts
synchronized (on second thought: Maybe better to actually replace theserialBoardPorts
array completely rather than clearing and refilling it when it changes, since that is probably also atomic, and also makes sure that any callers that have a previous version of the list will not see their list change all of a sudden (on closer inspection, it seems that a copy is already returned now, so this does not really matter).However, looking around this code, it does seem like it's a bit of mess. I would think some refactoring might be helpful, except that I suspect that (serial) port discovery will soon be delegated to
arduino-cli
? @cmaglie, I suspect you can comment on that?Regardless, some things I think could be improved are:
boardPort.isOnline()
which (if the above is fixed) should switch to false and back to true.isOnline
changes instead of having a timer inAbstractMonitor
, to make sure a quick offline/online transition is not missed.resolveDeviceByVendorIdProductId()
is called which again looks up the vidpid for the port name. The latter could probably be skipped and just use the vidpid that are already known. Update: On closer inspection, it seems that the latter actually also returns info on the serial number and product name, while the serial port list only has vidpi.The text was updated successfully, but these errors were encountered: