It would be nice if there was a way to save the serial port configuration when opening it, and restoring it when closing it. My situation is that I have a python app running on a Gumstix using the serial console. It is intended to communicate with the second serial port, but for testing, I let it use the serial console port. When I terminate the program, I'm left with my serial port still in raw mode, and I have to blindly type "stty sane" to recover, and then reload my key assignments. It would be nice if I didn't have to do this.
One way to implement this would be to have the open() method return an object (perhaps a dictionary) that contains all the settings, and provide another method for applying all the settings, which the user could call before closing. If that's exposing too much to the user, the settings could be stored internally, along with an attribute flag that tells whether the settings should be restored on close.
What should be saved/restored should at least be everything changed on open. If it used a dictionary to support everything "stty", "setserial" and "bind" supports under Linux (and whatever smaller set of attributes Windows supports), then it would make pyserial useful as a general purpose serial port configurator.
Log in to post a comment.