(Note: this is my second pull request made today for grabserial, so it might make sense to look at the other one first. The other one (#38 ) is also much simpler -- some minor bug fixes.)
This pull request allows grabserial to handle disconnections of the serial device. I.e. if you have a USB UART, and you unplug it from the USB port.
Tested on Linux, Python 2 and 3. Tested on Windows, Python 2. Tested that it still restarts with -q and -e options. Tested that you can quit using Ctrl-C without causing an error when UART is disconnected or connected. Tested that it works when the program starts with the UART disconnected, and then it is plugged in afterwards.
Note that this "restart on disconnect" feature requires that the user specify the "-S" option, otherwise grabserial will quit when it fails to find the serial port device, because it won't exist when you unplug the UART.
Do you want me to add another command-line option for restarting upon disconnects, or just leave it as the default behaviour (it still requires "-S")? Perhaps the "-a" option could be modified to allow things like "-a=eqd", where 'e' means restart on timeout, 'q' for restart on quitpat, and 'd' for restart on disconnect.
Also, the use of "restart on disconnect" requires stable device names. I.e. when you disconnect /dev/ttyUSB2, and re-connect it, it must appear as /dev/ttyUSB2. Stable device names can be achieved with udev rules. Do you want me to add some text to explain these things? Maybe in the README, because it would be a bit too much text to put in the 'usage' string.
Let me know if you think anything in the code should be changed.
Hi Tim,
(Note: this is my second pull request made today for grabserial, so it might make sense to look at the other one first. The other one (#38 ) is also much simpler -- some minor bug fixes.)
This pull request allows grabserial to handle disconnections of the serial device. I.e. if you have a USB UART, and you unplug it from the USB port.
Example usage: grabserial -S -a ...