blob: e0181bbb162d687c8932466b8fcf46e494507059 [file] [log] [blame]
cliechti86e87872009-07-21 13:32:45 +00001==========
2 Examples
3==========
4
5Miniterm
6========
7This is a console application that provides a small terminal application.
8miniterm itself does not implement any terminal features such as VT102
9compatibility. However it inherits these features from the terminal it is run.
10For example on GNU/Linux running from an xterm it will support the escape
11sequences of the xterm. On Windows the typical console window is dumb and does
12not support any escapes. When ANSI.sys is loaded it supports some escapes.
13
cliechti5134aab2009-07-21 19:47:59 +000014miniterm::
15
16 --- Miniterm on /dev/ttyS0: 9600,8,N,1 ---
17 --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
18
cliechti86e87872009-07-21 13:32:45 +000019Command line options can be given so that binary data including escapes for
20terminals are escaped or output as hex.
21
cliechti5134aab2009-07-21 19:47:59 +000022Command line options ``miniterm.py -h``::
23
24 Usage: miniterm.py [options] [port [baudrate]]
25
26 Miniterm - A simple terminal program for the serial port.
27
28 Options:
29 -h, --help show this help message and exit
30 -p PORT, --port=PORT port, a number (default 0) or a device name
31 (deprecated option)
32 -b BAUDRATE, --baud=BAUDRATE
33 set baud rate, default 9600
34 --parity=PARITY set parity, one of [N, E, O, S, M], default=N
35 -e, --echo enable local echo (default off)
36 --rtscts enable RTS/CTS flow control (default off)
37 --xonxoff enable software flow control (default off)
38 --cr do not send CR+LF, send CR only
39 --lf do not send CR+LF, send LF only
40 -D, --debug debug received data (escape non-printable chars)
41 --debug can be given multiple times: 0: just print
42 what is received 1: escape non-printable characters,
43 do newlines as unusual 2: escape non-printable
44 characters, newlines too 3: hex dump everything
45 --rts=RTS_STATE set initial RTS line state (possible values: 0, 1)
46 --dtr=DTR_STATE set initial DTR line state (possible values: 0, 1)
47 -q, --quiet suppress non error messages
48 --exit-char=EXIT_CHAR
49 ASCII code of special character that is used to exit
50 the application
51 --menu-char=MENU_CHAR
52 ASCII code of special character that is used to
53 control miniterm (menu)
54
55
56miniterm supports some control functions. Typing :kbd:`Control+t Control+h` when it is
57running shows the help text::
58
59 --- pySerial - miniterm - help
60 ---
61 --- Ctrl+] Exit program
62 --- Ctrl+T Menu escape key, followed by:
63 --- Menu keys:
64 --- Ctrl+T Send the menu character itself to remote
65 --- Ctrl+] Send the exit character to remote
66 --- Ctrl+I Show info
67 --- Ctrl+U Upload file (prompt will be shown)
68 --- Toggles:
69 --- Ctrl+R RTS Ctrl+E local echo
70 --- Ctrl+D DTR Ctrl+B BREAK
71 --- Ctrl+L line feed Ctrl+A Cycle repr mode
72 ---
73 --- Port settings (Ctrl+T followed by the following):
74 --- 7 8 set data bits
75 --- n e o s m change parity (None, Even, Odd, Space, Mark)
76 --- 1 2 3 set stop bits (1, 2, 1.5)
77 --- b change baud rate
78 --- x X disable/enable software flow control
79 --- r R disable/enable hardware flow control
80
cliechti86e87872009-07-21 13:32:45 +000081
82miniterm.py_
83 The miniterm program.
84
85setup-miniterm-py2exe.py_
86 This is a py2exe setup script for Windows. It can be used to create a
87 standalone ``miniterm.exe``.
88
89.. _miniterm.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/miniterm.py
90.. _setup-miniterm-py2exe.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/setup-miniterm-py2exe.py
91
92
93TCP/IP - serial bridge
94======================
95This program opens a TCP/IP port. When a connection is made to that port (e.g.
96with telnet) it forwards all data to the serial port and vice versa.
97
98The serial port settings are set on the command line when starting the program.
99There is no possibility to change settings from remote.
cliechti5134aab2009-07-21 19:47:59 +0000100::
101
102 Usage: tcp_serial_redirect.py [options] [port [baudrate]]
103
104 Simple Serial to Network (TCP/IP) redirector.
105
106 Options:
107 -h, --help show this help message and exit
108 -q, --quiet suppress non error messages
109 --spy peek at the communication and print all data to the
110 console
111
112 Serial Port:
113 Serial port settings
114
115 -p PORT, --port=PORT
116 port, a number (default 0) or a device name
117 -b BAUDRATE, --baud=BAUDRATE
118 set baud rate, default: 9600
119 --parity=PARITY set parity, one of [N, E, O], default=N
120 --rtscts enable RTS/CTS flow control (default off)
121 --xonxoff enable software flow control (default off)
122 --rts=RTS_STATE set initial RTS line state (possible values: 0, 1)
123 --dtr=DTR_STATE set initial DTR line state (possible values: 0, 1)
124
125 Network settings:
126 Network configuration.
127
128 -P LOCAL_PORT, --localport=LOCAL_PORT
129 local TCP port
130
131 Newline Settings:
132 Convert newlines between network and serial port. Conversion is
133 normally disabled and can be enabled by --convert.
134
135 -c, --convert enable newline conversion (default off)
136 --net-nl=NET_NEWLINE
137 type of newlines that are expected on the network
138 (default: LF)
139 --ser-nl=SER_NEWLINE
140 type of newlines that are expected on the serial port
141 (default: CR+LF)
142
143 NOTE: no security measures are implemented. Anyone can remotely connect to
144 this service over the network. Only one connection at once is supported. When
145 the connection is terminated it waits for the next connect.
146
cliechti86e87872009-07-21 13:32:45 +0000147
148tcp_serial_redirect.py_
149 Main program.
150
151.. _tcp_serial_redirect.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/tcp_serial_redirect.py
152
153
cliechtibb5c3c52009-07-23 02:29:27 +0000154Multi-port TCP/IP - serial bridge
155=================================
156This example implements a TCP/IP to serial port service that works with
157multiple ports at once. It uses select, no threads, and runs on POSIX systems
158only.
159
160- Check existence of ``/tty/USB0...9``.
161- Ports are periodically checked using ``os.path.exists``.
162- Send Zeroconfig announcements when port appears or disappears (uses
163 python-avahi and dbus).
164- Single process for all ports (not per port).
165- All published services are kept in a dictionary that maps device->publisher
166 object.
167- A delay of 5 seconds slows down the poll loop to a reasonable period.
168- The script implements a daemon that logs to the syslog, unless specified
169 otherwise on the command line.
170
171
172Requirements
173------------
174- python (>2.4)
175- python-avahi
176- python-dbus
177- python-serial
178
179
180Installation
181------------
182- Copy the script ``port_publisher.py`` to ``/usr/local/bin``.
183- Copy the script ``port_publisher.sh`` to ``/etc/init.d``.
184- Add links to the runlevels using ``update-rc.d port_publisher.sh defaults 99``
185- Thats it :-) the service will be started on next reboot. Alternatively run
186 ``invoke-rc.d port_publisher.sh start`` as root.
187
188
189port_publisher.py_
190 Multi-port TCP/IP-serial converter for POSIX environments.
191
192port_publisher.sh_
193 Example init.d script.
194
195.. _port_publisher.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/port_publisher.py
196.. _port_publisher.sh: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/port_publisher.sh
197
198
cliechti86e87872009-07-21 13:32:45 +0000199wxPython examples
200=================
201A simple terminal application for wxPython and a flexible serial port
202configuration dialog are shown here.
203
204wxTerminal.py_
205 A simple terminal application. Note that the length of the buffer is
206 limited by wx and it may suddenly stop displaying new input.
207
208wxTerminal.wxg_
209 A wxGlade design file for the terminal application.
210
211wxSerialConfigDialog.py_
212 A flexible serial port configuration dialog.
213
214wxSerialConfigDialog.wxg_
215 The wxGlade design file for the configuration dialog.
216
217setup_demo.py_
218 A py2exe setup script to package the terminal application.
219
220.. _wxTerminal.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/wxTerminal.py
221.. _wxTerminal.wxg: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/wxTerminal.wxg
222.. _wxSerialConfigDialog.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/wxSerialConfigDialog.py
223.. _wxSerialConfigDialog.wxg: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/wxSerialConfigDialog.wxg
224.. _setup_demo.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/setup_demo.py
225
226
227Wrapper class
228=============
229This example provides a subclass based on ``Serial`` that has an alternative
230implementation of ``readline()``
231
232enhancedserial.py_
233 A class with alternative ``readline()`` implementation.
234
235.. _enhancedserial.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/enhancedserial.py
236
237
238Finding serial ports
239====================
240scan.py_
241 A simple loop that probes serial ports by number.
242
cliechti6d1e9d12009-07-22 01:06:29 +0000243scanlinux.py_
244 A Linux only version looking at the entries in ``/dev``. It works best with
245 on systems with devfs or udev that only create those entries that represent
246 devices. On older installations a lot of pre-created device files are found
247 and an additional open check should be added to ensure that the device is
248 real.
249
cliechti86e87872009-07-21 13:32:45 +0000250scanwin32.py_
251 A Windows only version that returns a list of serial ports with information
252 from the registry.
253
254.. _scan.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/scan.py
cliechti6d1e9d12009-07-22 01:06:29 +0000255.. _scanlinux.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/scanlinux.py
cliechti86e87872009-07-21 13:32:45 +0000256.. _scanwin32.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/scanwin32.py
257
258
259Unit tests
260==========
261The project uses a number of unit test to verify the functionality. They all
262need a loop back connector. The scripts itself contain more information.
263
264test.py_
265 Basic tests.
266
cliechti86e87872009-07-21 13:32:45 +0000267test_advanced.py_
268 Test more advanced features.
269
cliechtibb5c3c52009-07-23 02:29:27 +0000270test_high_load.py_
271 Tests involving sending a lot of data.
272
cliechti86e87872009-07-21 13:32:45 +0000273.. _test.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/test.py
cliechti86e87872009-07-21 13:32:45 +0000274.. _test_advanced.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/test_advanced.py
cliechtibb5c3c52009-07-23 02:29:27 +0000275.. _test_high_load.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/test_high_load.py