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 | |
| 154 | wxPython examples |
| 155 | ================= |
| 156 | A simple terminal application for wxPython and a flexible serial port |
| 157 | configuration dialog are shown here. |
| 158 | |
| 159 | wxTerminal.py_ |
| 160 | A simple terminal application. Note that the length of the buffer is |
| 161 | limited by wx and it may suddenly stop displaying new input. |
| 162 | |
| 163 | wxTerminal.wxg_ |
| 164 | A wxGlade design file for the terminal application. |
| 165 | |
| 166 | wxSerialConfigDialog.py_ |
| 167 | A flexible serial port configuration dialog. |
| 168 | |
| 169 | wxSerialConfigDialog.wxg_ |
| 170 | The wxGlade design file for the configuration dialog. |
| 171 | |
| 172 | setup_demo.py_ |
| 173 | A py2exe setup script to package the terminal application. |
| 174 | |
| 175 | .. _wxTerminal.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/wxTerminal.py |
| 176 | .. _wxTerminal.wxg: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/wxTerminal.wxg |
| 177 | .. _wxSerialConfigDialog.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/wxSerialConfigDialog.py |
| 178 | .. _wxSerialConfigDialog.wxg: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/wxSerialConfigDialog.wxg |
| 179 | .. _setup_demo.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/setup_demo.py |
| 180 | |
| 181 | |
| 182 | Wrapper class |
| 183 | ============= |
| 184 | This example provides a subclass based on ``Serial`` that has an alternative |
| 185 | implementation of ``readline()`` |
| 186 | |
| 187 | enhancedserial.py_ |
| 188 | A class with alternative ``readline()`` implementation. |
| 189 | |
| 190 | .. _enhancedserial.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/enhancedserial.py |
| 191 | |
| 192 | |
| 193 | Finding serial ports |
| 194 | ==================== |
| 195 | scan.py_ |
| 196 | A simple loop that probes serial ports by number. |
| 197 | |
cliechti | 6d1e9d1 | 2009-07-22 01:06:29 +0000 | [diff] [blame^] | 198 | scanlinux.py_ |
| 199 | A Linux only version looking at the entries in ``/dev``. It works best with |
| 200 | on systems with devfs or udev that only create those entries that represent |
| 201 | devices. On older installations a lot of pre-created device files are found |
| 202 | and an additional open check should be added to ensure that the device is |
| 203 | real. |
| 204 | |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 205 | scanwin32.py_ |
| 206 | A Windows only version that returns a list of serial ports with information |
| 207 | from the registry. |
| 208 | |
| 209 | .. _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^] | 210 | .. _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] | 211 | .. _scanwin32.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/scanwin32.py |
| 212 | |
| 213 | |
| 214 | Unit tests |
| 215 | ========== |
| 216 | The project uses a number of unit test to verify the functionality. They all |
| 217 | need a loop back connector. The scripts itself contain more information. |
| 218 | |
| 219 | test.py_ |
| 220 | Basic tests. |
| 221 | |
| 222 | test_high_load.py_ |
| 223 | Tests involving sending a lot of data. |
| 224 | |
| 225 | test_advanced.py_ |
| 226 | Test more advanced features. |
| 227 | |
| 228 | .. _test.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/test.py |
| 229 | .. _test_high_load.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/test_high_load.py |
| 230 | .. _test_advanced.py: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/examples/test_advanced.py |