blob: 599cef11c8ebc9efcf466b7995f8f02735c6d264 [file] [log] [blame]
Chris Liechti589c92a2015-09-04 23:04:34 +02001=======
2 Tools
3=======
4
5.. module:: serial
6
7serial.tools.list_ports
8=======================
9.. module:: serial.tools.list_ports
10
11This module can be executed to get a list of ports (``python -m
12serial.tools.list_ports``). It also contains the following functions.
13
14
15.. function:: comports()
16
Chris Liechti3ee3eff2015-11-13 02:01:01 +010017 :return: an iterable that yields :class:`ListPortInfo` objects.
Chris Liechti589c92a2015-09-04 23:04:34 +020018
19 The function returns an iterable that yields tuples of three strings:
20
21 - port name as it can be passed to :class:`serial.Serial` or
22 :func:`serial.serial_for_url`
23 - description in human readable form
24 - sort of hardware ID. E.g. may contain VID:PID of USB-serial adapters.
25
26 Items are returned in no particular order. It may make sense to sort the
27 items. Also note that the reported strings are different across platforms
28 and operating systems, even for the same device.
29
30 .. note:: Support is limited to a number of operating systems. On some
31 systems description and hardware ID will not be available
32 (``None``).
33
34 :platform: Posix (/dev files)
35 :platform: Linux (/dev files, sysfs and lsusb)
36 :platform: OSX (iokit)
37 :platform: Windows (setupapi, registry)
38
39
40.. function:: grep(regexp)
41
42 :param regexp: regular expression (see stdlib :mod:`re`)
Chris Liechti3ee3eff2015-11-13 02:01:01 +010043 :return: an iterable that yields :class:`ListPortInfo` objects, see also :func:`comports`.
Chris Liechti589c92a2015-09-04 23:04:34 +020044
45 Search for ports using a regular expression. Port name, description and
46 hardware ID are searched (case insensitive). The function returns an
47 iterable that contains the same tuples that :func:`comport` generates but
48 only those that match the regexp.
49
Chris Liechti3ee3eff2015-11-13 02:01:01 +010050.. class:: ListPortInfo
51
52 This objects holds information about a serial port. It supports indexed
53 access for backwards compatibility, as in ``port, desc, hwid = info``.
54
55 .. attribute:: device
56
57 Full device name/path, e.g. ``/dev/ttyUSB0``. This is also the
58 information returned as first element when accessed by index.
59
60 .. attribute:: name
61
62 Short device name, e.g. ``ttyUSB0``.
63
64 .. attribute:: description
65
66 Human readable description or ``n/a``. This is also the information
67 returned as second element when accessed by index.
68
69 .. attribute:: hwid
70
71 Technical description or ``n/a``. This is also the information
72 returned as third element when accessed by index.
73
74 USB specific data, these are all ``None`` if it is not a USB device (or the
75 platform does not support extended info)
76
77 .. attribute:: vid
78
79 USB Vendor ID (string of hex digits)
80
81 .. attribute:: pid
82
83 USB product ID (string of hex digits)
84
85 .. attribute:: serial_number
86
87 USB serial number as a string
88
89 .. attribute:: location
90
91 USB device location string ("<bus>-<port>[-<port>]...")
92
93 .. attribute:: manufacturer
94
95 USB manufacturer string, as reported by device
96
97 .. attribute:: product
98
99 USB product string, as reported by device
100
101 .. attribute:: interface
102
103 Interface specifc description, e.g. used in compound USB devices.
104
Chris Liechti589c92a2015-09-04 23:04:34 +0200105
106Command line usage
107
108Help for ``python -m serial.tools.list_ports``::
109
110 usage: list_ports.py [-h] [-v] [-q] [-n N] [regexp]
111
112 Serial port enumeration
113
114 positional arguments:
115 regexp only show ports that match this regex
116
117 optional arguments:
118 -h, --help show this help message and exit
119 -v, --verbose show more messages
120 -q, --quiet suppress all messages
121 -n N only output the N-th entry
122
123Examples:
124
125- List all ports with details::
126
127 python -m serial.tools.list_ports -v
128
129- List the 2nd port matching a USB VID:PID pattern::
130
131 python -m serial.tools.list_ports 1234:5678 -q -n 2
132
133.. versionadded:: 2.6
Chris Liechti3ee3eff2015-11-13 02:01:01 +0100134.. versionchanged:: 3.0 returning ListPortInfo objects instead of a tuple
Chris Liechti589c92a2015-09-04 23:04:34 +0200135
136
137.. _miniterm:
138
139serial.tools.miniterm
140=====================
141.. module:: serial.tools.miniterm
142
143This is a console application that provides a small terminal application.
144Miniterm itself does not implement any terminal features such as VT102
145compatibility. However it may inherit these features from the terminal it is run.
146For example on GNU/Linux running from an xterm it will support the escape
147sequences of the xterm. On Windows the typical console window is dumb and does
148not support any escapes. When ANSI.sys is loaded it supports some escapes.
149
150Miniterm::
151
152 --- Miniterm on /dev/ttyS0: 9600,8,N,1 ---
153 --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
154
155Command line options can be given so that binary data including escapes for
156terminals are escaped or output as hex.
157
158Miniterm supports :rfc:`2217` remote serial ports and raw sockets using :ref:`URLs`
159such as ``rfc2217:://<host>:<port>`` respectively ``socket://<host>:<port>`` as
160*port* argument when invoking.
161
162Command line options ``python -m serial.tools.miniterm -h``::
163
164 usage: miniterm.py [-h] [--parity {N,E,O,S,M}] [--rtscts] [--xonxoff]
165 [--rts RTS] [--dtr DTR] [-e] [--encoding CODEC] [-f NAME]
166 [--eol {CR,LF,CRLF}] [--raw] [--exit-char NUM]
167 [--menu-char NUM] [-q] [--develop]
168 [port] [baudrate]
169
170 Miniterm - A simple terminal program for the serial port.
171
172 positional arguments:
173 port serial port name
174 baudrate set baud rate, default: 9600
175
176 optional arguments:
177 -h, --help show this help message and exit
178
179 port settings:
180 --parity {N,E,O,S,M} set parity, one of {N E O S M}, default: N
181 --rtscts enable RTS/CTS flow control (default off)
182 --xonxoff enable software flow control (default off)
183 --rts RTS set initial RTS line state (possible values: 0, 1)
184 --dtr DTR set initial DTR line state (possible values: 0, 1)
185
186 data handling:
187 -e, --echo enable local echo (default off)
188 --encoding CODEC set the encoding for the serial port (e.g. hexlify,
189 Latin1, UTF-8), default: UTF-8
190 -f NAME, --filter NAME
191 add text transformation
192 --eol {CR,LF,CRLF} end of line mode
193 --raw Do no apply any encodings/transformations
194
195 hotkeys:
196 --exit-char NUM Unicode of special character that is used to exit the
197 application, default: 29
198 --menu-char NUM Unicode code of special character that is used to
199 control miniterm (menu), default: 20
200
201 diagnostics:
202 -q, --quiet suppress non-error messages
203 --develop show Python traceback on error
204
205
206Miniterm supports some control functions. Typing :kbd:`Ctrl+T Ctrl+H` when it is
207running shows the help text::
208
209 --- pySerial (3.0a) - miniterm - help
210 ---
211 --- Ctrl+] Exit program
212 --- Ctrl+T Menu escape key, followed by:
213 --- Menu keys:
214 --- Ctrl+T Send the menu character itself to remote
215 --- Ctrl+] Send the exit character itself to remote
216 --- Ctrl+I Show info
217 --- Ctrl+U Upload file (prompt will be shown)
218 --- Ctrl+A encoding
219 --- Ctrl+F edit filters
220 --- Toggles:
221 --- Ctrl+R RTS Ctrl+D DTR Ctrl+B BREAK
222 --- Ctrl+E echo Ctrl+L EOL
223 ---
224 --- Port settings (Ctrl+T followed by the following):
225 --- p change port
226 --- 7 8 set data bits
227 --- N E O S M change parity (None, Even, Odd, Space, Mark)
228 --- 1 2 3 set stop bits (1, 2, 1.5)
229 --- b change baud rate
230 --- x X disable/enable software flow control
231 --- r R disable/enable hardware flow control
232
233.. versionchanged:: 2.5
234 Added :kbd:`Ctrl+T` menu and added support for opening URLs.
235.. versionchanged:: 2.6
236 File moved from the examples to :mod:`serial.tools.miniterm`.
237.. versionchanged:: 3.0
238 Apply encoding on serial port, convert to Unicode for console.
239 Added new filters, default to stripping terminal control sequences.
240