Explorar o código

tools: Fix IDF Monitor so it will wait for the device to reconnect

Roland Dobai %!s(int64=5) %!d(string=hai) anos
pai
achega
b9eb7cb7f0

+ 1 - 0
examples/system/console_usb/main/console_usb_example_main.c

@@ -78,6 +78,7 @@ void app_main(void)
     /* Register commands */
     esp_console_register_help_command();
     register_system_common();
+    register_system_sleep();
     register_nvs();
 
     /* Prompt to be printed before each line.

+ 18 - 1
tools/idf_monitor.py

@@ -382,7 +382,24 @@ class SerialReader(StoppableThread):
             self.serial.dtr = self.serial.dtr   # usbser.sys workaround
         try:
             while self.alive:
-                data = self.serial.read(self.serial.in_waiting or 1)
+                try:
+                    data = self.serial.read(self.serial.in_waiting or 1)
+                except (serial.serialutil.SerialException, IOError) as e:
+                    data = b''
+                    # self.serial.open() was successful before, therefore, this is an issue related to
+                    # the disapperence of the device
+                    red_print(e)
+                    yellow_print('Waiting for the device to reconnect', newline='')
+                    self.serial.close()
+                    while self.alive:  # so that exiting monitor works while waiting
+                        try:
+                            time.sleep(0.5)
+                            self.serial.open()
+                            break  # device connected
+                        except serial.serialutil.SerialException:
+                            yellow_print('.', newline='')
+                            sys.stderr.flush()
+                    yellow_print('')  # go to new line
                 if len(data):
                     self.event_queue.put((TAG_SERIAL, data), False)
         finally: