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
- same class based interface on all supported platforms
- access to the port settings through Python 2.2+ properties
- 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
- support for different bytesizes, stopbits, 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. They depend on non standard but common packages on Windows (pywin32) and Jython (JavaComm). POSIX (Linux, BSD) uses only modules from the standard Python distribution)
- The port is set up for binary transmission. No NULL byte stripping, CR-LF translation etc. (which are many times enabled for POSIX.) This makes this module universally useful.
- Python 2.2 or newer
- pywin32 extensions on Windows
- “Java Communications” (JavaComm) or compatible extension for Java/Jython
Extract files from the archive, open a shell/console in that directory and let Distutils do the rest:
python setup.py install
The files get installed in the “Lib/site-packages” directory.
An EGG is available from the Python Package Index: http://pypi.python.org/pypi/pyserial
There is also a Windows installer for end users. It is located in the Download Page
Developers may be interested to get the source archive, because it contains examples and the readme.
Open port 0 at “9600,8,N,1”, no timeout
Open named port at “19200,8,N,1”, 1s timeout
Open second port at “38400,8,E,1”, non blocking HW handshaking
Get a Serial instance and configure/open it later
Be carefully when using “readline”. Do specify a timeout when opening the serial port otherwise it could block forever 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 opened correctly.
Do also have a look at the example files in the examples directory in the source distribution or online.
Please look in the SVN Repository. There is an example directory where you can find a simple terminal and more.
##Parameters for the Serial class
The port is immediately opened on object creation, if a port is given. It is not opened if port is None.
Options for read timeout:
##Methods of Serial instances
##Attributes of Serial instances
New values can be assigned to the following attributes, the port will be reconfigured, even if it’s opened at that time: