USPP
|
Universal Serial Port Python Library
Copyright
2001 Isaac Barona
ibarona@tid.es
|
|
Contents |
-
Introduction
-
Motivation
-
Features
-
Prerequisites
-
Usage and documentation
-
Where does it works
-
Porting to other platforms
-
License
-
Author
-
Versions
|
|
Introduction |
USPP Library is a multi-platform Python module to access serial ports.
At the moment, it only works in Windows and Linux (the platforms I have
access to) but as it is written entirely in Python (doesn't wrap any C/C++
library) I hope you can extend it to support any other platforms.
|
|
Motivation |
I like very much to make electronic widgets with microcontrollers, specially
those that can be connected to the computer to send and receive data.
Some months ago, I discovered Python and inmediatelly liked it a lot.
I started playing with it and saw that I could use it to make prototypes of
comunication protocols between computer and microcontrollers really
fast and easily than using C. At the same time, I was interested in
working over different platforms.
I started looking for Python modules to access serial port and I found
the following projects:
- win32comport_demo from the win32 extension module
- win32comm module of wheineman@uconect.net
- Sio Module of Roger Rurnham (rburnham@cri-inc.com)
- pyxal (Python X10 Abstraction Layer) of Les Smithson (lsmithson@open-networks.co.uk)
but they were not multi-platform, were just a wrap of propietary libraries or
were just simple examples of serial port access.
For these reasons and also for learning more Python, I decided to start
this project. Of course, I have used all this projects as reference to
my module and so, I want to thanks the authors for their excellent work and
for allowing us to study the code.
I hope you enjoy using the uspp module as much as I am enjoying doing it.
|
|
Features |
This module has the following features:
- hight level access to serial port under several platforms.
- autodetects the platform in which it is working and exports the correct
classes for that platform.
- object oriented approach.
- file object semantic operations over the ports.
- allows using the serial port with different speeds and
characteristics.
- RS-232 and RS-485 modes (now only RS-232). In RS-485 mode the communication
is half-duplex and uses the RTS line to control the direction of the
transference.
- blocking, non-blocking or configurable timeout reads.
|
|
Prerequisites |
You need the following to use the library:
- Python 1.5.2 or better
- In windows you need the win32 extension modules
|
|
Usage and documentation |
You only have to import in your program the uspp module and automatically
it loads the correct classes for the platform in which you are running
the program.
First of all you have to create a SerialPort object with the settings you
want. If a SerialPortException is not generated then you just can
use the read and write methods of the object to read and write to
the serial port.
Example:
>>> from uspp import *
>>> tty=SerialPort("COM2", 1000, 9600)
>>> # Opens COM2 at 9600 bps and with a read timeout of 1 second.
>>> tty.write("a") # Writes a character to the COM2 port
>>> # Now suppose we receive the string "abc"
>>> tty.inWaiting()
3
>>> tty.read()
'a'
>>> tty.inWaiting()
2
>>> tty.read(2)
'bc'
Documentation of the different classes and methods can be found on
uspp module docstring.
|
|
Where does it works |
The library has been tested in a Windows 95 machine with Python 2.0
and in a Linux (2.0.34 kernel) machine with Python 1.5.2 and
Python 2.0.1.
|
|
Porting to other
platforms |
If you want to port the library to other platforms you only have to follow
these steps:
- Create a new python file called SerialPort_XXXX.py in which you
implement the same public classes and methods found in the
SerialPort_win
and SerialPort_linux modules.
- Append the new platform to the uspp.py file.
|
|
License |
This code is released under the "GPL" that can be found in
http://www.gnu.org/copyleft/gpl.html or in the GPL.txt file that
is with the library.
If you use this software, I'd like to know about it.
|
|
Author |
This library has been created by Isaac Barona Martínez
(ibarona@tid.es)
|
|
Versions |
-
Version 0.1 - 09/01/2001 (September 2001)
Files:
Known problems
In Linux, I get the following error when the inWaiting method is called:
>>> tty.inWaiting()
Traceback (most recent call last):
File "", line 1, in ?
File "SerialPort_linux.py", line 179, in inWaiting
n=fcntl.ioctl(self.__handle, TERMIOS.TIOCINQ)
IOError: [Errno 14] Bad address
I have used this ioctl call in previous C programs and it has worked ok.
Please, help!!!!!
If you like to submit a bug report, or a feature request, send me
a mail to ibarona@tid.es.
To-do list
This is the to-do list:
- correct the error in the linux version of the inWaiting method.
- implement RS-485 mode.
- port the library to other platforms so that it can be really
multi-platform.
|
|
Copyright 2001 Isaac Barona |