py serial

46
pySerial Documentation Release 2.6 Chris Liechti December 08, 2011

Upload: abhisheknkar

Post on 08-Feb-2016

158 views

Category:

Documents


7 download

DESCRIPTION

Serial module of Python

TRANSCRIPT

Page 1: Py Serial

pySerial DocumentationRelease 2.6

Chris Liechti

December 08, 2011

Page 2: Py Serial
Page 3: Py Serial

CONTENTS

1 pySerial 31.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.3 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.4 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.6 Older Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2 Short introduction 72.1 Opening serial ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.2 Configuring ports later . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.3 Readline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.4 Testing ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3 Examples 93.1 Miniterm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.2 TCP/IP - serial bridge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.3 Single-port TCP/IP - serial bridge (RFC 2217) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.4 Multi-port TCP/IP - serial bridge (RFC 2217) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.5 wxPython examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.6 Wrapper class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.7 Unit tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

4 pySerial API 154.1 Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154.2 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234.4 Module functions and attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244.5 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

5 pyParallel 295.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295.2 Short introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305.3 API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305.4 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305.5 Misc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

6 Appendix 336.1 How To . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336.2 FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

i

Page 4: Py Serial

6.3 Related software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346.4 License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

7 Indices and tables 37

Python Module Index 39

Index 41

ii

Page 5: Py Serial

pySerial Documentation, Release 2.6

This module encapsulates the access for the serial port. It provides backends for Python running on Windows, Linux,BSD (possibly any POSIX compliant system), Jython and IronPython (.NET and Mono). The module named “serial”automatically selects the appropriate backend.

Other pages (online)

• project page on SourceForge

• SVN repository

• Download Page with releases

• This page, when viewed online, is at http://pyserial.sf.net.

Contents:

CONTENTS 1

Page 6: Py Serial

pySerial Documentation, Release 2.6

2 CONTENTS

Page 7: Py Serial

CHAPTER

ONE

PYSERIAL

1.1 Overview

This module encapsulates the access for the serial port. It provides backends for Python running on Windows, Linux,BSD (possibly any POSIX compliant system), Jython and IronPython (.NET and Mono). The module named “serial”automatically selects the appropriate backend.

It is released under a free software license, see LICENSE for more details.

Copyright (C) 2001-2010 Chris Liechti <cliechti(at)gmx.net>

Other pages (online)

• project page on SourceForge

• SVN repository

• Download Page with releases

• This page, when viewed online is at http://pyserial.sf.net.

1.2 Features

• Same class based interface on all supported platforms.

• Access to the port settings through Python properties.

• Support for different byte sizes, stop bits, parity and flow control with RTS/CTS and/or Xon/Xoff.

• Working with or without receive timeout.

• File like API with “read” and “write” (“readline” etc. also supported).

• The files in this package are 100% pure Python.

• The port is set up for binary transmission. No NULL byte stripping, CR-LF translation etc. (which are manytimes enabled for POSIX.) This makes this module universally useful.

• Compatible with io library (Python 2.6+)

• RFC 2217 client (experimental), server provided in the examples.

3

Page 8: Py Serial

pySerial Documentation, Release 2.6

1.3 Requirements

• Python 2.3 or newer, including Python 3.x

• ctypes extensions on Windows (is in standard library since Python 2.5+)

• “Java Communications” (JavaComm) or compatible extension for Java/Jython

1.4 Installation

1.4.1 pyserial

This installs a package that can be used from Python (import serial).

To install the module for all users on the system, administrator rights (root) is required..

From source (tar.gz or checkout)

Download the archive from http://pypi.python.org/pypi/pyserial. Unpack the archive, enter the pyserial-x.ydirectory and run:

python setup.py install

For Python 3.x:

python3 setup.py install

From PyPI

Alternatively it can be installed from PyPI, either manually downloading the files and installing as described above orusing:

pip pyserial

or:

easy_install -U pyserial

Packages

There are also packaged versions for some Linux distributions and Windows:

Debian/Ubuntu A package is available under the name “python-serial”. Note that some distributions package anolder version of pySerial.

Windows There is also a Windows installer for end users. It is located in the PyPi. Developers may be interested toget the source archive, because it contains examples and the readme.

4 Chapter 1. pySerial

Page 9: Py Serial

pySerial Documentation, Release 2.6

1.5 References

• Python: http://www.python.org/

• Jython: http://www.jython.org/

• Java@IBM: http://www-106.ibm.com/developerworks/java/jdk/ (JavaComm links are on the download page forthe respective platform JDK)

• Java@SUN: http://java.sun.com/products/

• IronPython: http://www.codeplex.com/IronPython

• setuptools: http://peak.telecommunity.com/DevCenter/setuptools

1.6 Older Versions

Older versions are still available on the Download Page. pySerial 1.21 is compatible with Python 2.0 on Windows,Linux and several un*x like systems, MacOSX and Jython.

On windows releases older than 2.5 will depend on pywin32 (previously known as win32all)

1.5. References 5

Page 10: Py Serial

pySerial Documentation, Release 2.6

6 Chapter 1. pySerial

Page 11: Py Serial

CHAPTER

TWO

SHORT INTRODUCTION

2.1 Opening serial ports

Open port 0 at “9600,8,N,1”, no timeout:

>>> import serial>>> ser = serial.Serial(0) # open first serial port>>> print ser.portstr # check which port was really used>>> ser.write("hello") # write a string>>> ser.close() # close port

Open named port at “19200,8,N,1”, 1s timeout:

>>> ser = serial.Serial(’/dev/ttyS1’, 19200, timeout=1)>>> x = ser.read() # read one byte>>> s = ser.read(10) # read up to ten bytes (timeout)>>> line = ser.readline() # read a ’\n’ terminated line>>> ser.close()

Open second port at “38400,8,E,1”, non blocking HW handshaking:

>>> ser = serial.Serial(1, 38400, timeout=0,... parity=serial.PARITY_EVEN, rtscts=1)>>> s = ser.read(100) # read up to one hundred bytes... # or as much is in the buffer

2.2 Configuring ports later

Get a Serial instance and configure/open it later:

>>> ser = serial.Serial()>>> ser.baudrate = 19200>>> ser.port = 0>>> serSerial<id=0xa81c10, open=False>(port=’COM1’, baudrate=19200, bytesize=8, parity=’N’, stopbits=1, timeout=None, xonxoff=0, rtscts=0)>>> ser.open()>>> ser.isOpen()True>>> ser.close()>>> ser.isOpen()False

7

Page 12: Py Serial

pySerial Documentation, Release 2.6

2.3 Readline

Be carefully when using readline(). Do specify a timeout when opening the serial port otherwise it could blockforever if no newline character is received. Also note that readlines() only works with a timeout. readlines()depends on having a timeout and interprets that as EOF (end of file). It raises an exception if the port is not openedcorrectly.

Do also have a look at the example files in the examples directory in the source distribution or online.

Note: The eol parameter for readline() is no longer supported when pySerial is run with newer Python versions(V2.6+) where the module io is available.

2.3.1 EOL

To specify the EOL character for readline() or to use universal newline mode, it is advised to useio.TextIOWrapper:

import serialimport ioser = serial.serial_for_url(’loop://’, timeout=1)sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))

sio.write(unicode("hello\n"))sio.flush() # it is buffering. required to get the data out *now*hello = sio.readline()print hello == unicode("hello\n")

2.4 Testing ports

2.4.1 Listing ports

python -m serial.tools.list_ports will print a list of available ports. It is also possible to add a regexpas first argument and the list will only include entries that matched.

Note: The enumeration may not work on all operating systems. It may be incomplete, list unavailable ports or maylack detailed descriptions of the ports.

2.4.2 Accessing ports

pySerial includes a small terminal console based terminal program called Miniterm. It ca be started with python -mserial.tools.miniterm <port name> (use option -h to get a listing of all options).

8 Chapter 2. Short introduction

Page 13: Py Serial

CHAPTER

THREE

EXAMPLES

3.1 Miniterm

This is a console application that provides a small terminal application. Miniterm itself does not implement anyterminal features such as VT102 compatibility. However it inherits these features from the terminal it is run. Forexample on GNU/Linux running from an xterm it will support the escape sequences of the xterm. On Windows thetypical console window is dumb and does not support any escapes. When ANSI.sys is loaded it supports some escapes.

Miniterm:

--- Miniterm on /dev/ttyS0: 9600,8,N,1 ------ Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---

Command line options can be given so that binary data including escapes for terminals are escaped or output as hex.

Miniterm supports RFC 2217 remote serial ports and raw sockets using URLs such asrfc2217:://<host>:<port> respectively socket://<host>:<port> as port argument when invoking.

Command line options python -m serial.tools.miniterm -h:

Usage: miniterm.py [options] [port [baudrate]]

Miniterm - A simple terminal program for the serial port.

Options:-h, --help show this help message and exit-p PORT, --port=PORT port, a number (default 0) or a device name

(deprecated option)-b BAUDRATE, --baud=BAUDRATE

set baud rate, default 9600--parity=PARITY set parity, one of [N, E, O, S, M], default=N-e, --echo enable local echo (default off)--rtscts enable RTS/CTS flow control (default off)--xonxoff enable software flow control (default off)--cr do not send CR+LF, send CR only--lf do not send CR+LF, send LF only-D, --debug debug received data (escape non-printable chars)

--debug can be given multiple times: 0: just printwhat is received 1: escape non-printable characters,do newlines as unusual 2: escape non-printablecharacters, newlines too 3: hex dump everything

--rts=RTS_STATE set initial RTS line state (possible values: 0, 1)--dtr=DTR_STATE set initial DTR line state (possible values: 0, 1)-q, --quiet suppress non error messages

9

Page 14: Py Serial

pySerial Documentation, Release 2.6

--exit-char=EXIT_CHARASCII code of special character that is used to exitthe application

--menu-char=MENU_CHARASCII code of special character that is used tocontrol miniterm (menu)

Miniterm supports some control functions. Typing Ctrl+T Ctrl+H when it is running shows the help text:

--- pySerial - miniterm - help------ Ctrl+] Exit program--- Ctrl+T Menu escape key, followed by:--- Menu keys:--- Ctrl+T Send the menu character itself to remote--- Ctrl+] Send the exit character to remote--- Ctrl+I Show info--- Ctrl+U Upload file (prompt will be shown)--- Toggles:--- Ctrl+R RTS Ctrl+E local echo--- Ctrl+D DTR Ctrl+B BREAK--- Ctrl+L line feed Ctrl+A Cycle repr mode------ Port settings (Ctrl+T followed by the following):--- p change port--- 7 8 set data bits--- n e o s m change parity (None, Even, Odd, Space, Mark)--- 1 2 3 set stop bits (1, 2, 1.5)--- b change baud rate--- x X disable/enable software flow control--- r R disable/enable hardware flow control

Changed in version 2.5: Added Ctrl+T menu and added support for opening URLs.Changed in version 2.6: Filemoved from the examples to serial.tools.miniterm.

miniterm.py The miniterm program.

setup-miniterm-py2exe.py This is a py2exe setup script for Windows. It can be used to create a standaloneminiterm.exe.

3.2 TCP/IP - serial bridge

This program opens a TCP/IP port. When a connection is made to that port (e.g. with telnet) it forwards all data to theserial port and vice versa.

This example only exports a raw socket connection. The next example below gives the client much more control overthe remote serial port.

• The serial port settings are set on the command line when starting the program.

• There is no possibility to change settings from remote.

• All data is passed through as-is.

Usage: tcp_serial_redirect.py [options] [port [baudrate]]

Simple Serial to Network (TCP/IP) redirector.

10 Chapter 3. Examples

Page 15: Py Serial

pySerial Documentation, Release 2.6

Options:-h, --help show this help message and exit-q, --quiet suppress non error messages--spy peek at the communication and print all data to the

console

Serial Port:Serial port settings

-p PORT, --port=PORTport, a number (default 0) or a device name

-b BAUDRATE, --baud=BAUDRATEset baud rate, default: 9600

--parity=PARITY set parity, one of [N, E, O], default=N--rtscts enable RTS/CTS flow control (default off)--xonxoff enable software flow control (default off)--rts=RTS_STATE set initial RTS line state (possible values: 0, 1)--dtr=DTR_STATE set initial DTR line state (possible values: 0, 1)

Network settings:Network configuration.

-P LOCAL_PORT, --localport=LOCAL_PORTlocal TCP port

--rfc2217 allow control commands with Telnet extension RFC-2217

Newline Settings:Convert newlines between network and serial port. Conversion isnormally disabled and can be enabled by --convert.

-c, --convert enable newline conversion (default off)--net-nl=NET_NEWLINE

type of newlines that are expected on the network(default: LF)

--ser-nl=SER_NEWLINEtype of newlines that are expected on the serial port(default: CR+LF)

NOTE: no security measures are implemented. Anyone can remotely connect tothis service over the network. Only one connection at once is supported. Whenthe connection is terminated it waits for the next connect.

tcp_serial_redirect.py Main program.

3.3 Single-port TCP/IP - serial bridge (RFC 2217)

Simple cross platform RFC 2217 serial port server. It uses threads and is portable (runs on POSIX, Windows, etc).

• The port settings and control lines (RTS/DTR) can be changed at any time using RFC 2217 requests. The statuslines (DSR/CTS/RI/CD) are polled every second and notifications are sent to the client.

• Telnet character IAC (0xff) needs to be doubled in data stream. IAC followed by an other value is interpreted asTelnet command sequence.

• Telnet negotiation commands are sent when connecting to the server.

• RTS/DTR are activated on client connect and deactivated on disconnect.

3.3. Single-port TCP/IP - serial bridge (RFC 2217) 11

Page 16: Py Serial

pySerial Documentation, Release 2.6

• Default port settings are set again when client disconnects.

Usage: rfc2217_server.py [options] port

RFC 2217 Serial to Network (TCP/IP) redirector.

Options:-h, --help show this help message and exit-p LOCAL_PORT, --localport=LOCAL_PORT

local TCP port

NOTE: no security measures are implemented. Anyone can remotely connect tothis service over the network. Only one connection at once is supported. Whenthe connection is terminated it waits for the next connect.

New in version 2.5.

rfc2217_server.py Main program.

setup-rfc2217_server-py2exe.py This is a py2exe setup script for Windows. It can be used to create a standalonerfc2217_server.exe.

3.4 Multi-port TCP/IP - serial bridge (RFC 2217)

This example implements a TCP/IP to serial port service that works with multiple ports at once. It uses select, nothreads, for the serial ports and the network sockets and therefore runs on POSIX systems only.

• Full control over the serial port with RFC 2217.

• Check existence of /tty/USB0...8. This is done every 5 seconds using os.path.exists.

• Send zeroconf announcements when port appears or disappears (uses python-avahi and dbus). Service name:_serial_port._tcp.

• Each serial port becomes available as one TCP/IP server. e.g. /dev/ttyUSB0 is reachable at <host>:7000.

• Single process for all ports and sockets (not per port).

• The script can be started as daemon.

• Logging to stdout or when run as daemon to syslog.

• Default port settings are set again when client disconnects.

• modem status lines (CTS/DSR/RI/CD) are not polled periodically and the server therefore does not send NO-TIFY_MODEMSTATE on its own. However it responds to request from the client (i.e. use the poll_modemoption in the URL when using a pySerial client.)

Requirements:

• Python (>= 2.4)

• python-avahi

• python-dbus

• python-serial (>= 2.5)

Installation as daemon:

• Copy the script port_publisher.py to /usr/local/bin.

• Copy the script port_publisher.sh to /etc/init.d.

12 Chapter 3. Examples

Page 17: Py Serial

pySerial Documentation, Release 2.6

• Add links to the runlevels using update-rc.d port_publisher.sh defaults 99

• Thats it :-) the service will be started on next reboot. Alternatively run invoke-rc.dport_publisher.sh start as root.

New in version 2.5: new example

port_publisher.py Multi-port TCP/IP-serial converter (RFC 2217) for POSIX environments.

port_publisher.sh Example init.d script.

3.5 wxPython examples

A simple terminal application for wxPython and a flexible serial port configuration dialog are shown here.

wxTerminal.py A simple terminal application. Note that the length of the buffer is limited by wx and it may suddenlystop displaying new input.

wxTerminal.wxg A wxGlade design file for the terminal application.

wxSerialConfigDialog.py A flexible serial port configuration dialog.

wxSerialConfigDialog.wxg The wxGlade design file for the configuration dialog.

setup-wxTerminal-py2exe.py A py2exe setup script to package the terminal application.

3.6 Wrapper class

This example provides a subclass based on Serial that has an alternative implementation of readline()

enhancedserial.py A class with alternative readline() implementation.

3.7 Unit tests

The project uses a number of unit test to verify the functionality. They all need a loop back connector. The scriptsitself contain more information. All test scripts are contained in the directory test.

The unit tests are performed on port 0 unless a different device name or rfc2217:// URL is given on the commandline (argv[1]).

run_all_tests.py Collect all tests from all test* files and run them. By default, the loop:// device is used.

test.py Basic tests (binary capabilities, timeout, control lines).

test_advanced.py Test more advanced features (properties).

test_high_load.py Tests involving sending a lot of data.

test_readline.py Tests involving readline.

test_iolib.py Tests involving the io library. Only available for Python 2.6 and newer.

test_url.py Tests involving the URL feature.

3.5. wxPython examples 13

Page 18: Py Serial

pySerial Documentation, Release 2.6

14 Chapter 3. Examples

Page 19: Py Serial

CHAPTER

FOUR

PYSERIAL API

4.1 Classes

4.1.1 Native ports

class serial.Serial

__init__(port=None, baudrate=9600, bytesize=EIGHTBITS, parity=PARITY_NONE, stop-bits=STOPBITS_ONE, timeout=None, xonxoff=False, rtscts=False, writeTimeout=None,dsrdtr=False, interCharTimeout=None)

Parameters

• port – Device name or port number number or None.

• baudrate – Baud rate such as 9600 or 115200 etc.

• bytesize – Number of data bits. Possible values: FIVEBITS, SIXBITS, SEVENBITS,EIGHTBITS

• parity – Enable parity checking. Possible values: PARITY_NONE, PARITY_EVEN,PARITY_ODD PARITY_MARK, PARITY_SPACE

• stopbits – Number of stop bits. Possible values: STOPBITS_ONE,STOPBITS_ONE_POINT_FIVE, STOPBITS_TWO

• timeout – Set a read timeout value.

• xonxoff – Enable software flow control.

• rtscts – Enable hardware (RTS/CTS) flow control.

• dsrdtr – Enable hardware (DSR/DTR) flow control.

• writeTimeout – Set a write timeout value.

• interCharTimeout – Inter-character timeout, None to disable (default).

Raises

• ValueError – Will be raised when parameter are out of range, e.g. baud rate, data bits.

• SerialException – In case the device can not be found or can not be configured.

The port is immediately opened on object creation, when a port is given. It is not opened when port isNone and a successive call to open() will be needed.

Possible values for the parameter port:

15

Page 20: Py Serial

pySerial Documentation, Release 2.6

•Number: number of device, numbering starts at zero.

•Device name: depending on operating system. e.g. /dev/ttyUSB0 on GNU/Linux or COM3 onWindows.

The parameter baudrate can be one of the standard values: 50, 75, 110, 134, 150, 200, 300, 600, 1200,1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200. These are well supported on all platforms.Standard values above 115200 such as: 230400, 460800, 500000, 576000, 921600, 1000000, 1152000,1500000, 2000000, 2500000, 3000000, 3500000, 4000000 also work on many platforms.

Non-standard values are also supported on some platforms (GNU/Linux, MAC OSX >= Tiger, Windows).Though, even on these platforms some serial ports may reject non-standard values.

Possible values for the parameter timeout:

•timeout = None: wait forever

•timeout = 0: non-blocking mode (return immediately on read)

•timeout = x: set timeout to x seconds (float allowed)

Writes are blocking by default, unless writeTimeout is set. For possible values refer to the list for timeoutabove.

Note that enabling both flow control methods (xonxoff and rtscts) together may not be supported. It iscommon to use one of the methods at once, not both.

dsrdtr is not supported by all platforms (silently ignored). Setting it to None has the effect that its statefollows rtscts.

Also consider using the function serial_for_url() instead of creating Serial instances directly.Changed in version 2.5: dsrdtr now defaults to False (instead of None)

open()Open port.

close()Close port immediately.

__del__()Destructor, close port when serial port instance is freed.

The following methods may raise ValueError when applied to a closed port.

read(size=1)

Parameters size – Number of bytes to read.

Returns Bytes read from the port.

Read size bytes from the serial port. If a timeout is set it may return less characters as requested. Withno timeout it will block until the requested number of bytes is read. Changed in version 2.5: Returns aninstance of bytes when available (Python 2.6 and newer) and str otherwise.

write(data)

Parameters data – Data to send.

Returns Number of bytes written.

Raises SerialTimeoutException In case a write timeout is configured for the port and the timeis exceeded.

Write the string data to the port. Changed in version 2.5: Accepts instances of bytes and bytearraywhen available (Python 2.6 and newer) and str otherwise.Changed in version 2.5: Write returned Nonein previous versions.

16 Chapter 4. pySerial API

Page 21: Py Serial

pySerial Documentation, Release 2.6

inWaiting()Return the number of chars in the receive buffer.

flush()Flush of file like objects. In this case, wait until all data is written.

flushInput()Flush input buffer, discarding all it’s contents.

flushOutput()Clear output buffer, aborting the current output and discarding all that is in the buffer.

sendBreak(duration=0.25)

Parameters duration – Time (float) to activate the BREAK condition.

Send break condition. Timed, returns to idle state after given duration.

setBreak(level=True)

Parameters level – when true activate BREAK condition, else disable.

Set break: Controls TXD. When active, no transmitting is possible.

setRTS(level=True)

Parameters level – Set control line to logic level.

Set RTS line to specified logic level.

setDTR(level=True)

Parameters level – Set control line to logic level.

Set DTR line to specified logic level.

getCTS()

Returns Current state (boolean)

Return the state of the CTS line.

getDSR()

Returns Current state (boolean)

Return the state of the DSR line.

getRI()

Returns Current state (boolean)

Return the state of the RI line.

getCD()

Returns Current state (boolean)

Return the state of the CD line

Read-only attributes:

nameDevice name. This is always the device name even if the port was opened by a number. (Read Only). Newin version 2.5.

portstr

Deprecated use name instead

4.1. Classes 17

Page 22: Py Serial

pySerial Documentation, Release 2.6

New values can be assigned to the following attributes (properties), the port will be reconfigured, even if it’sopened at that time:

portRead or write port. When the port is already open, it will be closed and reopened with the new setting.

baudrateRead or write current baud rate setting.

bytesizeRead or write current data byte size setting.

parityRead or write current parity setting.

stopbitsRead or write current stop bit width setting.

timeoutRead or write current read timeout setting.

writeTimeoutRead or write current write timeout setting.

xonxoffRead or write current software flow control rate setting.

rtsctsRead or write current hardware flow control setting.

dsrdtrRead or write current hardware flow control setting.

interCharTimeoutRead or write current inter character timeout setting.

The following constants are also provided:

BAUDRATESA list of valid baud rates. The list may be incomplete such that higher baud rates may be supported by thedevice and that values in between the standard baud rates are supported. (Read Only).

BYTESIZESA list of valid byte sizes for the device (Read Only).

PARITIESA list of valid parities for the device (Read Only).

STOPBITSA list of valid stop bit widths for the device (Read Only).

The following methods are for compatibility with the io library.

readable()

Returns True

New in version 2.5.

writable()

Returns True

New in version 2.5.

seekable()

18 Chapter 4. pySerial API

Page 23: Py Serial

pySerial Documentation, Release 2.6

Returns False

New in version 2.5.

readinto(b)

Parameters b – bytearray or array instance

Returns Number of byte read

Read up to len(b) bytes into bytearray b and return the number of bytes read. New in version 2.5.

The port settings can be read and written as dictionary.

getSettingsDict()

Returns a dictionary with current port settings.

Get a dictionary with port settings. This is useful to backup the current settings so that a later point in timethey can be restored using applySettingsDict().

Note that control lines (RTS/DTR) are part of the settings. New in version 2.5.

applySettingsDict(d)

Parameters d – a dictionary with port settings.

Applies a dictionary that was created by getSettingsDict(). Only changes are applied and when akey is missing it means that the setting stays unchanged.

Note that control lines (RTS/DTR) are not changed. New in version 2.5.

Platform specific methods.

Warning: Programs using the following methods are not portable to other platforms!

nonblocking()

Platform Unix

Configure the device for nonblocking operation. This can be useful if the port is used with select.

fileno()

Platform Unix

Returns File descriptor.

Return file descriptor number for the port that is opened by this object. It is useful when serial ports areused with select.

setXON(level=True)

Platform Windows

Parameters level – Set flow control state.

Set software flow control state.

Note: For systems that provide the io library (Python 2.6 and newer), the class Serial will derive fromio.RawIOBase. For all others from FileLike.

Implementation detail: some attributes and functions are provided by the class SerialBase and some by the plat-form specific class and others by the base class mentioned above.

4.1. Classes 19

Page 24: Py Serial

pySerial Documentation, Release 2.6

class serial.FileLikeAn abstract file like class. It is used as base class for Serial when no io module is available.

This class implements readline() and readlines() based on read() and writelines() based onwrite().

Note that when the serial port was opened with no timeout, that readline() blocks until it sees a newline(or the specified size is reached) and that readlines() would never return and therefore refuses to work (itraises an exception in this case)!

writelines(sequence)Write a list of strings to the port.

The following three methods are overridden in Serial.

flush()Flush of file like objects. It’s a no-op in this class, may be overridden.

read()Raises NotImplementedError, needs to be overridden by subclass.

write(data)Raises NotImplementedError, needs to be overridden by subclass.

The following functions are implemented for compatibility with other file-like objects, however serial ports arenot seekable.

seek(pos, whence=0)

Raises IOError always, as method is not supported on serial port

New in version 2.5.

tell()

Raises IOError always, as method is not supported on serial port

New in version 2.5.

truncate(self, n=None)

Raises IOError always, as method is not supported on serial port

New in version 2.5.

isatty()

Raises IOError always, as method is not supported on serial port

New in version 2.5.

To be able to use the file like object as iterator for e.g. for line in Serial(0): ... usage:

next()Return the next line by calling readline().

__iter__()Returns self.

Other high level access functions.

readline(size=None, eol=’\n’)

Parameters

• size – Max number of bytes to read, None -> no limit.

• eol – The end of line character.

20 Chapter 4. pySerial API

Page 25: Py Serial

pySerial Documentation, Release 2.6

Read a line which is terminated with end-of-line (eol) character (\n by default) or until timeout.

readlines(sizehint=None, eol=’\n’)

Parameters

• sizehint – Ignored parameter.

• eol – The end of line character.

Read a list of lines, until timeout. sizehint is ignored and only present for API compatibility with built-inFile objects.

Note that this function only returns on a timeout.

xreadlines(sizehint=None)Read lines, implemented as generator. Unlike readlines (that only returns on a timeout) is this functionyielding lines as they are received. Deprecated since version 2.5: Use for line in Serial(...):... instead. This method is not available in Python 2.6 and newer where the io library is available andpySerial bases on it.Changed in version 2.5: Implement as generator.

4.1.2 RFC 2217 Network ports

Warning: This implementation is currently in an experimental state. Use at your own risk.

class rfc2217.SerialThis implements a RFC 2217 compatible client. Port names are URLs in the form:rfc2217://<host>:<port>[/<option>[/<option>]]

This class API is compatible to Serial with a few exceptions:

•numbers as port name are not allowed, only URLs in the form described above.

•writeTimeout is not implemented

•The current implementation starts a thread that keeps reading from the (internal) socket. The thread ismanaged automatically by the rfc2217.Serial port object on open()/close(). However it maybe a problem for user applications that like to use select instead of threads.

Due to the nature of the network and protocol involved there are a few extra points to keep in mind:

•All operations have an additional latency time.

•Setting control lines (RTS/CTS) needs more time.

•Reading the status lines (DSR/DTR etc.) returns a cached value. When that cache is updated dependsentirely on the server. The server itself may implement a polling at a certain rate and quick changes maybe invisible.

•The network layer also has buffers. This means that flush(), flushInput() and flushOutput()may work with additional delay. Likewise inWaiting() returns the size of the data arrived at the objectinternal buffer and excludes any bytes in the network buffers or any server side buffer.

•Closing and immediately reopening the same port may fail due to time needed by the server to get readyagain.

Not implemented yet / Possible problems with the implementation:

•RFC 2217 flow control between client and server (objects internal buffer may eat all your memory whennever read).

•No authentication support (servers may not prompt for a password etc.)

4.1. Classes 21

Page 26: Py Serial

pySerial Documentation, Release 2.6

•No encryption.

Due to lack of authentication and encryption it is not suitable to use this client for connections across the internetand should only be used in controlled environments. New in version 2.5.

class rfc2217.PortManagerThis class provides helper functions for implementing RFC 2217 compatible servers.

Basically, it implements every thing needed for the RFC 2217 protocol. It just does not open sockets andread/write to serial ports (though it changes other port settings). The user of this class must take care of the datatransmission itself. The reason for that is, that this way, this class supports all programming models such asthreads and select.

Usage examples can be found in the examples where two TCP/IP - serial converters are shown, one using threads(the single port server) and an other using select (the multi port server).

Note: Each new client connection must create a new instance as this object (and the RFC 2217 protocol) hasinternal state.

__init__(serial_port, connection, debug_output=False)

Parameters

• serial_port – a Serial instance that is managed.

• connection – an object implementing write(), used to write to the network.

• debug_output – enables debug messages: a logging.Logger instance or None.

Initializes the Manager and starts negotiating with client in Telnet and RFC 2217 protocol. The negotiationstarts immediately so that the class should be instantiated in the moment the client connects.

The serial_port can be controlled by RFC 2217 commands. This object will modify the port settings (baudrate etc.) and control lines (RTS/DTR) send BREAK etc. when the corresponding commands are foundby the filter() method.

The connection object must implement a write(data)() function. This function must ensure that datais written at once (no user data mixed in, i.e. it must be thread-safe). All data must be sent in its raw form(escape() must not be used) as it is used to send Telnet and RFC 2217 control commands.

For diagnostics of the connection or the implementation, debug_output can be set to an instance of alogging.Logger (e.g. logging.getLogger(’rfc2217.server’)). The caller should con-figure the logger using setLevel for the desired detail level of the logs.

escape(data)

Parameters data – data to be sent over the network.

Returns data, escaped for Telnet/RFC 2217

A generator that escapes all data to be compatible with RFC 2217. Implementors of servers should usethis function to process all data sent over the network.

The function returns a generator which can be used in for loops. It can be converted to bytes usingserial.to_bytes().

filter(data)

Parameters data – data read from the network, including Telnet and RFC 2217 controls.

Returns data, free from Telnet and RFC 2217 controls.

22 Chapter 4. pySerial API

Page 27: Py Serial

pySerial Documentation, Release 2.6

A generator that filters and processes all data related to RFC 2217. Implementors of servers should usethis function to process all data received from the network.

The function returns a generator which can be used in for loops. It can be converted to bytes usingserial.to_bytes().

check_modem_lines(force_notification=False)

Parameters force_notification – Set to false. Parameter is for internal use.

This function needs to be called periodically (e.g. every second) when the server wants to send NO-TIFY_MODEMSTATE messages. This is required to support the client for reading CTS/DSR/RI/CDstatus lines.

The function reads the status line and issues the notifications automatically.

New in version 2.5.

See Also:

RFC 2217 - Telnet Com Port Control Option

4.2 Exceptions

exception serial.SerialExceptionBase class for serial port exceptions. Changed in version 2.5: Now derrives from IOError instead ofException

exception serial.SerialTimeoutExceptionException that is raised on write timeouts.

4.3 Constants

Parity

serial.PARITY_NONE

serial.PARITY_EVEN

serial.PARITY_ODD

serial.PARITY_MARK

serial.PARITY_SPACE

Stop bits

serial.STOPBITS_ONE

serial.STOPBITS_ONE_POINT_FIVE

serial.STOPBITS_TWO

Note that 1.5 stop bits are not supported on POSIX. It will fall back to 2 stop bits.

Byte size

serial.FIVEBITS

serial.SIXBITS

serial.SEVENBITS

4.2. Exceptions 23

Page 28: Py Serial

pySerial Documentation, Release 2.6

serial.EIGHTBITS

Others

Default control characters (instances of bytes for Python 3.0+) for software flow control:

serial.XON

serial.XOFF

Module version:

serial.VERSIONA string indicating the pySerial version, such as 2.5. New in version 2.3.

4.4 Module functions and attributes

serial.device(number)

Parameters number – Port number.

Returns String containing device name.

Deprecated Use device names directly.

Convert a port number to a platform dependent device name. Unfortunately this does not work well for allplatforms; e.g. some may miss USB-Serial converters and enumerate only internal serial ports.

The conversion may be made off-line, that is, there is no guarantee that the returned device name really existson the system.

serial.serial_for_url(url, *args, **kwargs)

Parameters

• url – Device name, number or URL

• do_not_open – When set to true, the serial port is not opened.

Returns an instance of Serial or a compatible object.

Get a native or a RFC 2217 implementation of the Serial class, depending on port/url. This factory function isuseful when an application wants to support both, local ports and remote ports. There is also support for othertypes, see URL section below.

The port is not opened when a keyword parameter called do_not_open is given and true, by default it is opened.New in version 2.5.

serial.protocol_handler_packagesThis attribute is a list of package names (strings) that is searched for protocol handlers.

e.g. we want to support a URL foobar://. A module my_handlers.protocol_foobar is providedby the user:

serial.protocol_handler_packages.append("my_handlers")s = serial.serial_for_url("foobar://")

For an URL starting with XY:// is the function serial_for_url() attempts to importPACKAGE.protocol_XY with each candidate for PACKAGE from this list. New in version 2.6.

serial.to_bytes(sequence)

Parameters sequence – String or list of integers

24 Chapter 4. pySerial API

Page 29: Py Serial

pySerial Documentation, Release 2.6

Returns an instance of bytes

Convert a sequence to a bytes type. This is used to write code that is compatible to Python 2.x and 3.x.

In Python versions prior 3.x, bytes is a subclass of str. They convert str([17]) to ’[17]’ instead of’\x11’ so a simple bytes(sequence) doesn’t work for all versions of Python.

This function is used internally and in the unit tests. New in version 2.5.

4.4.1 URLs

The function serial_for_url() accepts the following types of URLs:

• rfc2217://<host>:<port>[/<option>[/<option>]]

• socket://<host>:<port>[/<option>[/<option>]]

• loop://[<option>[/<option>]]

Device names are also supported, e.g.:

• /dev/ttyUSB0 (Linux)

• COM3 (Windows)

Future releases of pySerial might add more types. Since pySerial 2.6 it is also possible for the user to add protocolhandlers using protocol_handler_packages.

rfc2217:// Used to connect to RFC 2217 compatible servers. All serial port functions are supported. Imple-mented by rfc2217.Serial.

Supported options in the URL are:

• ign_set_control does not wait for acknowledges to SET_CONTROL. This option can beused for non compliant servers (i.e. when getting an remote rejected value for option’control’ error when connecting).

• poll_modem: The client issues NOTIFY_MODEMSTATE requests when status lines are read(CTS/DTR/RI/CD). Without this option it relies on the server sending the notifications automatically(that’s what the RFC suggests and most servers do). Enable this option when getCTS() does not workas expected, i.e. for servers that do not send notifications.

• timeout=<value>: Change network timeout (default 3 seconds). This is useful when the server takesa little more time to send its answers. The timeout applies to the initial Telnet / RFC 2271 negotiation aswell as changing port settings or control line change commands.

• logging=[debug|info|warning|error]: Prints diagnostic messages (not useful for end users).It uses the logging module and a logger called pySerial.rfc2217 so that the application can setupup logging handlers etc. It will call logging.basicConfig() which initializes for output onsys.stderr (if no logging was set up already).

socket:// The purpose of this connection type is that applications using pySerial can connect to TCP/IP to serialport converters that do not support RFC 2217.

Uses a TCP/IP socket. All serial port settings, control and status lines are ignored. Only data is transmitted andreceived.

Supported options in the URL are:

• logging=[debug|info|warning|error]: Prints diagnostic messages (not useful for end users).It uses the logging module and a logger called pySerial.socket so that the application can setupup logging handlers etc. It will call logging.basicConfig() which initializes for output onsys.stderr (if no logging was set up already).

4.4. Module functions and attributes 25

Page 30: Py Serial

pySerial Documentation, Release 2.6

loop:// The least useful type. It simulates a loop back connection (RX<->TX RTS<->CTS DTR<->DSR). Itcould be used to test applications or run the unit tests.

Supported options in the URL are:

• logging=[debug|info|warning|error]: Prints diagnostic messages (not useful for end users).It uses the logging module and a logger called pySerial.loop so that the application can setup up log-ging handlers etc. It will call logging.basicConfig()which initializes for output on sys.stderr(if no logging was set up already).

Examples:

• rfc2217://localhost:7000

• rfc2217://localhost:7000/poll_modem

• rfc2217://localhost:7000/ign_set_control/timeout=5.5

• socket://localhost:7777

• loop://logging=debug

4.5 Tools

4.5.1 serial.tools.list_ports

New in version 2.6. This module can be executed to get a list of ports (python -mserial.tools.list_ports). It also contains the following functions.

serial.tools.list_ports.comports()

Returns an iterable.

The function returns an iterable that yields tuples of three strings:

•port name as it can be passed to serial.Serial or serial.serial_for_url()

•description in human readable form

•sort of hardware ID. E.g. may contain VID:PID of USB-serial adapters.

Items are returned in no particular order. It may make sense to sort the items. Also note that the reported stringsare different across platforms and operating systems, even for the same device.

Note: Support is limited to a number of operating systems. On some systems description and hardware ID willnot be available (None).

Platform Posix (/dev files)

Platform Linux (/dev files, sysfs and lsusb)

Platform Windows (setupapi, registry)

serial.tools.list_ports.grep(regexp)

Parameters regexp – regular expression (see stdlib re)

Returns filtered sequence, see comports().

26 Chapter 4. pySerial API

Page 31: Py Serial

pySerial Documentation, Release 2.6

Search for ports using a regular expression. Port name, description and hardware ID are searched (case insensi-tive). The function returns an iterable that contains the same tuples that comport() generates but only thosethat match the regexp.

4.5.2 serial.tools.miniterm

New in version 2.6. Miniterm is now available as module instead of example. see Miniterm for details.

4.5. Tools 27

Page 32: Py Serial

pySerial Documentation, Release 2.6

28 Chapter 4. pySerial API

Page 33: Py Serial

CHAPTER

FIVE

PYPARALLEL

Note: This module is in development (since years ;-)

5.1 Overview

This module encapsulates the access for the parallel port. It provides backends for Python running on Windows andLinux. Other platforms are possible too but not yet integrated.

This module is still under development. But it may be useful for developers.

Copyright (C) 2001-2003 Chris Liechti <cliechti(at)gmx.net>

Here is the project page on SourceForge and here is the SVN repository.

5.1.1 Features

• same class based interface on all supported platforms

• port numbering starts at zero, no need to know the port name in the user program

• port string (device name) can be specified if access through numbering is inappropriate

5.1.2 Requirements

• Python 2.2 or newer

• “Java Communications” (JavaComm) extension for Java/Jython

5.1.3 Installation

Extract files from the archive, open a shell/console in that directory and let Distutils do the rest: python setup.pyinstall

The files get installed in the “Lib/site-packages” directory in newer Python versions.

The windows version needs a compiled extension and the giveio.sys driver for Windows NT/2k/XP. The extensionmodule can be compiled with Distutils with either MSVC or GCC/mingw32.

It is released under a free software license, see LICENSE.txt for more details.

29

Page 34: Py Serial

pySerial Documentation, Release 2.6

5.2 Short introduction

>>> import parallel>>> p = parallel.Parallel() # open LPT1>>> p.setData(0x55)

5.2.1 Examples

Please look in the SVN Repository. There is an example directory where you can find a simple terminal and more.http://pyserial.svn.sourceforge.net/viewvc/pyserial/trunk/pyparallel/examples/

5.3 API

class parallel.Parallel

__init__(port)Open given parallel port.

setData(value)Apply the given byte to the data pins of the parallel port.

setDataStrobe(level)Set the “data strobe” line to the given state.

setAutoFeed(level)Set “auto feed” line to given state.

setInitOut(level)Set “initialize” line to given state.

getInSelected()Read level of “select” line.

getInPaperOut()Read level of “paper out” line.

getInAcknowledge()Read level of “Acknowledge” line.

class parallel.parallelutil.BitaccessMetaThis mix-in class adds a few properties that allow easier bit access to the data lines. (D0 .. D7) e.g. p.D0 refersto the first bit of the data lines.

class parallel.parallelutil.VirtualParallelPortThis class provides a virtual parallel port implementation, useful for tests and simulations without real hardware.

5.4 Notes

5.4.1 Linux

1. The lp(4) module must be unloaded, rmmod lp. lp claims exclusive access to the port and other programswon’t be able to use it.

30 Chapter 5. pyParallel

Page 35: Py Serial

pySerial Documentation, Release 2.6

2. The ppdev(4) module needs to be loaded, modprobe ppdev. When udev is in use, (default with 2.6kernels) this will create a /dev/parport0.

3. The user needs to have write permissions to /dev/parport0. Many distributions have an lp group that ownsthe device; the simplest is to add the user account to this group. Simply changing permissions on the device isnot the best strategy as they will be reverted to their defaults next time the driver is loaded.

5.4.2 Windows

The giveio driver must be installed as the module needs direct access to the hardware. This also means that USBparallel port adapters won’t be supported.

5.5 Misc

5.5.1 References

• Python: http://www.python.org/

• Jython: http://www.jython.org/

• Java@IBM: http://www-106.ibm.com/developerworks/java/jdk/ (JavaComm links are on the download page forthe respective platform JDK)

• Java@SUN: http://java.sun.com/products/

5.5. Misc 31

Page 36: Py Serial

pySerial Documentation, Release 2.6

32 Chapter 5. pyParallel

Page 37: Py Serial

CHAPTER

SIX

APPENDIX

6.1 How To

Enable RFC 2217 in programs using pySerial. Patch the code where the serial.Serial is instantiated. Re-place it with:

try:s = serial.serial_for_url(...)

except AttributeError:s = serial.Serial(...)

Assuming the application already stores port names as strings that’s all that is required. The user just needs away to change the port setting of your application to an rfc2217:// URL (e.g. by editing a configuration file,GUI dialog etc.).

Please note that this enables all URL types supported by pySerial and that those involving the network areunencrypted and not protected against eavesdropping.

Test your setup. Is the device not working as expected? Maybe it’s time to check the connection before proceeding.Miniterm from the Examples can be used to open the serial port and do some basic tests.

To test cables, connecting RX to TX (loop back) and typing some characters in Miniterm is a simple test. Whenthe characters are displayed on the screen, then at least RX and TX work (they still could be swapped though).

6.2 FAQ

Example works in Miniterm but not in script. The RTS and DTR lines are switched when the port is opened. Thismay cause some processing or reset on the connected device. In such a cases an immediately following call towrite() may not be received by the device.

A delay after opening the port, before the first write(), is recommended in this situation. E.g. atime.sleep(1)

Application works when .py file is run, but fails when packaged (py2exe etc.) py2exe and similar packaging pro-grams scan the sources for import statements and create a list of modules that they package. pySerial may createtwo issues with that:

• implementations for other modules are found. On Windows, it’s safe to exclude ‘serialposix’, ‘serialjava’and ‘serialcli’ as these are not used.

• serial.serial_for_url() does a dynamic lookup of protocol handlers at runtime. If this functionis used, the desired handlers have to be included manually (e.g. ‘serial.urlhandler.protocol_socket’, ‘se-

33

Page 38: Py Serial

pySerial Documentation, Release 2.6

rial.urlhandler.protocol_rfc2217’, etc.). This can be done either with the “includes” option in setup.pyor by a dummy import in one of the packaged modules.

User supplied URL handlers serial.serial_for_url() can be used to access “virtual” serial ports identi-fied by an URL scheme. E.g. for the RFC 2217: rfc2217:://.

Custom URL handlers can be added by extending the module search path inserial.protocol_handler_packages. This is possible starting from pySerial V2.6.

6.3 Related software

com0com - http://com0com.sourceforge.net/ Provides virtual serial ports for Windows.

6.4 License

Copyright (C) 2001-2011 Chris Liechti <cliechti(at)gmx.net>; All Rights Reserved.

This is the Python license. In short, you can use this product in commercial and non-commercial applications, modifyit, redistribute it. A notification to the author when you use and/or modify it is welcome.

TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING THIS SOFTWARE

LICENSE AGREEMENT

1. This LICENSE AGREEMENT is between the copyright holder of this product, and the Individual or Orga-nization (“Licensee”) accessing and otherwise using this product in source or binary form and its associateddocumentation.

2. Subject to the terms and conditions of this License Agreement, the copyright holder hereby grants Licenseea nonexclusive, royalty-free, world-wide license to reproduce, analyze, test, perform and/or display publicly,prepare derivative works, distribute, and otherwise use this product alone or in any derivative version, provided,however, that copyright holders License Agreement and copyright holders notice of copyright are retained inthis product alone or in any derivative version prepared by Licensee.

3. In the event Licensee prepares a derivative work that is based on or incorporates this product or any part thereof,and wants to make the derivative work available to others as provided herein, then Licensee hereby agrees toinclude in any such work a brief summary of the changes made to this product.

4. The copyright holder is making this product available to Licensee on an “AS IS” basis. THE COPYRIGHTHOLDER MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OFEXAMPLE, BUT NOT LIMITATION, THE COPYRIGHT HOLDER MAKES NO AND DISCLAIMS ANYREPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULARPURPOSE OR THAT THE USE OF THIS PRODUCT WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.

5. THE COPYRIGHT HOLDER SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THISPRODUCT FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RE-SULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING THIS PRODUCT, OR ANY DERIVA-TIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.

6. This License Agreement will automatically terminate upon a material breach of its terms and conditions.

7. Nothing in this License Agreement shall be deemed to create any relationship of agency, partnership, or jointventure between the copyright holder and Licensee. This License Agreement does not grant permission to usetrademarks or trade names from the copyright holder in a trademark sense to endorse or promote products orservices of Licensee, or any third party.

34 Chapter 6. Appendix

Page 39: Py Serial

pySerial Documentation, Release 2.6

8. By copying, installing or otherwise using this product, Licensee agrees to be bound by the terms and conditionsof this License Agreement.

6.4. License 35

Page 40: Py Serial

pySerial Documentation, Release 2.6

36 Chapter 6. Appendix

Page 41: Py Serial

CHAPTER

SEVEN

INDICES AND TABLES

• genindex

• modindex

• search

37

Page 42: Py Serial

pySerial Documentation, Release 2.6

38 Chapter 7. Indices and tables

Page 43: Py Serial

PYTHON MODULE INDEX

pparallel, 30parallel.parallelutil, 30

sserial, 15serial.tools.list_ports, 26serial.tools.miniterm, 27

39

Page 44: Py Serial

pySerial Documentation, Release 2.6

40 Python Module Index

Page 45: Py Serial

INDEX

Symbols__del__() (serial.Serial method), 16__init__() (parallel.Parallel method), 30__init__() (serial.Serial method), 15__init__() (serial.rfc2217.PortManager method), 22__iter__() (serial.FileLike method), 20

AapplySettingsDict() (serial.Serial method), 19

Bbaudrate (serial.Serial attribute), 18BAUDRATES (serial.Serial attribute), 18BitaccessMeta (class in parallel.parallelutil), 30bytesize (serial.Serial attribute), 18BYTESIZES (serial.Serial attribute), 18

Ccheck_modem_lines() (serial.rfc2217.PortManager

method), 23close() (serial.Serial method), 16comports() (in module serial.tools.list_ports), 26

Ddevice() (in module serial), 24dsrdtr (serial.Serial attribute), 18

EEIGHTBITS (in module serial), 23escape() (serial.rfc2217.PortManager method), 22

FFileLike (class in serial), 19fileno() (serial.Serial method), 19filter() (serial.rfc2217.PortManager method), 22FIVEBITS (in module serial), 23flush() (serial.FileLike method), 20flush() (serial.Serial method), 17flushInput() (serial.Serial method), 17flushOutput() (serial.Serial method), 17

GgetCD() (serial.Serial method), 17getCTS() (serial.Serial method), 17getDSR() (serial.Serial method), 17getInAcknowledge() (parallel.Parallel method), 30getInPaperOut() (parallel.Parallel method), 30getInSelected() (parallel.Parallel method), 30getRI() (serial.Serial method), 17getSettingsDict() (serial.Serial method), 19grep() (in module serial.tools.list_ports), 26

IinterCharTimeout (serial.Serial attribute), 18inWaiting() (serial.Serial method), 16isatty() (serial.FileLike method), 20

Nname (serial.Serial attribute), 17next() (serial.FileLike method), 20nonblocking() (serial.Serial method), 19

Oopen() (serial.Serial method), 16

PParallel (class in parallel), 30parallel (module), 30parallel.parallelutil (module), 30PARITIES (serial.Serial attribute), 18parity (serial.Serial attribute), 18PARITY_EVEN (in module serial), 23PARITY_MARK (in module serial), 23PARITY_NONE (in module serial), 23PARITY_ODD (in module serial), 23PARITY_SPACE (in module serial), 23port (serial.Serial attribute), 18portstr (serial.Serial attribute), 17protocol_handler_packages (in module serial), 24

Rread() (serial.FileLike method), 20

41

Page 46: Py Serial

pySerial Documentation, Release 2.6

read() (serial.Serial method), 16readable() (serial.Serial method), 18readinto() (serial.Serial method), 19readline() (serial.FileLike method), 20readlines() (serial.FileLike method), 21RFC

RFC 2217, 9, 11, 12, 21–25, 33, 34RFC 2271, 25

rfc2217.PortManager (class in serial), 22rfc2217.Serial (class in serial), 21rtscts (serial.Serial attribute), 18

Sseek() (serial.FileLike method), 20seekable() (serial.Serial method), 18sendBreak() (serial.Serial method), 17Serial (class in serial), 15serial (module), 15serial.tools.list_ports (module), 26serial.tools.miniterm (module), 27serial_for_url() (in module serial), 24SerialException, 23SerialTimeoutException, 23setAutoFeed() (parallel.Parallel method), 30setBreak() (serial.Serial method), 17setData() (parallel.Parallel method), 30setDataStrobe() (parallel.Parallel method), 30setDTR() (serial.Serial method), 17setInitOut() (parallel.Parallel method), 30setRTS() (serial.Serial method), 17setXON() (serial.Serial method), 19SEVENBITS (in module serial), 23SIXBITS (in module serial), 23STOPBITS (serial.Serial attribute), 18stopbits (serial.Serial attribute), 18STOPBITS_ONE (in module serial), 23STOPBITS_ONE_POINT_FIVE (in module serial), 23STOPBITS_TWO (in module serial), 23

Ttell() (serial.FileLike method), 20timeout (serial.Serial attribute), 18to_bytes() (in module serial), 24truncate() (serial.FileLike method), 20

VVERSION (in module serial), 24VirtualParallelPort (class in parallel.parallelutil), 30

Wwritable() (serial.Serial method), 18write() (serial.FileLike method), 20write() (serial.Serial method), 16

writelines() (serial.FileLike method), 20writeTimeout (serial.Serial attribute), 18

XXOFF (in module serial), 24XON (in module serial), 24xonxoff (serial.Serial attribute), 18xreadlines() (serial.FileLike method), 21

42 Index