blob: 0710f6fde85d280839c2b0f5ba418c336022953f [file] [log] [blame]
cliechti22978142009-07-21 01:58:11 +00001==========
2 Appendix
3==========
4
cliechti86844e82009-08-12 00:05:33 +00005How To
6======
7
8Enable :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
26Test 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
cliechtia517f4c2011-03-19 00:57:11 +000037FAQ
38===
cliechti4a63d6b2011-03-19 02:57:51 +000039Example works in :ref:`miniterm` but not in script.
cliechtia517f4c2011-03-19 00:57:11 +000040 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
cliechti4a63d6b2011-03-19 02:57:51 +000049Application 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
65User 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 Liechti894d0dd2016-02-08 23:01:01 +010068 ``rfc2217://``.
cliechti4a63d6b2011-03-19 02:57:51 +000069
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
Chris Liechti7ba25cd2016-07-04 21:45:11 +020074``Permission denied`` errors
75 On POSIX based systems, the user usually needs to be in a special group to
76 have access to serial ports.
77
78 On Debian based systems, serial ports are usually in the group ``dialout``,
79 so running ``sudo adduser $USER dialout`` (and logging-out and -in) enables
80 the user to use the port.
81
cliechti4a63d6b2011-03-19 02:57:51 +000082
cliechtibb5c3c52009-07-23 02:29:27 +000083Related software
84================
85
86com0com - http://com0com.sourceforge.net/
87 Provides virtual serial ports for Windows.
88
89
cliechti22978142009-07-21 01:58:11 +000090License
91=======
Chris Liechti06ae1dc2016-05-05 23:54:35 +020092Copyright (c) 2001-2016 Chris Liechti <cliechti@gmx.net>
cliechti22978142009-07-21 01:58:11 +000093All Rights Reserved.
94
Chris Liechti90570b92015-08-04 03:32:02 +020095Redistribution and use in source and binary forms, with or without
96modification, are permitted provided that the following conditions are
97met:
cliechti22978142009-07-21 01:58:11 +000098
Chris Liechti90570b92015-08-04 03:32:02 +020099 * Redistributions of source code must retain the above copyright
100 notice, this list of conditions and the following disclaimer.
cliechti22978142009-07-21 01:58:11 +0000101
Chris Liechti90570b92015-08-04 03:32:02 +0200102 * Redistributions in binary form must reproduce the above
103 copyright notice, this list of conditions and the following
104 disclaimer in the documentation and/or other materials provided
105 with the distribution.
cliechti22978142009-07-21 01:58:11 +0000106
Chris Liechti90570b92015-08-04 03:32:02 +0200107 * Neither the name of the copyright holder nor the names of its
108 contributors may be used to endorse or promote products derived
109 from this software without specific prior written permission.
cliechti22978142009-07-21 01:58:11 +0000110
Chris Liechti90570b92015-08-04 03:32:02 +0200111THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
112"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
113LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
114A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
115HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
116SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
117LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
118DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
119THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
120(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
121OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cliechti22978142009-07-21 01:58:11 +0000122