blob: 962c98b75d342f2a1a4dab0403ac06b74735856e [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
17 :return: an iterable.
18
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`)
43 :return: filtered sequence, see :func:`comports`.
44
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
50
51Command line usage
52
53Help for ``python -m serial.tools.list_ports``::
54
55 usage: list_ports.py [-h] [-v] [-q] [-n N] [regexp]
56
57 Serial port enumeration
58
59 positional arguments:
60 regexp only show ports that match this regex
61
62 optional arguments:
63 -h, --help show this help message and exit
64 -v, --verbose show more messages
65 -q, --quiet suppress all messages
66 -n N only output the N-th entry
67
68Examples:
69
70- List all ports with details::
71
72 python -m serial.tools.list_ports -v
73
74- List the 2nd port matching a USB VID:PID pattern::
75
76 python -m serial.tools.list_ports 1234:5678 -q -n 2
77
78.. versionadded:: 2.6
79
80
81.. _miniterm:
82
83serial.tools.miniterm
84=====================
85.. module:: serial.tools.miniterm
86
87This is a console application that provides a small terminal application.
88Miniterm itself does not implement any terminal features such as VT102
89compatibility. However it may inherit these features from the terminal it is run.
90For example on GNU/Linux running from an xterm it will support the escape
91sequences of the xterm. On Windows the typical console window is dumb and does
92not support any escapes. When ANSI.sys is loaded it supports some escapes.
93
94Miniterm::
95
96 --- Miniterm on /dev/ttyS0: 9600,8,N,1 ---
97 --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
98
99Command line options can be given so that binary data including escapes for
100terminals are escaped or output as hex.
101
102Miniterm supports :rfc:`2217` remote serial ports and raw sockets using :ref:`URLs`
103such as ``rfc2217:://<host>:<port>`` respectively ``socket://<host>:<port>`` as
104*port* argument when invoking.
105
106Command line options ``python -m serial.tools.miniterm -h``::
107
108 usage: miniterm.py [-h] [--parity {N,E,O,S,M}] [--rtscts] [--xonxoff]
109 [--rts RTS] [--dtr DTR] [-e] [--encoding CODEC] [-f NAME]
110 [--eol {CR,LF,CRLF}] [--raw] [--exit-char NUM]
111 [--menu-char NUM] [-q] [--develop]
112 [port] [baudrate]
113
114 Miniterm - A simple terminal program for the serial port.
115
116 positional arguments:
117 port serial port name
118 baudrate set baud rate, default: 9600
119
120 optional arguments:
121 -h, --help show this help message and exit
122
123 port settings:
124 --parity {N,E,O,S,M} set parity, one of {N E O S M}, default: N
125 --rtscts enable RTS/CTS flow control (default off)
126 --xonxoff enable software flow control (default off)
127 --rts RTS set initial RTS line state (possible values: 0, 1)
128 --dtr DTR set initial DTR line state (possible values: 0, 1)
129
130 data handling:
131 -e, --echo enable local echo (default off)
132 --encoding CODEC set the encoding for the serial port (e.g. hexlify,
133 Latin1, UTF-8), default: UTF-8
134 -f NAME, --filter NAME
135 add text transformation
136 --eol {CR,LF,CRLF} end of line mode
137 --raw Do no apply any encodings/transformations
138
139 hotkeys:
140 --exit-char NUM Unicode of special character that is used to exit the
141 application, default: 29
142 --menu-char NUM Unicode code of special character that is used to
143 control miniterm (menu), default: 20
144
145 diagnostics:
146 -q, --quiet suppress non-error messages
147 --develop show Python traceback on error
148
149
150Miniterm supports some control functions. Typing :kbd:`Ctrl+T Ctrl+H` when it is
151running shows the help text::
152
153 --- pySerial (3.0a) - miniterm - help
154 ---
155 --- Ctrl+] Exit program
156 --- Ctrl+T Menu escape key, followed by:
157 --- Menu keys:
158 --- Ctrl+T Send the menu character itself to remote
159 --- Ctrl+] Send the exit character itself to remote
160 --- Ctrl+I Show info
161 --- Ctrl+U Upload file (prompt will be shown)
162 --- Ctrl+A encoding
163 --- Ctrl+F edit filters
164 --- Toggles:
165 --- Ctrl+R RTS Ctrl+D DTR Ctrl+B BREAK
166 --- Ctrl+E echo Ctrl+L EOL
167 ---
168 --- Port settings (Ctrl+T followed by the following):
169 --- p change port
170 --- 7 8 set data bits
171 --- N E O S M change parity (None, Even, Odd, Space, Mark)
172 --- 1 2 3 set stop bits (1, 2, 1.5)
173 --- b change baud rate
174 --- x X disable/enable software flow control
175 --- r R disable/enable hardware flow control
176
177.. versionchanged:: 2.5
178 Added :kbd:`Ctrl+T` menu and added support for opening URLs.
179.. versionchanged:: 2.6
180 File moved from the examples to :mod:`serial.tools.miniterm`.
181.. versionchanged:: 3.0
182 Apply encoding on serial port, convert to Unicode for console.
183 Added new filters, default to stripping terminal control sequences.
184