Python newline \r\n problems

26 views
Skip to first unread message

Matthew Walker

unread,
Oct 7, 2021, 4:06:40 PM10/7/21
to Protocol Buffers
Hi all,

Trying to push data via USB serial onto python application. Fails intermittently seemingly only ever due to the \r\n combination found within the received bytes (shown below).
Any ideas whats going on here?

Screenshot from 2021-10-07 21-01-16.pngScreenshot from 2021-10-07 21-03-33.png
Code snippet from application:
            len_ = ser.read_until(size = 2)
            # Unpack as uint16 with big endianness
            bytes_to_read = struct.unpack('>H',len_)[0]
            print("PB bytes incoming: {}".format(bytes_to_read))
            message = bytearray(ser.read(size=bytes_to_read))
            print(message)
            print(message.hex(' '))
            print(len(message))
            try:
                telemetry.ParseFromString(message)
            except:
                 print("Bad decode!")

Cheers,
Matt.                  

Matthew Walker

unread,
Oct 8, 2021, 2:19:16 PM10/8/21
to Protocol Buffers
More investigation. Its definitely \r\n that causes this, or specifically the hexadecimal 0d 0a. Whenever this is received in this combination the ParseFromString falls over. Any ideas? I've got no print statements in the C that is sending this binary over USB, and these are received mid message, I suspect due to the line-up of bytes.
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages