How to find EOL (end of line) in a byte-stream from a serial device
<p>I try to read lines from a device that sends every 2 seconds 1 to 3 lines of text to a serial printer, using pyserial to read the serial output of that device.</p>

<p>First, I have used minicom to get an output-sample: When I open it with a hax-reader (ghex in linux), I see that every end of line has the hex-value x0A.</p>

<p>When I capture the output with pyserial (version 3.2.1) byte by byte:</p>

<pre><code>print(self.ser.read())
</code></pre>

<p>the output at the end of a line is </p>

<p>b'\r'</p>

<p>b'\n'</p>

<p>every time a line ends (why two characters?)</p>

<p>I have tried to define a read_line() function:</p>

<pre><code>import serial  

def read_line(self):
        line = []
        print("start read_line")
        while True:
            print("read_line_loop")
            for c in self.ser.read():
                line.append(c)
                print("appended")
                if c == b'\x0A':
                    print("stop condition")
                    print("Line: " + line)
                    line = []
                    break
</code></pre>

<p>The loop is enterd as expected, but the condition c == b'\x0A' is never met.
The messages shown are "read_line_loop", and every to seconds several times
"appended", but never "stop condition".</p>

<p>Any idea?</p>