blob: 57e8e2f9edd211c63c330f7b571567d24ea83e63 [file] [log] [blame]
cliechti22978142009-07-21 01:58:11 +00001==========
2 Appendix
3==========
4
cliechti86844e82009-08-12 00:05:33 +00005How To
6======
7
Chris Liechti961234d2016-09-18 23:54:49 +02008Enable :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
cliechti86844e82009-08-12 00:05:33 +000014 it with::
15
Chris Liechti961234d2016-09-18 23:54:49 +020016 s = serial.serial_for_url(...)
17
18 or for backwards compatibility to old pySerial installations::
19
cliechti86844e82009-08-12 00:05:33 +000020 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
34Test 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 Liechti961234d2016-09-18 23:54:49 +020044 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
cliechti86844e82009-08-12 00:05:33 +000048
cliechtia517f4c2011-03-19 00:57:11 +000049FAQ
50===
cliechti4a63d6b2011-03-19 02:57:51 +000051Example works in :ref:`miniterm` but not in script.
cliechtia517f4c2011-03-19 00:57:11 +000052 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
cliechti4a63d6b2011-03-19 02:57:51 +000061Application 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
Chris Liechtibc6031c2017-03-21 01:54:03 +010071 at runtime. If this function is used, the desired handlers have to be
cliechti4a63d6b2011-03-19 02:57:51 +000072 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
77User 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 Liechti894d0dd2016-02-08 23:01:01 +010080 ``rfc2217://``.
cliechti4a63d6b2011-03-19 02:57:51 +000081
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 Liechti7ba25cd2016-07-04 21:45:11 +020086``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 Liechtid389f8a2016-07-11 23:32:21 +020092 the user to access the port.
Chris Liechti7ba25cd2016-07-04 21:45:11 +020093
Chris Liechti5f52b6a2016-12-13 23:52:41 +010094Support for Python 2.6 or earlier
95 Support for older Python releases than 2.7 will not return to pySerial 3.x.
Chris Liechtibc6031c2017-03-21 01:54:03 +010096 Python 2.7 is now many years old (released 2010). If you insist on using
Chris Liechti5f52b6a2016-12-13 23:52:41 +010097 Python 2.6 or earlier, it is recommend to use pySerial `2.7`_
98 (or any 2.x version).
99
100.. _`2.7`: https://pypi.python.org/pypi/pyserial/2.7
101
cliechti4a63d6b2011-03-19 02:57:51 +0000102
cliechtibb5c3c52009-07-23 02:29:27 +0000103Related software
104================
105
106com0com - http://com0com.sourceforge.net/
107 Provides virtual serial ports for Windows.
108
109
cliechti22978142009-07-21 01:58:11 +0000110License
111=======
Chris Liechtibc6031c2017-03-21 01:54:03 +0100112Copyright (c) 2001-2017 Chris Liechti <cliechti@gmx.net>
cliechti22978142009-07-21 01:58:11 +0000113All Rights Reserved.
114
Chris Liechti90570b92015-08-04 03:32:02 +0200115Redistribution and use in source and binary forms, with or without
116modification, are permitted provided that the following conditions are
117met:
cliechti22978142009-07-21 01:58:11 +0000118
Chris Liechti90570b92015-08-04 03:32:02 +0200119 * Redistributions of source code must retain the above copyright
120 notice, this list of conditions and the following disclaimer.
cliechti22978142009-07-21 01:58:11 +0000121
Chris Liechti90570b92015-08-04 03:32:02 +0200122 * Redistributions in binary form must reproduce the above
123 copyright notice, this list of conditions and the following
124 disclaimer in the documentation and/or other materials provided
125 with the distribution.
cliechti22978142009-07-21 01:58:11 +0000126
Chris Liechti90570b92015-08-04 03:32:02 +0200127 * Neither the name of the copyright holder nor the names of its
128 contributors may be used to endorse or promote products derived
129 from this software without specific prior written permission.
cliechti22978142009-07-21 01:58:11 +0000130
Chris Liechti90570b92015-08-04 03:32:02 +0200131THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
132"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
133LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
134A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
135HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
136SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
137LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
138DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
139THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
140(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
141OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cliechti22978142009-07-21 01:58:11 +0000142