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