Hi Nikita,
Your Monitor program looks great. I spun up a much simpler serial monitor program for my own use some time ago. My main motivation for doing this was that I hated the way most serial monitor programs required manual intervention around the connect and disconnect operations. As microcontrollers reboot and are re-flashed they disconnect their USB connection which is viewed by the OS’s as the tty closing. What my program does is continue to monitor the tty and automatically reconnect when it becomes available again. I cannot tell you how extremely valuable this has been to me. It is such a simple thing, and I would suggest you implement it.
Also, I have noticed recent behavior where the tty device that a USB connection is assigned to can change. In particular in MacOS for some reason the device name can sometimes start sequencing /dev/tty.usbxxxx1 then /dev/tty.usbxxxx2, etc… It is easy enough to query the /dev directory for tty.usb* and just connect to the one that appears. You may want to do something like this too.
I hope this helps and your project is successful.
- Rich