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

This commit is contained in:
Roland Dobai 2020-05-06 15:39:47 +02:00
parent eff2aa8094
commit b9eb7cb7f0
2 changed files with 19 additions and 1 deletions

View file

@ -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.

View file

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