cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 1 | ============== |
| 2 | pySerial API |
| 3 | ============== |
| 4 | |
| 5 | .. module:: serial |
| 6 | |
| 7 | Classes |
| 8 | ======= |
| 9 | |
cliechti | 7aed833 | 2009-08-05 14:19:31 +0000 | [diff] [blame] | 10 | Native ports |
| 11 | ------------ |
| 12 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 13 | .. class:: Serial |
| 14 | |
| 15 | .. method:: __init__(port=None, baudrate=9600, bytesize=EIGHTBITS, parity=PARITY_NONE, stopbits=STOPBITS_ONE, timeout=None, xonxoff=0, rtscts=0, interCharTimeout=None) |
| 16 | |
| 17 | :param port: |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 18 | Device name or port number number or :const:`None`. |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 19 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 20 | :param baudrate: |
| 21 | Baud rate such as 9600 or 115200 etc. |
| 22 | |
| 23 | :param bytesize: |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 24 | Number of data bits. Possible values: |
| 25 | :const:`FIVEBITS`, :const:`SIXBITS`, :const:`SEVENBITS`, |
| 26 | :const:`EIGHTBITS` |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 27 | |
| 28 | :param parity: |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 29 | Enable parity checking. Possible values: |
cliechti | 8768624 | 2009-08-18 00:58:31 +0000 | [diff] [blame^] | 30 | :const:`PARITY_NONE`, :const:`PARITY_EVEN`, :const:`PARITY_ODD` |
| 31 | :const:`PARITY_MARK`, :const:`PARITY_SPACE` |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 32 | |
| 33 | :param stopbits: |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 34 | Number of stop bits. Possible values: |
cliechti | 8768624 | 2009-08-18 00:58:31 +0000 | [diff] [blame^] | 35 | :const:`STOPBITS_ONE`, :const:`STOPBITS_ONE_POINT_FIVE`, |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 36 | :const:`STOPBITS_TWO` |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 37 | |
| 38 | :param timeout: |
| 39 | Set a read timeout value. |
| 40 | |
| 41 | :param xonxoff: |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 42 | Enable software flow control. |
| 43 | |
| 44 | :param rtscts: |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 45 | Enable hardware (RTS/CTS) flow control. |
| 46 | |
| 47 | :param interCharTimeout: |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 48 | Inter-character timeout, :const:`None` to disable (default). |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 49 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 50 | :exception ValueError: |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 51 | Will be raised when parameter are out of range, e.g. baud rate, data bits. |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 52 | |
| 53 | :exception SerialException: |
| 54 | In case the device can not be found or can not be configured. |
| 55 | |
| 56 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 57 | The port is immediately opened on object creation, when a *port* is |
| 58 | given. It is not opened when *port* is :const:`None` and a successive call |
| 59 | to :meth:`open` will be needed. |
| 60 | |
| 61 | Possible values for the parameter *port*: |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 62 | |
cliechti | 5134aab | 2009-07-21 19:47:59 +0000 | [diff] [blame] | 63 | - Number: number of device, numbering starts at zero. |
| 64 | - Device name: depending on operating system. e.g. ``/dev/ttyUSB0`` |
| 65 | on GNU/Linux or ``COM3`` on Windows. |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 66 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 67 | Possible values for the parameter *timeout*: |
cliechti | 5134aab | 2009-07-21 19:47:59 +0000 | [diff] [blame] | 68 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 69 | - ``timeout = None``: wait forever |
| 70 | - ``timeout = 0``: non-blocking mode (return immediately on read) |
cliechti | f81362e | 2009-07-25 03:44:33 +0000 | [diff] [blame] | 71 | - ``timeout = x``: set timeout to ``x`` seconds (float allowed) |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 72 | |
cliechti | 8611bf4 | 2009-08-03 00:34:03 +0000 | [diff] [blame] | 73 | Note that enabling both flow control methods (*xonxoff* and *rtscts*) |
| 74 | together may not be supported. It is common to use one of the methods |
| 75 | at once, not both. |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 76 | |
| 77 | .. method:: open() |
| 78 | |
| 79 | Open port. |
| 80 | |
| 81 | .. method:: close() |
| 82 | |
| 83 | Close port immediately. |
| 84 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 85 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 86 | The following methods may raise :exc:`ValueError` when applied to a closed |
| 87 | port. |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 88 | |
| 89 | .. method:: read(size=1) |
| 90 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 91 | :param size: Number of bytes to read. |
| 92 | :return: Bytes read from the port. |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 93 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 94 | Read *size* bytes from the serial port. If a timeout is set it may |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 95 | return less characters as requested. With no timeout it will block |
| 96 | until the requested number of bytes is read. |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 97 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 98 | .. versionchanged:: 2.5 |
| 99 | Returns an instance of :class:`bytes` when available (Python 2.6 |
cliechti | 8611bf4 | 2009-08-03 00:34:03 +0000 | [diff] [blame] | 100 | and newer) and :class:`str` otherwise. |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 101 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 102 | .. method:: write(data) |
| 103 | |
| 104 | :param data: Data to send. |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 105 | :return: Number of bytes written. |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 106 | :exception SerialTimeoutException: |
| 107 | In case a write timeout is configured for the port and the time is |
| 108 | exceeded. |
| 109 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 110 | Write the string *data* to the port. |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 111 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 112 | .. versionchanged:: 2.5 |
cliechti | ddd7813 | 2009-07-28 01:13:28 +0000 | [diff] [blame] | 113 | Accepts instances of :class:`bytes` and :class:`bytearray` when |
cliechti | 8611bf4 | 2009-08-03 00:34:03 +0000 | [diff] [blame] | 114 | available (Python 2.6 and newer) and :class:`str` otherwise. |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 115 | |
| 116 | .. method:: inWaiting() |
| 117 | |
| 118 | Return the number of chars in the receive buffer. |
| 119 | |
| 120 | .. method:: flush() |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 121 | |
| 122 | Flush of file like objects. In this case, wait until all data is |
| 123 | written. |
| 124 | |
| 125 | .. method:: flushInput() |
| 126 | |
| 127 | Flush input buffer, discarding all it's contents. |
| 128 | |
| 129 | .. method:: flushOutput() |
| 130 | |
| 131 | Clear output buffer, aborting the current output and |
| 132 | discarding all that is in the buffer. |
| 133 | |
| 134 | .. method:: sendBreak(duration=0.25) |
| 135 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 136 | :param duration: Time (float) to activate the BREAK condition. |
| 137 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 138 | Send break condition. Timed, returns to idle state after given |
| 139 | duration. |
| 140 | |
| 141 | .. method:: setBreak(level=True) |
| 142 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 143 | :param level: when true activate BREAK condition, else disable. |
| 144 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 145 | Set break: Controls TXD. When active, no transmitting is possible. |
| 146 | |
| 147 | .. method:: setRTS(level=True) |
| 148 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 149 | :param level: Set control line to logic level. |
| 150 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 151 | Set RTS line to specified logic level. |
| 152 | |
| 153 | .. method:: setDTR(level=True) |
| 154 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 155 | :param level: Set control line to logic level. |
| 156 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 157 | Set DTR line to specified logic level. |
| 158 | |
| 159 | .. method:: getCTS() |
| 160 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 161 | :return: Current state (boolean) |
| 162 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 163 | Return the state of the CTS line. |
| 164 | |
| 165 | .. method:: getDSR() |
| 166 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 167 | :return: Current state (boolean) |
| 168 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 169 | Return the state of the DSR line. |
| 170 | |
| 171 | .. method:: getRI() |
| 172 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 173 | :return: Current state (boolean) |
| 174 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 175 | Return the state of the RI line. |
| 176 | |
| 177 | .. method:: getCD() |
| 178 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 179 | :return: Current state (boolean) |
| 180 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 181 | Return the state of the CD line |
| 182 | |
| 183 | Read-only attributes: |
| 184 | |
cliechti | f81362e | 2009-07-25 03:44:33 +0000 | [diff] [blame] | 185 | .. attribute:: name |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 186 | |
cliechti | 5134aab | 2009-07-21 19:47:59 +0000 | [diff] [blame] | 187 | Device name. This is always the device name even if the |
| 188 | port was opened by a number. (Read Only). |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 189 | |
cliechti | f81362e | 2009-07-25 03:44:33 +0000 | [diff] [blame] | 190 | .. versionadded:: 2.5 |
| 191 | |
| 192 | .. attribute:: portstr |
| 193 | |
| 194 | :deprecated: use :attr:`name` instead |
| 195 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 196 | .. attribute:: BAUDRATES |
| 197 | |
| 198 | A list of valid baud rates. The list may be incomplete such that higher |
| 199 | baud rates may be supported by the device and that values in between the |
| 200 | standard baud rates are supported. (Read Only). |
| 201 | |
| 202 | .. attribute:: BYTESIZES |
| 203 | |
| 204 | A list of valid byte sizes for the device (Read Only). |
| 205 | |
| 206 | .. attribute:: PARITIES |
| 207 | |
| 208 | A list of valid parities for the device (Read Only). |
| 209 | |
| 210 | .. attribute:: STOPBITS |
| 211 | |
| 212 | A list of valid stop bit widths for the device (Read Only). |
| 213 | |
| 214 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 215 | New values can be assigned to the following attributes, the port will be |
| 216 | reconfigured, even if it's opened at that time: |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 217 | |
| 218 | .. attribute:: port |
| 219 | |
| 220 | Port name/number as set by the user. |
| 221 | |
| 222 | .. attribute:: baudrate |
| 223 | |
| 224 | Current baud rate setting. |
| 225 | |
| 226 | .. attribute:: bytesize |
| 227 | |
| 228 | Byte size in bits. |
| 229 | |
| 230 | .. attribute:: parity |
| 231 | |
| 232 | Parity setting. |
| 233 | |
| 234 | .. attribute:: stopbits |
| 235 | |
| 236 | Stop bit with. |
| 237 | |
| 238 | .. attribute:: timeout |
| 239 | |
cliechti | 5134aab | 2009-07-21 19:47:59 +0000 | [diff] [blame] | 240 | Timeout setting (seconds, float). |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 241 | |
| 242 | .. attribute:: xonxoff |
| 243 | |
| 244 | If Xon/Xoff flow control is enabled. |
| 245 | |
| 246 | .. attribute:: rtscts |
| 247 | |
| 248 | If hardware flow control is enabled. |
| 249 | |
| 250 | Platform specific methods. |
| 251 | |
| 252 | .. warning:: Programs using the following methods are not portable to other platforms! |
| 253 | |
| 254 | .. method:: nonblocking() |
| 255 | |
| 256 | :platform: Unix |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 257 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 258 | Configure the device for nonblocking operations. This can be useful if |
| 259 | the port is used with ``select``. |
| 260 | |
| 261 | .. method:: fileno() |
| 262 | |
| 263 | :platform: Unix |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 264 | :return: File descriptor. |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 265 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 266 | Return file descriptor number for the port that is opened by this object. |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 267 | |
| 268 | .. method:: setXON(level=True) |
| 269 | |
| 270 | :platform: Windows |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 271 | :param level: Set flow control state. |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 272 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 273 | Set software flow control state. |
| 274 | |
| 275 | |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 276 | .. class:: SerialBase |
| 277 | |
| 278 | The following attributes are implemented as properties. They work with open |
| 279 | and closed ports. |
| 280 | |
| 281 | .. attribute:: port |
| 282 | |
| 283 | Read or write port. When the port is already open, it will be closed |
| 284 | and reopened with the new setting. |
| 285 | |
| 286 | .. attribute:: baudrate |
| 287 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 288 | Read or write current baud rate setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 289 | |
| 290 | .. attribute:: bytesize |
| 291 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 292 | Read or write current data byte size setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 293 | |
| 294 | .. attribute:: parity |
| 295 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 296 | Read or write current parity setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 297 | |
| 298 | .. attribute:: stopbits |
| 299 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 300 | Read or write current stop bit width setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 301 | |
| 302 | .. attribute:: timeout |
| 303 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 304 | Read or write current read timeout setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 305 | |
| 306 | .. attribute:: writeTimeout |
| 307 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 308 | Read or write current write timeout setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 309 | |
| 310 | .. attribute:: xonxoff |
| 311 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 312 | Read or write current software flow control rate setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 313 | |
| 314 | .. attribute:: rtscts |
| 315 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 316 | Read or write current hardware flow control setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 317 | |
| 318 | .. attribute:: dsrdtr |
| 319 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 320 | Read or write current hardware flow control setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 321 | |
| 322 | .. attribute:: interCharTimeout |
| 323 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 324 | Read or write current inter character timeout setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 325 | |
| 326 | The following constants are also provided: |
| 327 | |
| 328 | .. attribute:: BAUDRATES |
| 329 | |
| 330 | A tuple of standard baud rate values. The actual device may support more |
| 331 | or less... |
| 332 | |
| 333 | .. attribute:: BYTESIZES |
| 334 | |
| 335 | A tuple of supported byte size values. |
| 336 | |
| 337 | .. attribute:: PARITIES |
| 338 | |
| 339 | A tuple of supported parity settings. |
| 340 | |
| 341 | .. attribute:: STOPBITS |
| 342 | |
| 343 | A tuple of supported stop bit settings. |
| 344 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 345 | .. method:: readline(size=None, eol='\\n') |
| 346 | |
| 347 | :param size: Max number of bytes to read, ``None`` -> no limit. |
| 348 | :param eol: The end of line character. |
| 349 | |
| 350 | Read a line which is terminated with end-of-line (*eol*) character |
| 351 | (``\\n`` by default) or until timeout. |
| 352 | |
| 353 | .. method:: readlines(sizehint=None, eol='\\n') |
| 354 | |
| 355 | :param size: Ignored parameter. |
| 356 | :param eol: The end of line character. |
| 357 | |
| 358 | Read a list of lines, until timeout. *sizehint* is ignored and only |
| 359 | present for API compatibility with built-in File objects. |
| 360 | |
| 361 | .. method:: xreadlines(sizehint=None) |
| 362 | |
| 363 | Just calls :meth:`readlines` - here for compatibility. |
| 364 | |
| 365 | For compatibility with the :mod:`io` library are the following methods. |
| 366 | |
| 367 | .. method:: readable() |
| 368 | |
| 369 | :return: True |
cliechti | f456634 | 2009-08-04 00:07:19 +0000 | [diff] [blame] | 370 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 371 | .. versionadded:: 2.5 |
| 372 | |
| 373 | .. method:: writable() |
| 374 | |
| 375 | :return: True |
cliechti | f456634 | 2009-08-04 00:07:19 +0000 | [diff] [blame] | 376 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 377 | .. versionadded:: 2.5 |
| 378 | |
| 379 | .. method:: seekable() |
| 380 | |
| 381 | :return: False |
cliechti | f456634 | 2009-08-04 00:07:19 +0000 | [diff] [blame] | 382 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 383 | .. versionadded:: 2.5 |
| 384 | |
| 385 | .. method:: readinto(b) |
| 386 | |
cliechti | 8611bf4 | 2009-08-03 00:34:03 +0000 | [diff] [blame] | 387 | :param b: bytearray or array instance |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 388 | :return: Number of byte read |
| 389 | |
cliechti | d7e7ce2 | 2009-08-03 02:01:07 +0000 | [diff] [blame] | 390 | Read up to len(b) bytes into :class:`bytearray` *b* and return the |
| 391 | number of bytes read. |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 392 | |
| 393 | .. versionadded:: 2.5 |
| 394 | |
cliechti | 7053b23 | 2009-08-10 01:37:34 +0000 | [diff] [blame] | 395 | .. method:: getSettingsDict() |
cliechti | 4065dce | 2009-08-10 00:55:46 +0000 | [diff] [blame] | 396 | |
| 397 | :return: a dictionary with current port settings. |
| 398 | |
| 399 | Get a dictionary with port settings. This is useful to backup the |
| 400 | current settings so that a later point in time they can be restored |
| 401 | using :meth:`applySettingsDict`. |
| 402 | |
| 403 | Note that control lines (RTS/DTR) are part of the settings. |
| 404 | |
| 405 | .. versionadded:: 2.5 |
| 406 | |
cliechti | 7053b23 | 2009-08-10 01:37:34 +0000 | [diff] [blame] | 407 | .. method:: applySettingsDict(d) |
cliechti | 4065dce | 2009-08-10 00:55:46 +0000 | [diff] [blame] | 408 | |
| 409 | :param d: a dictionary with port settings. |
| 410 | |
| 411 | Applies a dictionary that was created by :meth:`getSettingsDict`. Only |
| 412 | changes are applied and when a key is missing it means that the setting |
| 413 | stays unchanged. |
| 414 | |
| 415 | Note that control lines (RTS/DTR) are not changed. |
| 416 | |
| 417 | .. versionadded:: 2.5 |
| 418 | |
cliechti | f456634 | 2009-08-04 00:07:19 +0000 | [diff] [blame] | 419 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 420 | .. note:: |
| 421 | |
| 422 | For systems that provide the :mod:`io` library (Python 2.6 and newer), the |
cliechti | d7e7ce2 | 2009-08-03 02:01:07 +0000 | [diff] [blame] | 423 | class :class:`Serial` will derive from :class:`io.RawIOBase`. For all |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 424 | others from :class:`FileLike`. |
| 425 | |
| 426 | .. class:: FileLike |
| 427 | |
| 428 | An abstract file like class. It is used as base class for :class:`Serial`. |
| 429 | |
| 430 | This class implements :meth:`readline` and :meth:`readlines` based on read |
| 431 | and :meth:`writelines` based on write. This class is used to provide the |
| 432 | above functions for to Serial port objects. |
| 433 | |
| 434 | Note that when the serial port was opened with no timeout that |
| 435 | :meth:`readline` blocks until it sees a newline (or the specified size is |
| 436 | reached) and that :meth:`readlines` would never return and therefore |
| 437 | refuses to work (it raises an exception in this case)! |
| 438 | |
| 439 | .. method:: writelines(sequence) |
| 440 | |
| 441 | Write a list of strings to the port. |
| 442 | |
| 443 | |
| 444 | The following three methods are overridden in :class:`Serial`. |
| 445 | |
| 446 | .. method:: flush() |
| 447 | |
| 448 | Flush of file like objects. It's a no-op in this class, may be overridden. |
| 449 | |
| 450 | .. method:: read() |
| 451 | |
| 452 | Raises NotImplementedError, needs to be overridden by subclass. |
| 453 | |
| 454 | .. method:: write(data) |
| 455 | |
| 456 | Raises NotImplementedError, needs to be overridden by subclass. |
| 457 | |
| 458 | The following functions are implemented for compatibility with other |
| 459 | file-like objects, however serial ports are not seekable. |
| 460 | |
| 461 | |
| 462 | .. method:: seek(pos, whence=0) |
| 463 | |
| 464 | :exception IOError: always, as method is not supported on serial port |
| 465 | |
| 466 | .. versionadded:: 2.5 |
| 467 | |
| 468 | .. method:: tell() |
| 469 | |
| 470 | :exception IOError: always, as method is not supported on serial port |
| 471 | |
| 472 | .. versionadded:: 2.5 |
| 473 | |
| 474 | .. method:: truncate(self, n=None) |
| 475 | |
| 476 | :exception IOError: always, as method is not supported on serial port |
| 477 | |
| 478 | .. versionadded:: 2.5 |
| 479 | |
| 480 | .. method:: isatty() |
| 481 | |
| 482 | :exception IOError: always, as method is not supported on serial port |
| 483 | |
| 484 | .. versionadded:: 2.5 |
| 485 | |
| 486 | To be able to use the file like object as iterator for e.g. |
| 487 | ``for line in Serial(0): ...`` usage: |
| 488 | |
| 489 | .. method:: next() |
| 490 | |
| 491 | Return the next line by calling :meth:`readline`. |
| 492 | |
| 493 | .. method:: __iter__() |
| 494 | |
| 495 | Returns self. |
| 496 | |
cliechti | 7aed833 | 2009-08-05 14:19:31 +0000 | [diff] [blame] | 497 | :rfc:`2217` Network ports |
| 498 | ------------------------- |
| 499 | |
| 500 | .. warning:: This implementation is currently in an experimental state. Use |
| 501 | at your own risk. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 502 | |
cliechti | ec4ac1b | 2009-08-02 00:47:21 +0000 | [diff] [blame] | 503 | .. class:: rfc2217.Serial |
| 504 | |
cliechti | f456634 | 2009-08-04 00:07:19 +0000 | [diff] [blame] | 505 | This implements a :rfc:`2217` compatible client. Port names are URLs_ in the |
| 506 | form: ``rfc2217://<host>:<port>[/<option>[/<option>]]`` |
cliechti | ec4ac1b | 2009-08-02 00:47:21 +0000 | [diff] [blame] | 507 | |
cliechti | ec4ac1b | 2009-08-02 00:47:21 +0000 | [diff] [blame] | 508 | This class API is compatible to :class:`Serial` with a few exceptions: |
| 509 | |
| 510 | - numbers as port name are not allowed, only URLs in the form described |
| 511 | above. |
| 512 | - writeTimeout is not implemented |
| 513 | - The current implementation starts a thread that keeps reading from the |
| 514 | (internal) socket. The thread is managed automatically by the |
| 515 | :class:`rfc2217.Serial` port object on :meth:`open`/:meth:`close`. |
| 516 | However it may be a problem for user applications that like to use select |
| 517 | instead of threads. |
| 518 | |
| 519 | Due to the nature of the network and protocol involved there are a few |
| 520 | extra points to keep in mind: |
| 521 | |
| 522 | - All operations have an additional latency time. |
| 523 | - Setting control lines (RTS/CTS) needs more time. |
| 524 | - Reading the status lines (DSR/DTR etc.) returns a cached value. When that |
| 525 | cache is updated depends entirely on the server. The server itself may |
| 526 | implement a polling at a certain rate and quick changes may be invisible. |
| 527 | - The network layer also has buffers. This means that :meth:`flush`, |
| 528 | :meth:`flushInput` and :meth:`flushOutput` may work with additional delay. |
| 529 | Likewise :meth:`inWaiting` returns the size of the data arrived at the |
| 530 | object internal buffer and excludes any bytes in the network buffers or |
| 531 | any server side buffer. |
| 532 | - Closing and immediately reopening the same port may fail due to time |
| 533 | needed by the server to get ready again. |
| 534 | |
| 535 | Not implemented yet / Possible problems with the implementation: |
| 536 | |
cliechti | 8611bf4 | 2009-08-03 00:34:03 +0000 | [diff] [blame] | 537 | - :rfc:`2217` flow control between client and server (objects internal |
| 538 | buffer may eat all your memory when never read). |
cliechti | d7e7ce2 | 2009-08-03 02:01:07 +0000 | [diff] [blame] | 539 | - No authentication support (servers may not prompt for a password etc.) |
| 540 | - No encryption. |
| 541 | |
| 542 | Due to lack of authentication and encryption it is not suitable to use this |
| 543 | client for connections across the internet and should only be used in |
| 544 | controlled environments. |
cliechti | ec4ac1b | 2009-08-02 00:47:21 +0000 | [diff] [blame] | 545 | |
cliechti | 7c640ed | 2009-08-02 00:54:51 +0000 | [diff] [blame] | 546 | .. versionadded:: 2.5 |
cliechti | ec4ac1b | 2009-08-02 00:47:21 +0000 | [diff] [blame] | 547 | |
cliechti | 7aed833 | 2009-08-05 14:19:31 +0000 | [diff] [blame] | 548 | |
| 549 | .. class:: rfc2217.PortManager |
| 550 | |
| 551 | This class provides helper functions for implementing :rfc:`2217` |
| 552 | compatible servers. |
| 553 | |
| 554 | Basically, it implements every thing needed for the :rfc:`2217` protocol. |
| 555 | It just does not open sockets and read/write to serial ports (though it |
| 556 | changes other port settings). The user of this class must take care of the |
| 557 | data transmission itself. The reason for that is, that this way, this class |
| 558 | supports all programming models such as threads and select. |
| 559 | |
| 560 | Usage examples can be found in the examples where two TCP/IP - serial |
| 561 | converters are shown, one using threads (the single port server) and an |
| 562 | other using select (the multi port server). |
| 563 | |
| 564 | .. note:: Each new client connection must create a new instance as this |
| 565 | object (and the :rfc:`2217` protocol) has internal state. |
| 566 | |
| 567 | .. method:: __init__(serial_port, connection, debug_output=False) |
| 568 | |
| 569 | :param serial_port: a :class:`Serial` instance that is managed. |
| 570 | :param connection: an object implementing :meth:`write`, used to write |
| 571 | to the network. |
cliechti | 86844e8 | 2009-08-12 00:05:33 +0000 | [diff] [blame] | 572 | :param debug_output: enables debug messages: a :class:`logging.Logger` |
| 573 | instance or None. |
cliechti | 7aed833 | 2009-08-05 14:19:31 +0000 | [diff] [blame] | 574 | |
| 575 | Initializes the Manager and starts negotiating with client in Telnet |
| 576 | and :rfc:`2217` protocol. The negotiation starts immediately so that |
| 577 | the class should be instantiated in the moment the client connects. |
| 578 | |
| 579 | The *serial_port* can be controlled by :rfc:`2217` commands. This |
| 580 | object will modify the port settings (baud rate etc) and control lines |
| 581 | (RTS/DTR) send BREAK etc. when the corresponding commands are found by |
| 582 | the :meth:`filter` method. |
| 583 | |
| 584 | The *connection* object must implement a :meth:`write(data)` function. |
| 585 | This function must ensure that *data* is written at once (no user data |
| 586 | mixed in, i.e. it must be thread-safe). All data must be sent in its |
| 587 | raw form (:meth:`escape` must not be used) as it is used to send Telnet |
| 588 | and :rfc:`2217` control commands. |
| 589 | |
cliechti | 86844e8 | 2009-08-12 00:05:33 +0000 | [diff] [blame] | 590 | For diagnostics of the connection or the implementation, *debug_output* |
| 591 | can be set to an instance of a :class:`logging.Logger` (e.g. |
| 592 | ``logging.getLogger('rfc2217.server')``). The caller should configure |
| 593 | the logger using ``setLevel`` for the desired detail level of the logs. |
| 594 | |
cliechti | 7aed833 | 2009-08-05 14:19:31 +0000 | [diff] [blame] | 595 | .. method:: escape(data) |
| 596 | |
| 597 | :param data: data to be sent over the network. |
| 598 | :return: data, escaped for Telnet/:rfc:`2217` |
| 599 | |
| 600 | A generator that escapes all data to be compatible with :rfc:`2217`. |
| 601 | Implementors of servers should use this function to process all data |
| 602 | sent over the network. |
| 603 | |
| 604 | The function returns a generator which can be used in ``for`` loops. |
| 605 | It can be converted to bytes using ``serial.to_bytes``. |
| 606 | |
| 607 | .. method:: filter(data) |
| 608 | |
| 609 | :param data: data read from the network, including Telnet and |
| 610 | :rfc:`2217` controls. |
| 611 | :return: data, free from Telnet and :rfc:`2217` controls. |
| 612 | |
| 613 | A generator that filters and processes all data related to :rfc:`2217`. |
| 614 | Implementors of servers should use this function to process all data |
| 615 | received from the network. |
| 616 | |
| 617 | The function returns a generator which can be used in ``for`` loops. |
| 618 | It can be converted to bytes using ``serial.to_bytes``. |
| 619 | |
cliechti | 7cb78e8 | 2009-08-05 15:47:57 +0000 | [diff] [blame] | 620 | .. method:: check_modem_lines(force_notification=False) |
| 621 | |
| 622 | :param force_notification: Set to false. Parameter is for internal use. |
cliechti | 7aed833 | 2009-08-05 14:19:31 +0000 | [diff] [blame] | 623 | |
| 624 | This function needs to be called periodically (e.g. every second) when |
| 625 | the server wants to send NOTIFY_MODEMSTATE messages. This is required |
| 626 | to support the client for reading CTS/DSR/RI/CD status lines. |
| 627 | |
| 628 | The function reads the status line and issues the notifications |
| 629 | automatically. |
| 630 | |
| 631 | .. versionadded:: 2.5 |
| 632 | |
cliechti | ec4ac1b | 2009-08-02 00:47:21 +0000 | [diff] [blame] | 633 | .. seealso:: |
| 634 | |
| 635 | :rfc:`2217` - Telnet Com Port Control Option |
| 636 | |
| 637 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 638 | Exceptions |
| 639 | ========== |
| 640 | |
| 641 | .. exception:: SerialException |
| 642 | |
| 643 | Base class for serial port exceptions. |
| 644 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 645 | .. versionchanged:: 2.5 |
| 646 | Now derrives from :exc:`IOError` instead of :exc:`Exception` |
| 647 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 648 | .. exception:: SerialTimeoutException |
| 649 | |
| 650 | Exception that is raised on write timeouts. |
| 651 | |
| 652 | |
| 653 | Constants |
| 654 | ========= |
| 655 | |
cliechti | 8768624 | 2009-08-18 00:58:31 +0000 | [diff] [blame^] | 656 | *Parity* |
| 657 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 658 | .. data:: PARITY_NONE |
| 659 | .. data:: PARITY_EVEN |
| 660 | .. data:: PARITY_ODD |
| 661 | .. data:: PARITY_MARK |
| 662 | .. data:: PARITY_SPACE |
| 663 | |
cliechti | 8768624 | 2009-08-18 00:58:31 +0000 | [diff] [blame^] | 664 | *Stop bits* |
| 665 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 666 | .. data:: STOPBITS_ONE |
| 667 | .. data:: STOPBITS_ONE_POINT_FIVE |
| 668 | .. data:: STOPBITS_TWO |
| 669 | |
cliechti | 8768624 | 2009-08-18 00:58:31 +0000 | [diff] [blame^] | 670 | *Byte size* |
| 671 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 672 | .. data:: FIVEBITS |
| 673 | .. data:: SIXBITS |
| 674 | .. data:: SEVENBITS |
| 675 | .. data:: EIGHTBITS |
cliechti | 5b7d16a | 2009-07-21 21:53:59 +0000 | [diff] [blame] | 676 | |
cliechti | 8768624 | 2009-08-18 00:58:31 +0000 | [diff] [blame^] | 677 | |
| 678 | *Others* |
| 679 | |
cliechti | 8611bf4 | 2009-08-03 00:34:03 +0000 | [diff] [blame] | 680 | Default control characters (instances of :class:`bytes` for Python 3.0+) for |
cliechti | daf47ba | 2009-07-28 01:28:16 +0000 | [diff] [blame] | 681 | software flow control: |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 682 | |
cliechti | 5b7d16a | 2009-07-21 21:53:59 +0000 | [diff] [blame] | 683 | .. data:: XON |
| 684 | .. data:: XOFF |
cliechti | f81362e | 2009-07-25 03:44:33 +0000 | [diff] [blame] | 685 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 686 | Module version: |
cliechti | f81362e | 2009-07-25 03:44:33 +0000 | [diff] [blame] | 687 | |
| 688 | .. data:: VERSION |
| 689 | |
| 690 | A string indicating the pySerial version, such as ``2.5``. |
| 691 | |
cliechti | 8768624 | 2009-08-18 00:58:31 +0000 | [diff] [blame^] | 692 | .. versionadded:: 2.3 |
| 693 | |
| 694 | Module functions |
| 695 | ================ |
cliechti | f81362e | 2009-07-25 03:44:33 +0000 | [diff] [blame] | 696 | |
| 697 | .. function:: device(number) |
| 698 | |
| 699 | :param number: Port number. |
| 700 | :return: String containing device name. |
| 701 | :deprecated: Use device names directly. |
| 702 | |
| 703 | Convert a port number to a platform dependent device name. Unfortunately |
| 704 | this does not work well for all platforms; e.g. some may miss USB-Serial |
| 705 | converters and enumerate only internal serial ports. |
| 706 | |
| 707 | The conversion may be made off-line, that is, there is no guarantee that |
| 708 | the returned device name really exists on the system. |
cliechti | 7c640ed | 2009-08-02 00:54:51 +0000 | [diff] [blame] | 709 | |
| 710 | |
cliechti | e3ab353 | 2009-08-05 12:40:38 +0000 | [diff] [blame] | 711 | .. function:: serial_for_url(url, \*args, \*\*kwargs) |
cliechti | 7c640ed | 2009-08-02 00:54:51 +0000 | [diff] [blame] | 712 | |
cliechti | 86844e8 | 2009-08-12 00:05:33 +0000 | [diff] [blame] | 713 | :param url: Device name, number or :ref:`URL <URLs>` |
cliechti | 7c640ed | 2009-08-02 00:54:51 +0000 | [diff] [blame] | 714 | :param do_not_open: When set to true, the serial port is not opened. |
| 715 | :return: an instance of :class:`Serial` or a compatible object. |
| 716 | |
| 717 | Get a native or a :rfc:`2217` implementation of the Serial class, depending |
cliechti | d7e7ce2 | 2009-08-03 02:01:07 +0000 | [diff] [blame] | 718 | on port/url. This factory function is useful when an application wants |
| 719 | to support both, local ports and remote ports. |
cliechti | 7c640ed | 2009-08-02 00:54:51 +0000 | [diff] [blame] | 720 | |
| 721 | When *url* matches the form ``rfc2217://<host>:<port>`` an instance of |
| 722 | :class:`rfc2217.Serial` is returned. In all other cases the native (system |
| 723 | dependant) :class:`Serial` instance is returned. |
| 724 | |
cliechti | d7e7ce2 | 2009-08-03 02:01:07 +0000 | [diff] [blame] | 725 | The port is not opened when a keyword parameter called *do_not_open* is |
| 726 | given and true, by default it is opened. |
cliechti | 7c640ed | 2009-08-02 00:54:51 +0000 | [diff] [blame] | 727 | |
| 728 | .. versionadded:: 2.5 |
cliechti | f456634 | 2009-08-04 00:07:19 +0000 | [diff] [blame] | 729 | |
cliechti | 8768624 | 2009-08-18 00:58:31 +0000 | [diff] [blame^] | 730 | |
cliechti | 86844e8 | 2009-08-12 00:05:33 +0000 | [diff] [blame] | 731 | .. _URLs: |
cliechti | f456634 | 2009-08-04 00:07:19 +0000 | [diff] [blame] | 732 | |
| 733 | URLs |
| 734 | ---- |
cliechti | e3ab353 | 2009-08-05 12:40:38 +0000 | [diff] [blame] | 735 | The class :class:`rfc2217.Serial` and the function :func:`serial_for_url` |
cliechti | ab90e07 | 2009-08-06 01:44:34 +0000 | [diff] [blame] | 736 | accept the following types URL: |
cliechti | f456634 | 2009-08-04 00:07:19 +0000 | [diff] [blame] | 737 | |
cliechti | ab90e07 | 2009-08-06 01:44:34 +0000 | [diff] [blame] | 738 | - ``rfc2217://<host>:<port>[/<option>[/<option>]]`` |
| 739 | - ``socket://<host>:<port>[/<option>[/<option>]]`` |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 740 | - ``loop://[<option>[/<option>]]`` |
cliechti | f456634 | 2009-08-04 00:07:19 +0000 | [diff] [blame] | 741 | |
cliechti | 8768624 | 2009-08-18 00:58:31 +0000 | [diff] [blame^] | 742 | Device names are also supported: |
| 743 | |
| 744 | - ``/dev/ttyUSB0`` (Linux) |
| 745 | - ``COM3`` (Windows) |
| 746 | |
cliechti | f456634 | 2009-08-04 00:07:19 +0000 | [diff] [blame] | 747 | (Future releases of pySerial might add more types). |
| 748 | |
cliechti | ab90e07 | 2009-08-06 01:44:34 +0000 | [diff] [blame] | 749 | ``rfc2217://`` |
| 750 | Used to connect to :rfc:`2217` compatible servers. All serial port |
| 751 | functions are supported. |
| 752 | |
| 753 | Supported options in the URL are: |
| 754 | |
| 755 | - ``ign_set_control`` does not wait for acknowledges to SET_CONTROL. This |
| 756 | option can be used for non compliant servers (i.e. when getting an |
| 757 | ``remote rejected value for option 'control'`` error when connecting). |
| 758 | |
| 759 | - ``poll_modem``: The client issues NOTIFY_MODEMSTATE requests when status |
| 760 | lines are read (CTS/DTR/RI/CD). Without this option it relies on the server |
| 761 | sending the notifications automatically (that's what the RFC suggests and |
| 762 | most servers do). Enable this option when :meth:`getCTS` does not work as |
| 763 | expected, i.e. for servers that do not send notifications. |
| 764 | |
cliechti | dfe2d27 | 2009-08-10 22:19:41 +0000 | [diff] [blame] | 765 | - ``timeout=<value>``: Change network timeout (default 3 seconds). This is |
| 766 | useful when the server takes a little more time to send its answers. The |
| 767 | timeout applies to the initial Telnet / :rfc:`2271` negotiation as well |
| 768 | as changing port settings or control line change commands. |
| 769 | |
cliechti | 86844e8 | 2009-08-12 00:05:33 +0000 | [diff] [blame] | 770 | - ``logging=[debug|info|warning|error]``: Prints diagnostic messages (not |
cliechti | c64ba69 | 2009-08-12 00:32:47 +0000 | [diff] [blame] | 771 | useful for end users). It uses the logging module and a logger called |
| 772 | ``pySerial.rfc2217`` so that the application can setup up logging |
| 773 | handlers etc. It will call :meth:`logging.basicConfig` which initializes |
| 774 | for output on ``sys.stderr`` (if no logging was set up already). |
cliechti | ab90e07 | 2009-08-06 01:44:34 +0000 | [diff] [blame] | 775 | |
| 776 | ``socket://`` |
| 777 | The purpose of this connection type is that applications using pySerial can |
| 778 | connect to TCP/IP to serial port converters that do not support :rfc:`2217`. |
| 779 | |
| 780 | Uses a TCP/IP socket. All serial port settings, control and status lines |
| 781 | are ignored. Only data is transmitted and received. |
| 782 | |
| 783 | Supported options in the URL are: |
| 784 | |
cliechti | c64ba69 | 2009-08-12 00:32:47 +0000 | [diff] [blame] | 785 | - ``logging=[debug|info|warning|error]``: Prints diagnostic messages (not |
| 786 | useful for end users). It uses the logging module and a logger called |
| 787 | ``pySerial.socket`` so that the application can setup up logging handlers |
| 788 | etc. It will call :meth:`logging.basicConfig` which initializes for |
| 789 | output on ``sys.stderr`` (if no logging was set up already). |
cliechti | ab90e07 | 2009-08-06 01:44:34 +0000 | [diff] [blame] | 790 | |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 791 | ``loop://`` |
| 792 | The least useful type. It simulates a loop back connection. |
| 793 | ``RX<->TX`` ``RTS<->CTS`` ``DTR<->DSR`` |
| 794 | |
| 795 | Supported options in the URL are: |
| 796 | |
cliechti | c64ba69 | 2009-08-12 00:32:47 +0000 | [diff] [blame] | 797 | - ``logging=[debug|info|warning|error]``: Prints diagnostic messages (not |
| 798 | useful for end users). It uses the logging module and a logger called |
| 799 | ``pySerial.loop`` so that the application can setup up logging handlers |
| 800 | etc. It will call :meth:`logging.basicConfig` which initializes for |
| 801 | output on ``sys.stderr`` (if no logging was set up already). |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 802 | |
| 803 | |
cliechti | dfe2d27 | 2009-08-10 22:19:41 +0000 | [diff] [blame] | 804 | Examples: |
cliechti | f456634 | 2009-08-04 00:07:19 +0000 | [diff] [blame] | 805 | |
cliechti | dfe2d27 | 2009-08-10 22:19:41 +0000 | [diff] [blame] | 806 | - ``rfc2217://localhost:7000`` |
| 807 | - ``rfc2217://localhost:7000/poll_modem`` |
| 808 | - ``rfc2217://localhost:7000/ign_set_control/timeout=5.5`` |
| 809 | - ``socket://localhost:7777`` |
cliechti | c64ba69 | 2009-08-12 00:32:47 +0000 | [diff] [blame] | 810 | - ``loop://logging=debug`` |