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 | |
| 10 | .. class:: Serial |
| 11 | |
| 12 | .. method:: __init__(port=None, baudrate=9600, bytesize=EIGHTBITS, parity=PARITY_NONE, stopbits=STOPBITS_ONE, timeout=None, xonxoff=0, rtscts=0, interCharTimeout=None) |
| 13 | |
| 14 | :param port: |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 15 | Device name or port number number or :const:`None`. |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 16 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 17 | :param baudrate: |
| 18 | Baud rate such as 9600 or 115200 etc. |
| 19 | |
| 20 | :param bytesize: |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 21 | Number of data bits. Possible values: |
| 22 | :const:`FIVEBITS`, :const:`SIXBITS`, :const:`SEVENBITS`, |
| 23 | :const:`EIGHTBITS` |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 24 | |
| 25 | :param parity: |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 26 | Enable parity checking. Possible values: |
| 27 | :const:`PARITY_NONE` :const:`PARITY_EVEN` :const:`PARITY_ODD` |
| 28 | :const:`PARITY_MARK` :const:`PARITY_SPACE` |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 29 | |
| 30 | :param stopbits: |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 31 | Number of stop bits. Possible values: |
| 32 | :const:`STOPBITS_ONE` :const:`STOPBITS_ONE_POINT_FIVE` |
| 33 | :const:`STOPBITS_TWO` |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 34 | |
| 35 | :param timeout: |
| 36 | Set a read timeout value. |
| 37 | |
| 38 | :param xonxoff: |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 39 | Enable software flow control. |
| 40 | |
| 41 | :param rtscts: |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 42 | Enable hardware (RTS/CTS) flow control. |
| 43 | |
| 44 | :param interCharTimeout: |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 45 | Inter-character timeout, :const:`None` to disable (default). |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 46 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 47 | :exception ValueError: |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 48 | 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] | 49 | |
| 50 | :exception SerialException: |
| 51 | In case the device can not be found or can not be configured. |
| 52 | |
| 53 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 54 | The port is immediately opened on object creation, when a *port* is |
| 55 | given. It is not opened when *port* is :const:`None` and a successive call |
| 56 | to :meth:`open` will be needed. |
| 57 | |
| 58 | Possible values for the parameter *port*: |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 59 | |
cliechti | 5134aab | 2009-07-21 19:47:59 +0000 | [diff] [blame] | 60 | - Number: number of device, numbering starts at zero. |
| 61 | - Device name: depending on operating system. e.g. ``/dev/ttyUSB0`` |
| 62 | on GNU/Linux or ``COM3`` on Windows. |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 63 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 64 | Possible values for the parameter *timeout*: |
cliechti | 5134aab | 2009-07-21 19:47:59 +0000 | [diff] [blame] | 65 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 66 | - ``timeout = None``: wait forever |
| 67 | - ``timeout = 0``: non-blocking mode (return immediately on read) |
cliechti | f81362e | 2009-07-25 03:44:33 +0000 | [diff] [blame] | 68 | - ``timeout = x``: set timeout to ``x`` seconds (float allowed) |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 69 | |
| 70 | |
| 71 | .. method:: open() |
| 72 | |
| 73 | Open port. |
| 74 | |
| 75 | .. method:: close() |
| 76 | |
| 77 | Close port immediately. |
| 78 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 79 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 80 | The following methods may raise :exc:`ValueError` when applied to a closed |
| 81 | port. |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 82 | |
| 83 | .. method:: read(size=1) |
| 84 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 85 | :param size: Number of bytes to read. |
| 86 | :return: Bytes read from the port. |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 87 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 88 | 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] | 89 | return less characters as requested. With no timeout it will block |
| 90 | until the requested number of bytes is read. |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 91 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 92 | .. versionchanged:: 2.5 |
| 93 | Returns an instance of :class:`bytes` when available (Python 2.6 |
| 94 | and newer) and :class:`str` otherwiese. |
| 95 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 96 | .. method:: write(data) |
| 97 | |
| 98 | :param data: Data to send. |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 99 | :return: Number of bytes written. |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 100 | :exception SerialTimeoutException: |
| 101 | In case a write timeout is configured for the port and the time is |
| 102 | exceeded. |
| 103 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 104 | Write the string *data* to the port. |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 105 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 106 | .. versionchanged:: 2.5 |
| 107 | Accepts an instance of :class:`bytes` when available (Python 2.6 |
| 108 | and newer) and :class:`str` otherwiese. |
| 109 | |
| 110 | .. method:: inWaiting() |
| 111 | |
| 112 | Return the number of chars in the receive buffer. |
| 113 | |
| 114 | .. method:: flush() |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 115 | |
| 116 | Flush of file like objects. In this case, wait until all data is |
| 117 | written. |
| 118 | |
| 119 | .. method:: flushInput() |
| 120 | |
| 121 | Flush input buffer, discarding all it's contents. |
| 122 | |
| 123 | .. method:: flushOutput() |
| 124 | |
| 125 | Clear output buffer, aborting the current output and |
| 126 | discarding all that is in the buffer. |
| 127 | |
| 128 | .. method:: sendBreak(duration=0.25) |
| 129 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 130 | :param duration: Time (float) to activate the BREAK condition. |
| 131 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 132 | Send break condition. Timed, returns to idle state after given |
| 133 | duration. |
| 134 | |
| 135 | .. method:: setBreak(level=True) |
| 136 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 137 | :param level: when true activate BREAK condition, else disable. |
| 138 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 139 | Set break: Controls TXD. When active, no transmitting is possible. |
| 140 | |
| 141 | .. method:: setRTS(level=True) |
| 142 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 143 | :param level: Set control line to logic level. |
| 144 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 145 | Set RTS line to specified logic level. |
| 146 | |
| 147 | .. method:: setDTR(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 DTR line to specified logic level. |
| 152 | |
| 153 | .. method:: getCTS() |
| 154 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 155 | :return: Current state (boolean) |
| 156 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 157 | Return the state of the CTS line. |
| 158 | |
| 159 | .. method:: getDSR() |
| 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 DSR line. |
| 164 | |
| 165 | .. method:: getRI() |
| 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 RI line. |
| 170 | |
| 171 | .. method:: getCD() |
| 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 CD line |
| 176 | |
| 177 | Read-only attributes: |
| 178 | |
cliechti | f81362e | 2009-07-25 03:44:33 +0000 | [diff] [blame] | 179 | .. attribute:: name |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 180 | |
cliechti | 5134aab | 2009-07-21 19:47:59 +0000 | [diff] [blame] | 181 | Device name. This is always the device name even if the |
| 182 | port was opened by a number. (Read Only). |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 183 | |
cliechti | f81362e | 2009-07-25 03:44:33 +0000 | [diff] [blame] | 184 | .. versionadded:: 2.5 |
| 185 | |
| 186 | .. attribute:: portstr |
| 187 | |
| 188 | :deprecated: use :attr:`name` instead |
| 189 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 190 | .. attribute:: BAUDRATES |
| 191 | |
| 192 | A list of valid baud rates. The list may be incomplete such that higher |
| 193 | baud rates may be supported by the device and that values in between the |
| 194 | standard baud rates are supported. (Read Only). |
| 195 | |
| 196 | .. attribute:: BYTESIZES |
| 197 | |
| 198 | A list of valid byte sizes for the device (Read Only). |
| 199 | |
| 200 | .. attribute:: PARITIES |
| 201 | |
| 202 | A list of valid parities for the device (Read Only). |
| 203 | |
| 204 | .. attribute:: STOPBITS |
| 205 | |
| 206 | A list of valid stop bit widths for the device (Read Only). |
| 207 | |
| 208 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 209 | New values can be assigned to the following attributes, the port will be |
| 210 | reconfigured, even if it's opened at that time: |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 211 | |
| 212 | .. attribute:: port |
| 213 | |
| 214 | Port name/number as set by the user. |
| 215 | |
| 216 | .. attribute:: baudrate |
| 217 | |
| 218 | Current baud rate setting. |
| 219 | |
| 220 | .. attribute:: bytesize |
| 221 | |
| 222 | Byte size in bits. |
| 223 | |
| 224 | .. attribute:: parity |
| 225 | |
| 226 | Parity setting. |
| 227 | |
| 228 | .. attribute:: stopbits |
| 229 | |
| 230 | Stop bit with. |
| 231 | |
| 232 | .. attribute:: timeout |
| 233 | |
cliechti | 5134aab | 2009-07-21 19:47:59 +0000 | [diff] [blame] | 234 | Timeout setting (seconds, float). |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 235 | |
| 236 | .. attribute:: xonxoff |
| 237 | |
| 238 | If Xon/Xoff flow control is enabled. |
| 239 | |
| 240 | .. attribute:: rtscts |
| 241 | |
| 242 | If hardware flow control is enabled. |
| 243 | |
| 244 | Platform specific methods. |
| 245 | |
| 246 | .. warning:: Programs using the following methods are not portable to other platforms! |
| 247 | |
| 248 | .. method:: nonblocking() |
| 249 | |
| 250 | :platform: Unix |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 251 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 252 | Configure the device for nonblocking operations. This can be useful if |
| 253 | the port is used with ``select``. |
| 254 | |
| 255 | .. method:: fileno() |
| 256 | |
| 257 | :platform: Unix |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 258 | :return: File descriptor. |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 259 | |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 260 | Return file descriptor number for the port that is opened by this object. |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 261 | |
| 262 | .. method:: setXON(level=True) |
| 263 | |
| 264 | :platform: Windows |
cliechti | bb5c3c5 | 2009-07-23 02:29:27 +0000 | [diff] [blame] | 265 | :param level: Set flow control state. |
cliechti | 86e8787 | 2009-07-21 13:32:45 +0000 | [diff] [blame] | 266 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 267 | Set software flow control state. |
| 268 | |
| 269 | |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 270 | .. class:: SerialBase |
| 271 | |
| 272 | The following attributes are implemented as properties. They work with open |
| 273 | and closed ports. |
| 274 | |
| 275 | .. attribute:: port |
| 276 | |
| 277 | Read or write port. When the port is already open, it will be closed |
| 278 | and reopened with the new setting. |
| 279 | |
| 280 | .. attribute:: baudrate |
| 281 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 282 | Read or write current baud rate setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 283 | |
| 284 | .. attribute:: bytesize |
| 285 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 286 | Read or write current data byte size setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 287 | |
| 288 | .. attribute:: parity |
| 289 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 290 | Read or write current parity setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 291 | |
| 292 | .. attribute:: stopbits |
| 293 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 294 | Read or write current stop bit width setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 295 | |
| 296 | .. attribute:: timeout |
| 297 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 298 | Read or write current read timeout setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 299 | |
| 300 | .. attribute:: writeTimeout |
| 301 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 302 | Read or write current write timeout setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 303 | |
| 304 | .. attribute:: xonxoff |
| 305 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 306 | Read or write current software flow control rate setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 307 | |
| 308 | .. attribute:: rtscts |
| 309 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 310 | Read or write current hardware flow control setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 311 | |
| 312 | .. attribute:: dsrdtr |
| 313 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 314 | Read or write current hardware flow control setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 315 | |
| 316 | .. attribute:: interCharTimeout |
| 317 | |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 318 | Read or write current inter character timeout setting. |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 319 | |
| 320 | The following constants are also provided: |
| 321 | |
| 322 | .. attribute:: BAUDRATES |
| 323 | |
| 324 | A tuple of standard baud rate values. The actual device may support more |
| 325 | or less... |
| 326 | |
| 327 | .. attribute:: BYTESIZES |
| 328 | |
| 329 | A tuple of supported byte size values. |
| 330 | |
| 331 | .. attribute:: PARITIES |
| 332 | |
| 333 | A tuple of supported parity settings. |
| 334 | |
| 335 | .. attribute:: STOPBITS |
| 336 | |
| 337 | A tuple of supported stop bit settings. |
| 338 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 339 | .. method:: readline(size=None, eol='\\n') |
| 340 | |
| 341 | :param size: Max number of bytes to read, ``None`` -> no limit. |
| 342 | :param eol: The end of line character. |
| 343 | |
| 344 | Read a line which is terminated with end-of-line (*eol*) character |
| 345 | (``\\n`` by default) or until timeout. |
| 346 | |
| 347 | .. method:: readlines(sizehint=None, eol='\\n') |
| 348 | |
| 349 | :param size: Ignored parameter. |
| 350 | :param eol: The end of line character. |
| 351 | |
| 352 | Read a list of lines, until timeout. *sizehint* is ignored and only |
| 353 | present for API compatibility with built-in File objects. |
| 354 | |
| 355 | .. method:: xreadlines(sizehint=None) |
| 356 | |
| 357 | Just calls :meth:`readlines` - here for compatibility. |
| 358 | |
| 359 | For compatibility with the :mod:`io` library are the following methods. |
| 360 | |
| 361 | .. method:: readable() |
| 362 | |
| 363 | :return: True |
| 364 | .. versionadded:: 2.5 |
| 365 | |
| 366 | .. method:: writable() |
| 367 | |
| 368 | :return: True |
| 369 | .. versionadded:: 2.5 |
| 370 | |
| 371 | .. method:: seekable() |
| 372 | |
| 373 | :return: False |
| 374 | .. versionadded:: 2.5 |
| 375 | |
| 376 | .. method:: readinto(b) |
| 377 | |
| 378 | :param b: bytearray or array instace |
| 379 | :return: Number of byte read |
| 380 | |
| 381 | Read up to len(b) bytes into bytearray b and return the number of bytes read. |
| 382 | |
| 383 | .. versionadded:: 2.5 |
| 384 | |
| 385 | |
| 386 | .. note:: |
| 387 | |
| 388 | For systems that provide the :mod:`io` library (Python 2.6 and newer), the |
| 389 | class :class:`Serial` will derrive from :class:`io.RawIOBase`. For all |
| 390 | others from :class:`FileLike`. |
| 391 | |
| 392 | .. class:: FileLike |
| 393 | |
| 394 | An abstract file like class. It is used as base class for :class:`Serial`. |
| 395 | |
| 396 | This class implements :meth:`readline` and :meth:`readlines` based on read |
| 397 | and :meth:`writelines` based on write. This class is used to provide the |
| 398 | above functions for to Serial port objects. |
| 399 | |
| 400 | Note that when the serial port was opened with no timeout that |
| 401 | :meth:`readline` blocks until it sees a newline (or the specified size is |
| 402 | reached) and that :meth:`readlines` would never return and therefore |
| 403 | refuses to work (it raises an exception in this case)! |
| 404 | |
| 405 | .. method:: writelines(sequence) |
| 406 | |
| 407 | Write a list of strings to the port. |
| 408 | |
| 409 | |
| 410 | The following three methods are overridden in :class:`Serial`. |
| 411 | |
| 412 | .. method:: flush() |
| 413 | |
| 414 | Flush of file like objects. It's a no-op in this class, may be overridden. |
| 415 | |
| 416 | .. method:: read() |
| 417 | |
| 418 | Raises NotImplementedError, needs to be overridden by subclass. |
| 419 | |
| 420 | .. method:: write(data) |
| 421 | |
| 422 | Raises NotImplementedError, needs to be overridden by subclass. |
| 423 | |
| 424 | The following functions are implemented for compatibility with other |
| 425 | file-like objects, however serial ports are not seekable. |
| 426 | |
| 427 | |
| 428 | .. method:: seek(pos, whence=0) |
| 429 | |
| 430 | :exception IOError: always, as method is not supported on serial port |
| 431 | |
| 432 | .. versionadded:: 2.5 |
| 433 | |
| 434 | .. method:: tell() |
| 435 | |
| 436 | :exception IOError: always, as method is not supported on serial port |
| 437 | |
| 438 | .. versionadded:: 2.5 |
| 439 | |
| 440 | .. method:: truncate(self, n=None) |
| 441 | |
| 442 | :exception IOError: always, as method is not supported on serial port |
| 443 | |
| 444 | .. versionadded:: 2.5 |
| 445 | |
| 446 | .. method:: isatty() |
| 447 | |
| 448 | :exception IOError: always, as method is not supported on serial port |
| 449 | |
| 450 | .. versionadded:: 2.5 |
| 451 | |
| 452 | To be able to use the file like object as iterator for e.g. |
| 453 | ``for line in Serial(0): ...`` usage: |
| 454 | |
| 455 | .. method:: next() |
| 456 | |
| 457 | Return the next line by calling :meth:`readline`. |
| 458 | |
| 459 | .. method:: __iter__() |
| 460 | |
| 461 | Returns self. |
| 462 | |
cliechti | edcdbe4 | 2009-07-22 00:48:34 +0000 | [diff] [blame] | 463 | |
| 464 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 465 | Exceptions |
| 466 | ========== |
| 467 | |
| 468 | .. exception:: SerialException |
| 469 | |
| 470 | Base class for serial port exceptions. |
| 471 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 472 | .. versionchanged:: 2.5 |
| 473 | Now derrives from :exc:`IOError` instead of :exc:`Exception` |
| 474 | |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 475 | .. exception:: SerialTimeoutException |
| 476 | |
| 477 | Exception that is raised on write timeouts. |
| 478 | |
| 479 | |
| 480 | Constants |
| 481 | ========= |
| 482 | |
cliechti | 5134aab | 2009-07-21 19:47:59 +0000 | [diff] [blame] | 483 | Parity |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 484 | ------ |
| 485 | .. data:: PARITY_NONE |
| 486 | .. data:: PARITY_EVEN |
| 487 | .. data:: PARITY_ODD |
| 488 | .. data:: PARITY_MARK |
| 489 | .. data:: PARITY_SPACE |
| 490 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 491 | Stop bits |
| 492 | --------- |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 493 | .. data:: STOPBITS_ONE |
| 494 | .. data:: STOPBITS_ONE_POINT_FIVE |
| 495 | .. data:: STOPBITS_TWO |
| 496 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 497 | Byte size |
| 498 | --------- |
cliechti | c1c3760 | 2009-07-21 01:34:57 +0000 | [diff] [blame] | 499 | .. data:: FIVEBITS |
| 500 | .. data:: SIXBITS |
| 501 | .. data:: SEVENBITS |
| 502 | .. data:: EIGHTBITS |
cliechti | 5b7d16a | 2009-07-21 21:53:59 +0000 | [diff] [blame] | 503 | |
| 504 | Others |
| 505 | ------- |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 506 | Default control characters for software flow control: |
cliechti | 6066f84 | 2009-07-24 00:05:45 +0000 | [diff] [blame] | 507 | |
cliechti | 5b7d16a | 2009-07-21 21:53:59 +0000 | [diff] [blame] | 508 | .. data:: XON |
| 509 | .. data:: XOFF |
cliechti | f81362e | 2009-07-25 03:44:33 +0000 | [diff] [blame] | 510 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame^] | 511 | Module version: |
cliechti | f81362e | 2009-07-25 03:44:33 +0000 | [diff] [blame] | 512 | |
| 513 | .. data:: VERSION |
| 514 | |
| 515 | A string indicating the pySerial version, such as ``2.5``. |
| 516 | |
| 517 | Functions: |
| 518 | |
| 519 | .. function:: device(number) |
| 520 | |
| 521 | :param number: Port number. |
| 522 | :return: String containing device name. |
| 523 | :deprecated: Use device names directly. |
| 524 | |
| 525 | Convert a port number to a platform dependent device name. Unfortunately |
| 526 | this does not work well for all platforms; e.g. some may miss USB-Serial |
| 527 | converters and enumerate only internal serial ports. |
| 528 | |
| 529 | The conversion may be made off-line, that is, there is no guarantee that |
| 530 | the returned device name really exists on the system. |