arduino / arduino-ide

Arduino IDE 2.x
https://www.arduino.cc/en/software
GNU Affero General Public License v3.0
2.35k stars 395 forks source link

Serial Monitor loses connection after PC sleeps #1895

Open per1234 opened 1 year ago

per1234 commented 1 year ago

Describe the problem

Serial Monitor is the primary tool for Arduino IDE users to get runtime feedback from a sketch program. Since it is not intrusive and does not interfere with the usability of the other Arduino IDE UI components, the average user likely has the Serial Monitor open most of the time.

Putting the computer through a sleep/wake cycle while Serial Monitor is open causes loss of connection to the port.

πŸ› When in this state, Serial Monitor does not show data sent by the board and does not transmit messages the user sends from the message field. It does not give any indication of the lost connection to the user.

To reproduce

  1. Upload a sketch that produces periodic serial output and also has an observable response to serial input:

    unsigned long previousMillis;
    
    void setup() {
     Serial.begin(9600);
    }
    
    void loop() {
     if (Serial.available() > 0) {
       while (Serial.available() > 0) {
         Serial.write(Serial.read());
         delay(10);
       }
     } else if (millis() - previousMillis >= 1000) {
       previousMillis = millis();
       Serial.println("hello");
     }
    }
  2. Open the Serial Monitor view.
  3. Select "9600" from the baud rate menu. πŸ™‚ hello is printed in the Serial Monitor output field at 1 Hz.
  4. Type foo in the Serial Monitor message field.
  5. Press the Enter key. πŸ™‚ foo is echoed in the Serial Monitor output field.
  6. Put the computer to sleep.
  7. Wake the computer. πŸ› hello is no longer printed in the Serial Monitor output field at 1 Hz, even though the TX LED on the Arduino board shows it is transmitting serial data. πŸ› There is no indication of a lost connection in the Serial Monitor UI.
  8. Type foo in the Serial Monitor message field.
  9. Press the Enter key. πŸ› The RX LED does not blink on the Arduino board to indicate serial data was received. πŸ› foo is not echoed in the Serial Monitor output field.

Expected behavior

Putting computer through a sleep/wake cycle does not cause the loss of Serial Monitor's connection to the port.

-OR-

The loss of the connection is clearly communicated to the user (related issue: https://github.com/arduino/arduino-ide/issues/1508).

Arduino IDE version

Original report

d68bc4a (with serial-monitor 0.13.0)

Last verified with

8f8b46f (with serial-monitor 0.13.0)

Operating system

Operating system version

Additional context

I was not able to reproduce the issue on my Linux (Ubuntu 22.04) machine.


The fault does not occur under the same conditions when using arduino-cli monitor, the Arduino CLI gRPC interface with grpcurl, or Arduino IDE 1.8.19


When the arduino.cli.daemon.debug setting is enabled, I see this in the logs from the time the PC is put to sleep:

2023-02-19 19:07:01 2023-02-20T03:07:01.601Z monitor-service INFO stopped monitor to COM34 using serial
2023-02-19 19:07:01 2023-02-20T03:07:01.603Z daemon INFO 51 |  ERROR:  EOF
51 |  REQ:  {}
INFO[0036] sending command                               command=CLOSE monitor=serial-monitor

2023-02-19 19:07:01 2023-02-20T03:07:01.609Z daemon INFO INFO[0036] received message                              error=false event_type=close message=OK monitor=serial-monitor
INFO[0036] sending command                               command=QUIT monitor=serial-monitor
INFO[0036] received message                              error=false event_type=quit message=OK monitor=serial-monitor
INFO[0036] Killing monitor process                       monitor=serial-monitor
ERRO[0036] stopped decode loop: EOF                      monitor=serial-monitor

2023-02-19 19:07:01 2023-02-20T03:07:01.614Z daemon INFO ERRO[0036] Waiting for process end                       error="exit status 1" monitor=serial-monitor
INFO[0036] Monitor process killed                        monitor=serial-monitor
51 STREAM CLOSED

But there is no equivalent log output to indicate an attempt to start the monitor process again after the PC wakes.


The fault occurs both with boards that have a dedicated USB chip (e.g., Uno) and boards with native USB (e.g., Leonardo).


Originally reported at: https://forum.arduino.cc/t/ide-disconnect-form-the-board-after-pc-suspension/1092323

Additional reports

Workaround

  1. Click the X icon on the "Serial Monitor" tab in the bottom panel of the Arduino IDE window to close the tab: image
  2. Open Serial Monitor again by clicking the icon on the IDE toolbar or selecting Tools > Serial Monitor from the Arduino IDE menus.

Issue checklist

alastaira commented 5 months ago

I'm pleased to see this issue reported here, since it's one of those low-impact, but incredibly frequent bugs I encounter (not to mention a regression from 1.8.x) - has there been any progress on a fix?