Jun-10-2019, 09:22 PM
I am trying to read serial data from a device that outputs in a mix of ASCII and binary, using Python 3.
The message format is: "$PASHR,<msg type>,<binary payload>,<checksum>,\r\n" (minus the quotes)
To make it more interesting, there are several different message types, and they have different payload lengths, so I can't just read X bytes (I can infer the payload length based on the message type). The sequence of five messages (one of each type) is sent every 20 seconds, at 115200 baud.
I haven't been able to read this with serial.readline(), probably because of newlines embedded in the payload.
I think that if I could set the line-end character to "$PASH" that would give me a way to frame the messages -- ie, everything between one $PASH and the next is one message. But I haven't succeeded in setting serial.newline to that value.
Is there a way to set the newline to that multi-character string, or is there a different/better approach I should use?
Thanks!
The message format is: "$PASHR,<msg type>,<binary payload>,<checksum>,\r\n" (minus the quotes)
To make it more interesting, there are several different message types, and they have different payload lengths, so I can't just read X bytes (I can infer the payload length based on the message type). The sequence of five messages (one of each type) is sent every 20 seconds, at 115200 baud.
I haven't been able to read this with serial.readline(), probably because of newlines embedded in the payload.
I think that if I could set the line-end character to "$PASH" that would give me a way to frame the messages -- ie, everything between one $PASH and the next is one message. But I haven't succeeded in setting serial.newline to that value.
Is there a way to set the newline to that multi-character string, or is there a different/better approach I should use?
Thanks!