Merge branch 'bugfix/monitor_wait_reconnect' into 'master'

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

Closes IDF-1640

See merge request espressif/esp-idf!8632
This commit is contained in:
Ivan Grokhotkov 2020-07-06 15:18:48 +08:00
commit 59f5e9af37
2 changed files with 19 additions and 1 deletions

View file

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

View file

@ -382,7 +382,24 @@ class SerialReader(StoppableThread):
self.serial.dtr = self.serial.dtr # usbser.sys workaround self.serial.dtr = self.serial.dtr # usbser.sys workaround
try: try:
while self.alive: while self.alive:
try:
data = self.serial.read(self.serial.in_waiting or 1) 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): if len(data):
self.event_queue.put((TAG_SERIAL, data), False) self.event_queue.put((TAG_SERIAL, data), False)
finally: finally: