Skip to content
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

Serial Monitor loses connection after PC sleeps #1895

Open
3 tasks done
per1234 opened this issue Feb 20, 2023 · 1 comment
Open
3 tasks done

Serial Monitor loses connection after PC sleeps #1895

per1234 opened this issue Feb 20, 2023 · 1 comment
Labels
topic: code Related to content of the project itself topic: serial monitor Related to the Serial Monitor type: imperfection Perceived defect in any part of project

Comments

@per1234
Copy link
Contributor

per1234 commented Feb 20, 2023

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: #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

  • Windows
  • macOS

Operating system version

  • Windows 11
  • macOS Ventura

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:  {}
�[36mINFO�[0m[0036] sending command                               �[36mcommand�[0m=CLOSE �[36mmonitor�[0m=serial-monitor

2023-02-19 19:07:01 2023-02-20T03:07:01.609Z daemon INFO �[36mINFO�[0m[0036] received message                              �[36merror�[0m=false �[36mevent_type�[0m=close �[36mmessage�[0m=OK �[36mmonitor�[0m=serial-monitor
�[36mINFO�[0m[0036] sending command                               �[36mcommand�[0m=QUIT �[36mmonitor�[0m=serial-monitor
�[36mINFO�[0m[0036] received message                              �[36merror�[0m=false �[36mevent_type�[0m=quit �[36mmessage�[0m=OK �[36mmonitor�[0m=serial-monitor
�[36mINFO�[0m[0036] Killing monitor process                       �[36mmonitor�[0m=serial-monitor
�[31mERRO�[0m[0036] stopped decode loop: EOF                      �[31mmonitor�[0m=serial-monitor

2023-02-19 19:07:01 2023-02-20T03:07:01.614Z daemon INFO �[31mERRO�[0m[0036] Waiting for process end                       �[31merror�[0m="exit status 1" �[31mmonitor�[0m=serial-monitor
�[36mINFO�[0m[0036] Monitor process killed                        �[36mmonitor�[0m=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

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest nightly build
  • My report contains all necessary details
@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project topic: serial monitor Related to the Serial Monitor labels Feb 20, 2023
@alastaira

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself topic: serial monitor Related to the Serial Monitor type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants