blob: 5d8bae0af74f8c6d501627dc7561b3c501a0a029 [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
74
cliechtibb5c3c52009-07-23 02:29:27 +000075Related software
76================
77
78com0com - http://com0com.sourceforge.net/
79 Provides virtual serial ports for Windows.
80
81
cliechti22978142009-07-21 01:58:11 +000082License
83=======
Chris Liechti06ae1dc2016-05-05 23:54:35 +020084Copyright (c) 2001-2016 Chris Liechti <cliechti@gmx.net>
cliechti22978142009-07-21 01:58:11 +000085All Rights Reserved.
86
Chris Liechti90570b92015-08-04 03:32:02 +020087Redistribution and use in source and binary forms, with or without
88modification, are permitted provided that the following conditions are
89met:
cliechti22978142009-07-21 01:58:11 +000090
Chris Liechti90570b92015-08-04 03:32:02 +020091 * Redistributions of source code must retain the above copyright
92 notice, this list of conditions and the following disclaimer.
cliechti22978142009-07-21 01:58:11 +000093
Chris Liechti90570b92015-08-04 03:32:02 +020094 * 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.
cliechti22978142009-07-21 01:58:11 +000098
Chris Liechti90570b92015-08-04 03:32:02 +020099 * 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.
cliechti22978142009-07-21 01:58:11 +0000102
Chris Liechti90570b92015-08-04 03:32:02 +0200103THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
104"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
105LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
106A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
107HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
108SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
109LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
110DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
111THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
112(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
113OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cliechti22978142009-07-21 01:58:11 +0000114