PySerial rereads its own data

Cliff Wells LogiplexSoftware at earthlink.net
Mon Jun 2 18:14:19 EDT 2003


I'm trying to write an app that talks to a bit of hardware on the serial
port.  As a test setup, I've got a null modem cable linking /dev/ttyS0
and /dev/ttyS1 on the same PC.

I start 'cat /dev/ttyS1' in a terminal and in another I run the
following:

Python 2.2.1 (#1, Aug 30 2002, 12:15:30) 
[GCC 3.2 20020822 (Red Hat Linux Rawhide 3.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> s = serial.Serial(0)
>>> s.write("hello\n")
>>> s.close()
>>> s = serial.Serial(0)
>>> s.write("hello\n")
>>> s.read()
'h'
>>> s.read()
'e'
>>> s.read()
'l'
>>> s.read()
'l'
>>> s.read()
'o'
>>> s.read()
'\r'
>>> s.read()
'\n'
>>> s.read() # this blocks as there is no more data

'hello' correctly appears on the console running 'cat /dev/ttyS1'.

My question is this:  why do I get back the data I just wrote?  More to
the point, how do I stop it?


Regards,

-- 
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726  (800) 735-0555






More information about the Python-list mailing list