blob: 8bc2c1a73434fdf5f5a0236ca350fc7dc612b6e9 [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
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
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
cliechti4a63d6b2011-03-19 02:57:51 +000094
cliechtibb5c3c52009-07-23 02:29:27 +000095Related software
96================
97
98com0com - http://com0com.sourceforge.net/
99 Provides virtual serial ports for Windows.
100
101
cliechti22978142009-07-21 01:58:11 +0000102License
103=======
Chris Liechti06ae1dc2016-05-05 23:54:35 +0200104Copyright (c) 2001-2016 Chris Liechti <cliechti@gmx.net>
cliechti22978142009-07-21 01:58:11 +0000105All Rights Reserved.
106
Chris Liechti90570b92015-08-04 03:32:02 +0200107Redistribution and use in source and binary forms, with or without
108modification, are permitted provided that the following conditions are
109met:
cliechti22978142009-07-21 01:58:11 +0000110
Chris Liechti90570b92015-08-04 03:32:02 +0200111 * Redistributions of source code must retain the above copyright
112 notice, this list of conditions and the following disclaimer.
cliechti22978142009-07-21 01:58:11 +0000113
Chris Liechti90570b92015-08-04 03:32:02 +0200114 * 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.
cliechti22978142009-07-21 01:58:11 +0000118
Chris Liechti90570b92015-08-04 03:32:02 +0200119 * 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.
cliechti22978142009-07-21 01:58:11 +0000122
Chris Liechti90570b92015-08-04 03:32:02 +0200123THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
124"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
125LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
126A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
127HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
128SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
129LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
130DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
131THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
132(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
133OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cliechti22978142009-07-21 01:58:11 +0000134