pyserial problem: script stops reading

Hendrik van Rooyen mail at microcorp.co.za
Sat Sep 9 04:26:07 EDT 2006


"Frederic Wenzel" <freeed at gmail.com> wrote:


| 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,

if this is enabling hardware flow control  try turning it off - at 1200 baud you
should not need it


|                                  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.

Sounds more and more like flow control hassle - can you lay your hands on a
break out box or a datascope?


|
| 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


- HTH Hendrik





More information about the Python-list mailing list