I'm trying to set the newline character for SiRF binary messages, but the IO wrapper doesn't seem to accept the newline chars.
Code:
import serial
import io
port = serial.Serial(port='/dev/ttyUSB0', baudrate=4800, timeout=2)
sio = io.TextIOWrapper(io.BufferedRWPair(port, port), newline='\xb0\xb3')
Output:
>>> sio = io.TextIOWrapper(io.BufferedRWPair(port, port, 1), newline='\xb3')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: illegal newline value: �
>>>
Note: It does accept '\x0d'
You can not just use any character as the newline. From the io.TextIOWrapper() documentation:
newline controls how line endings are handled. It can be
None,'','\n','\r', and'\r\n'.
You'll have to handle those bytes manually instead of a newline, directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With