Dear Mr. Liechti,
I have controllers that use CR as EOL character.
1. I have tried to change the EOL character for readline using io.TextIOWrapper, but readline waits until it times out instead of returning on CR. Follows a (working) snippet of what I have tried.
2. expected behavior: readline returns immediately
import serial
import io
socket = serial.Serial("/dev/tty.PL2303-0000101D")
socket.timeout = 3.0
sio = io.TextIOWrapper(
io.BufferedRWPair(socket, socket),
encoding="ascii", errors="strict",
newline="\r")
sio.write(u"? SP1\r")
print socket.inWaiting()
# 5: there are things in the pipe
ans = sio.readline() # waits timeout, exactly 3.00 s
print len(ans)
# 5: everything was in the pipe before sio.readline()
print [ord(c) for c in ans]
# [19, 17, 49, 50, 13]
print ans[-1] == "\r"
# True
I am having exactly this problem. Because I need to use the io module to set EOL to '\r' because that's what the device sends. But every readline has to time out.
It appears that io.TextIOWrapper isn't working correctly. Can you please restore the EOL functionality in psSerial?
The highest-rated answer to this seemed to work for me. Basically, you set the buffer size -