cliechti | 2297814 | 2009-07-21 01:58:11 +0000 | [diff] [blame] | 1 | ========== |
| 2 | Appendix |
| 3 | ========== |
| 4 | |
cliechti | 86844e8 | 2009-08-12 00:05:33 +0000 | [diff] [blame] | 5 | How To |
| 6 | ====== |
| 7 | |
| 8 | Enable :rfc:`2217` in programs using pySerial. |
| 9 | Patch the code where the :class:`serial.Serial` is instantiated. Replace |
| 10 | it with:: |
| 11 | |
| 12 | try: |
| 13 | s = serial.serial_for_url(...) |
| 14 | except AttributeError: |
| 15 | s = serial.Serial(...) |
| 16 | |
| 17 | Assuming the application already stores port names as strings that's all |
| 18 | that is required. The user just needs a way to change the port setting of |
| 19 | your application to an ``rfc2217://`` :ref:`URL <URLs>` (e.g. by editing a |
| 20 | configuration file, GUI dialog etc.). |
| 21 | |
| 22 | Please note that this enables all :ref:`URL <URLs>` types supported by |
| 23 | pySerial and that those involving the network are unencrypted and not |
| 24 | protected against eavesdropping. |
| 25 | |
| 26 | Test your setup. |
| 27 | Is the device not working as expected? Maybe it's time to check the |
| 28 | connection before proceeding. :ref:`miniterm` from the :ref:`examples` |
| 29 | can be used to open the serial port and do some basic tests. |
| 30 | |
| 31 | To test cables, connecting RX to TX (loop back) and typing some characters |
| 32 | in :ref:`miniterm` is a simple test. When the characters are displayed |
| 33 | on the screen, then at least RX and TX work (they still could be swapped |
| 34 | though). |
| 35 | |
| 36 | |
cliechti | a517f4c | 2011-03-19 00:57:11 +0000 | [diff] [blame] | 37 | FAQ |
| 38 | === |
cliechti | 4a63d6b | 2011-03-19 02:57:51 +0000 | [diff] [blame] | 39 | Example works in :ref:`miniterm` but not in script. |
cliechti | a517f4c | 2011-03-19 00:57:11 +0000 | [diff] [blame] | 40 | The RTS and DTR lines are switched when the port is opened. This may cause |
| 41 | some processing or reset on the connected device. In such a cases an |
| 42 | immediately following call to :meth:`write` may not be received by the |
| 43 | device. |
| 44 | |
| 45 | A delay after opening the port, before the first :meth:`write`, is |
| 46 | recommended in this situation. E.g. a ``time.sleep(1)`` |
| 47 | |
| 48 | |
cliechti | 4a63d6b | 2011-03-19 02:57:51 +0000 | [diff] [blame] | 49 | Application works when .py file is run, but fails when packaged (py2exe etc.) |
| 50 | py2exe and similar packaging programs scan the sources for import |
| 51 | statements and create a list of modules that they package. pySerial may |
| 52 | create two issues with that: |
| 53 | |
| 54 | - implementations for other modules are found. On Windows, it's safe to |
| 55 | exclude 'serialposix', 'serialjava' and 'serialcli' as these are not |
| 56 | used. |
| 57 | |
| 58 | - :func:`serial.serial_for_url` does a dynamic lookup of protocol handlers |
| 59 | at runtime. If this function is used, the desired handlers have to be |
| 60 | included manually (e.g. 'serial.urlhandler.protocol_socket', |
| 61 | 'serial.urlhandler.protocol_rfc2217', etc.). This can be done either with |
| 62 | the "includes" option in ``setup.py`` or by a dummy import in one of the |
| 63 | packaged modules. |
| 64 | |
| 65 | User supplied URL handlers |
| 66 | :func:`serial.serial_for_url` can be used to access "virtual" serial ports |
| 67 | identified by an :ref:`URL <URLs>` scheme. E.g. for the :rfc:`2217`: |
Chris Liechti | 894d0dd | 2016-02-08 23:01:01 +0100 | [diff] [blame] | 68 | ``rfc2217://``. |
cliechti | 4a63d6b | 2011-03-19 02:57:51 +0000 | [diff] [blame] | 69 | |
| 70 | Custom :ref:`URL <URLs>` handlers can be added by extending the module |
| 71 | search path in :data:`serial.protocol_handler_packages`. This is possible |
| 72 | starting from pySerial V2.6. |
| 73 | |
| 74 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 75 | Related software |
| 76 | ================ |
| 77 | |
| 78 | com0com - http://com0com.sourceforge.net/ |
| 79 | Provides virtual serial ports for Windows. |
| 80 | |
| 81 | |
cliechti | 2297814 | 2009-07-21 01:58:11 +0000 | [diff] [blame] | 82 | License |
| 83 | ======= |
Chris Liechti | 06ae1dc | 2016-05-05 23:54:35 +0200 | [diff] [blame] | 84 | Copyright (c) 2001-2016 Chris Liechti <cliechti@gmx.net> |
cliechti | 2297814 | 2009-07-21 01:58:11 +0000 | [diff] [blame] | 85 | All Rights Reserved. |
| 86 | |
Chris Liechti | 90570b9 | 2015-08-04 03:32:02 +0200 | [diff] [blame] | 87 | Redistribution and use in source and binary forms, with or without |
| 88 | modification, are permitted provided that the following conditions are |
| 89 | met: |
cliechti | 2297814 | 2009-07-21 01:58:11 +0000 | [diff] [blame] | 90 | |
Chris Liechti | 90570b9 | 2015-08-04 03:32:02 +0200 | [diff] [blame] | 91 | * Redistributions of source code must retain the above copyright |
| 92 | notice, this list of conditions and the following disclaimer. |
cliechti | 2297814 | 2009-07-21 01:58:11 +0000 | [diff] [blame] | 93 | |
Chris Liechti | 90570b9 | 2015-08-04 03:32:02 +0200 | [diff] [blame] | 94 | * Redistributions in binary form must reproduce the above |
| 95 | copyright notice, this list of conditions and the following |
| 96 | disclaimer in the documentation and/or other materials provided |
| 97 | with the distribution. |
cliechti | 2297814 | 2009-07-21 01:58:11 +0000 | [diff] [blame] | 98 | |
Chris Liechti | 90570b9 | 2015-08-04 03:32:02 +0200 | [diff] [blame] | 99 | * Neither the name of the copyright holder nor the names of its |
| 100 | contributors may be used to endorse or promote products derived |
| 101 | from this software without specific prior written permission. |
cliechti | 2297814 | 2009-07-21 01:58:11 +0000 | [diff] [blame] | 102 | |
Chris Liechti | 90570b9 | 2015-08-04 03:32:02 +0200 | [diff] [blame] | 103 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 104 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 105 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 106 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 107 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 108 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 109 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 110 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 111 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 112 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 113 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
cliechti | 2297814 | 2009-07-21 01:58:11 +0000 | [diff] [blame] | 114 | |