I’m sending the bytestring 0x0F, 0x07, 0x55, 0x55, 0x55 from a PIC microcontroller.
Over the serial port with Python I am using the readlines() command in PySerial. I receive:
['\x0f\x07UUU']
This does indeed correspond to the bytestring I sent, but it is formatted using what looks like a strange combination of hexadecimal and ASCII characters. What would be a good way to format this back to 0x0F, 0x07, 0x55, 0x55, 0x55 ?
In Python 2, a bytestring (str) is a string of 8-bit characters, so it will look like that. Use the “ord” function convert each character to an int: