cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 1 | ========== |
| 2 | Examples |
| 3 | ========== |
| 4 | |
| 5 | Miniterm |
| 6 | ======== |
| 7 | This is a console application that provides a small terminal application. |
| 8 | miniterm itself does not implement any terminal features such as VT102 |
| 9 | compatibility. However it inherits these features from the terminal it is run. |
| 10 | For example on GNU/Linux running from an xterm it will support the escape |
| 11 | sequences of the xterm. On Windows the typical console window is dumb and does |
| 12 | not support any escapes. When ANSI.sys is loaded it supports some escapes. |
| 13 | |
cliechti | 5134aab | 2009-07-21 19:47:59 +0000 | [diff] [blame] | 14 | miniterm:: |
| 15 | |
| 16 | --- Miniterm on /dev/ttyS0: 9600,8,N,1 --- |
| 17 | --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H --- |
| 18 | |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 19 | Command line options can be given so that binary data including escapes for |
| 20 | terminals are escaped or output as hex. |
| 21 | |
cliechti | 5134aab | 2009-07-21 19:47:59 +0000 | [diff] [blame] | 22 | Command 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 | |
| 56 | miniterm supports some control functions. Typing :kbd:`Control+t Control+h` when it is |
| 57 | running 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 | |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 81 | |
| 82 | miniterm.py_ |
| 83 | The miniterm program. |
| 84 | |
| 85 | setup-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 | |
| 93 | TCP/IP - serial bridge |
| 94 | ====================== |
| 95 | This program opens a TCP/IP port. When a connection is made to that port (e.g. |
| 96 | with telnet) it forwards all data to the serial port and vice versa. |
| 97 | |
| 98 | The serial port settings are set on the command line when starting the program. |
| 99 | There is no possibility to change settings from remote. |
cliechti | 5134aab | 2009-07-21 19:47:59 +0000 | [diff] [blame] | 100 | :: |
| 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 | |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 147 | |
| 148 | tcp_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 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 154 | Multi-port TCP/IP - serial bridge |
| 155 | ================================= |
| 156 | This example implements a TCP/IP to serial port service that works with |
| 157 | multiple ports at once. It uses select, no threads, and runs on POSIX systems |
| 158 | only. |
| 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 | |
| 172 | Requirements |
| 173 | ------------ |
| 174 | - python (>2.4) |
| 175 | - python-avahi |
| 176 | - python-dbus |
| 177 | - python-serial |
| 178 | |
| 179 | |
| 180 | Installation |
| 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 | |
| 189 | port_publisher.py_ |
| 190 | Multi-port TCP/IP-serial converter for POSIX environments. |
| 191 | |
| 192 | port_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 | |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 199 | wxPython examples |
| 200 | ================= |
| 201 | A simple terminal application for wxPython and a flexible serial port |
| 202 | configuration dialog are shown here. |
| 203 | |
| 204 | wxTerminal.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 | |
| 208 | wxTerminal.wxg_ |
cliechti | daf47ba | 2009-07-28 01:28:16 +0000 | [diff] [blame^] | 209 | test_high_load.py_ |
| 210 | Tests involving sending a lot of data. |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 211 | A wxGlade design file for the terminal application. |
| 212 | |
| 213 | wxSerialConfigDialog.py_ |
| 214 | A flexible serial port configuration dialog. |
| 215 | |
| 216 | wxSerialConfigDialog.wxg_ |
| 217 | The wxGlade design file for the configuration dialog. |
| 218 | |
| 219 | setup_demo.py_ |
| 220 | A py2exe setup script to package the terminal application. |
| 221 | |
| 222 | .. _wxTerminal.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/wxTerminal.py |
| 223 | .. _wxTerminal.wxg: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/wxTerminal.wxg |
| 224 | .. _wxSerialConfigDialog.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/wxSerialConfigDialog.py |
| 225 | .. _wxSerialConfigDialog.wxg: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/wxSerialConfigDialog.wxg |
| 226 | .. _setup_demo.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/setup_demo.py |
| 227 | |
| 228 | |
| 229 | Wrapper class |
| 230 | ============= |
| 231 | This example provides a subclass based on ``Serial`` that has an alternative |
| 232 | implementation of ``readline()`` |
| 233 | |
| 234 | enhancedserial.py_ |
| 235 | A class with alternative ``readline()`` implementation. |
| 236 | |
| 237 | .. _enhancedserial.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/enhancedserial.py |
| 238 | |
| 239 | |
| 240 | Finding serial ports |
| 241 | ==================== |
| 242 | scan.py_ |
| 243 | A simple loop that probes serial ports by number. |
| 244 | |
cliechti | 6d1e9d1 | 2009-07-22 01:06:29 +0000 | [diff] [blame] | 245 | scanlinux.py_ |
| 246 | A Linux only version looking at the entries in ``/dev``. It works best with |
| 247 | on systems with devfs or udev that only create those entries that represent |
| 248 | devices. On older installations a lot of pre-created device files are found |
| 249 | and an additional open check should be added to ensure that the device is |
| 250 | real. |
| 251 | |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 252 | scanwin32.py_ |
| 253 | A Windows only version that returns a list of serial ports with information |
| 254 | from the registry. |
| 255 | |
| 256 | .. _scan.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/scan.py |
cliechti | 6d1e9d1 | 2009-07-22 01:06:29 +0000 | [diff] [blame] | 257 | .. _scanlinux.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/scanlinux.py |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 258 | .. _scanwin32.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/scanwin32.py |
| 259 | |
| 260 | |
| 261 | Unit tests |
| 262 | ========== |
| 263 | The project uses a number of unit test to verify the functionality. They all |
| 264 | need a loop back connector. The scripts itself contain more information. |
| 265 | |
| 266 | test.py_ |
| 267 | Basic tests. |
| 268 | |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 269 | test_advanced.py_ |
| 270 | Test more advanced features. |
| 271 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 272 | test_high_load.py_ |
| 273 | Tests involving sending a lot of data. |
| 274 | |
cliechti | daf47ba | 2009-07-28 01:28:16 +0000 | [diff] [blame^] | 275 | test_iolib.py_ |
| 276 | Tests involving the :mod:`io` library. Only available for Python 2.6 and |
| 277 | newer. |
| 278 | |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 279 | .. _test.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/test.py |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 280 | .. _test_advanced.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/test_advanced.py |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 281 | .. _test_high_load.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/test_high_load.py |
cliechti | daf47ba | 2009-07-28 01:28:16 +0000 | [diff] [blame^] | 282 | .. _test_iolib.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/test_iolib.py |