I have a serial device that I\'m trying to read input from. I sent it a string \"ID\\r\", and it returns \"ID XX\\r\" (where \\r is an ASCII carriage return, hex 0x0d).
Thanks for the code Keith, but I wanted to keep this code somewhat portable, so I'd like to stick with the default "serial" package.
Plus, since I'm still learning Python, I wanted to try to learn how to use the TextIOWrapper in the way it was intended.
I gave up trying to make serial.readline() work, so for now I'll just use a simple "readLine" function to read a character at a time and look for a carriage return terminator. Though if I run into more serial quirkyness, I may revisit using your code.
Thanks!
def readLine(ser):
str = ""
while 1:
ch = ser.read()
if(ch == '\r' or ch == ''):
break
str += ch
#"print "str = " + str
return str