Patch the code where the serial.Serial is instantiated. Replace it with:
try:
s = serial.serial_for_url(...)
except AttributeError:
s = serial.Serial(...)
Assuming the application already stores port names as strings that’s all that is required. The user just needs a way to change the port setting of your application to an rfc2217:// URL (e.g. by editing a configuration file, GUI dialog etc.).
Please note that this enables all URL types supported by pySerial and that those involving the network are unencrypted and not protected against eavesdropping.
Is the device not working as expected? Maybe it’s time to check the connection before proceeding. Miniterm from the Examples can be used to open the serial port and do some basic tests.
To test cables, connecting RX to TX (loop back) and typing some characters in Miniterm is a simple test. When the characters are displayed on the screen, then at least RX and TX work (they still could be swapped though).
The RTS and DTR lines are switched when the port is opened. This may cause some processing or reset on the connected device. In such a cases an immediately following call to write() may not be received by the device.
A delay after opening the port, before the first write(), is recommended in this situation. E.g. a time.sleep(1)
py2exe and similar packaging programs scan the sources for import statements and create a list of modules that they package. pySerial may create two issues with that:
serial.serial_for_url() can be used to access “virtual” serial ports identified by an URL scheme. E.g. for the RFC 2217: rfc2217:://.
Custom URL handlers can be added by extending the module search path in serial.protocol_handler_packages. This is possible starting from pySerial V2.6.
Copyright (C) 2001-2011 Chris Liechti <cliechti(at)gmx.net>; All Rights Reserved.
This is the Python license. In short, you can use this product in commercial and non-commercial applications, modify it, redistribute it. A notification to the author when you use and/or modify it is welcome.
TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING THIS SOFTWARE
LICENSE AGREEMENT