I am using python 2.7.2 with pyserial 2.6.
What is the best way to use pyserial.readline() when talking to a device that has a character other than “\n” for eol? The pyserial doc points out that pyserial.readline() no longer takes an ‘eol=’ argument in python 2.6+, but recommends using io.TextIOWrapper as follows:
ser = serial.serial_for_url(‘loop://’, timeout=1)
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
However the python io.BufferedRWPair doc specifically warns against that approach, saying “BufferedRWPair does not attempt to synchronize accesses to its underlying raw streams. You should not pass it the same object as reader and writer; use BufferedRandom instead.”
Could someone point to a working example of pyserial.readline() working with an eol other than ‘eol’?
Thanks,
Tom
read() has a user-settable maximum size to the data it reads(in bits), if your data strings are a predictable length you could simply set that to capture a fixed-length string. it’s sort of ‘kentucky windage’ in execution but so long as your data strings are consistent in size it won’t bork.
beyond that, your real option is to capture and write the data stream to another file and split out your entries manually/programatically.
for example, you could write your datastream to a .csv file, and adjust the delimiter variable to be your EoL character.