pyserial problem: script stops reading
Frederic Wenzel
fred at osuosl.org
Fri Sep 8 21:24:48 EDT 2006
I wrote a script on Linux that uses pyserial to read status messages
from a serial line using readlines(). For now, it just displays what
it gets on stdout:
17:42 | 0005 | 02 | | 5 |Rack Abs.| - | --210
17:42 | 0008 | 02 | | 5 |Rack Abs.| - | --210
17:42 | 0001 | 02 | | 5 |Rack Abs.| - | --210
17:43 | 0008 | 02 | | 5 |Rack Abs.| - | --210
17:43 | 0001 | 02 | | 5 |Rack Abs.| - | --210
17:43 | 0005 | 02 | | 5 |Rack Abs.| - | --210
17
After a few hours, or sometimes days, of listening, the script stops
in the middle of the line and does not display any further output (as
you can see with the "17" in the last line above). That happens, even
though I set a timeout of 10s when opening the line, and on timeout it
displays the lines and reopens the port:
ser = serial.Serial(port=1,
baudrate=1200,
rtscts=1,
timeout=10)
while 1:
lines = sh.readLines()
for line in lines:
print line
ser.close()
ser.open()
If the script does not time out there, I am not sure what else it is
doing. It seems to be in a wait state it does not get out of.
So even if the line received turned out to have some sort of error, I
think it should time out after a while? Maybe there is some sort of
buffer overrunning (even though the traffic is quite low: a line every
few minutes on average)?
Does anyone see any obvious error? Any hint how I can further debug the problem?
Thanks
Fred
More information about the Python-list
mailing list