[Tutor] Parsing control characters from serial port

kromag@nsacom.net kromag@nsacom.net
Wed, 25 Apr 2001 13:42:39 -0700 (PDT)


I have had some success with grabbing strings from '/dev/ttyS0' by using 
readline(). It works just like I would expect, i.e. it stops 'listening' when 
a 'n' is detected. 

How can I tell readline() to complete a line when another character is 
detected? (I am listening for '0x02' FWIW)

Basically the device on the other end of the serial port talks like this:

0x02    #Listen up! I have news for you!
(string of characters)
0x03    #I'm Done!

Since readline() opens the serial port and listens intently without need for a 
 wake-up call, it won't be any big deal to strip the initial '0x02' off, but 
ending the message on '0x03' is confusing me. Do I need to somehow tell 
readlines() 'n'?

is there a way to tell python that for the purposes of this function '0x03' == 
'n'?

I have tried to come up with some sort of garble that does

while string contents != 0x03
read it all in and put it here
else n

(Sorry, I am not at my home machine and lunch is short!)

I hope this is clear enough!

Thanks,

Douglas