I’m looking for a way to reconnect serial monitor automatically when the device is unplugged then plugged, or pushed the RST. (I’m using Seeed XIAO ESP32 S3). Especially because I want to capture logs from setup().
Although pio device monitor has auto reconnection by default, it doesn’t recognize the disconnection until I hit any key. Once I hit, it tries to send the key and raise an exception, thus reconnects:
(I hit a key)
Disconnected (ClearCommError failed (PermissionError(13, 'The device does not recognize the command.', None, 22)))
Reconnecting to COM14 Connected!
So, technically I can keep pushing a key to cause this reconnection immediately, but it’s not convenient.
Both Arduino IDE serial monitor and VSCode serial monitor can detect disconnection and reconnect automatically. So, I guess there should be someway to detect it by pio device monitor, too. (I want to use pio device monitor as it’s nicely integrated with VSCode especially when I upload.)
Does anyone have any idea? I can send a PR if it’s the best way!
This is another reason I avoid pio device monitor.
tio handles brief port disconnections, such as those incurred during a device reset, quite well. It can also watch for the NEWEST device and connect to it (the one you already plugged in) or it can await a device to be plugged in (the one you’re about to plug in.)
Since you mention S3, the one case it doesn’t handle transparently is when the device reboots and comes back up wearing Groucho glasses and the system can’t recognize it as the same. I’d have to think through the exact combination, but it’s something like if you are using an S3 or P4 class ESP32 with a USB CDC connection, the device will be named something like /dev/cu.usbmodem110 for being on the first PCI bus with the first USB controller and the 0’th device - or something like that. But if you then hold BOOT and bonk RESET the device will come up in the boot monitor and is actually running a slighty different USB stack. (I think it’s thte one in the boot rom instead of the one in the silicon or vice versa) and now the device will be named /dev/cu.deviceABCDEFG where that last bit is the last several digits of the device’s serial number or something annoyingly different. If this happens, tio doesn’t know that those two are the same device. -a latest will still snag it, but it won’t reconnect automatically like it would have if the dev node had come back with the name name.