Is it possible to use python to get True Full Duplex on a Serial port?

greg greg at
Fri Aug 14 14:13:46 CEST 2009

Hendrik van Rooyen wrote:

> port = open("/dev/ttyS0","r+b",0)
> What I would really like is to have two threads - one that does blocking input 
> waiting for a character, and one that examines an output queue and transmits 
> the stuff it finds.

You can't read and write with the same stdio file object
at the same time. Odd things tend to happen if you try.

You need to open *two* file objects, one for reading
and one for writing:

   fr = open("/dev/ttyS0","rb",0)
   fw = open("/dev/ttyS0","wb",0)

and give fr to the reading thread and fw to the
writing thread.

You could also try avoiding file objects altogether
and use the raw system calls in the os module. Since
you're not using any buffering, there's little reason
to use the stdio layer. If you do that, you should be
able to use the same file descriptor for reading and
writing without any trouble.


More information about the Python-list mailing list