Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1251

Python • Re: Python serial programing

$
0
0
serial readline is tricky. When CRLF is not in the data, then getline is waiting till something arrives which terminates reading by a CRLF.
Which in your case is the next message, possibly.

Code:

 # Read the next PDU line                        pdu_line = ser.readline().decode('latin-1').strip()                        data = ser.readline()  # Replace this here by a loop reading only one byte after the other ser.read(1)                                                               # and check for ctrl-Z. Then go ahead with next commands using readline                        print(data.decode('latin-1').strip())                        # Check if it's the end (Ctrl+Z) - ASCII code 26                        if pdu_line == chr(26):                            break  # End PDU data reception

Statistics: Posted by ghp — Thu Nov 07, 2024 6:38 pm



Viewing all articles
Browse latest Browse all 1251

Trending Articles