I am converting a program from P2.7 to P3.5
I receive from a serial interface an array of bytes.
When I print the array in P2.7 I get this:
I need to do calculations whith the data so I want to convert de hex value in an integer by
However it seems that the problem is occuring earlier in the process:
I use the Serial library with the following code:
I receive from a serial interface an array of bytes.
When I print the array in P2.7 I get this:
Raw ['07', 'f3', '07', 'f0', '00', 'd2', '09', '50', '47', '53', '53', '49', '0f', '28', '28', '28', '95', '07', '0f']If I print the same result in P3.5 I get this:
Raw [b'\x07', b'\xf3', b'\x07', b'\xf0', b'\x00', b'\xd2', b'\t', b'P', b'H', b'S', b'S', b'J', b'\x0f', b'(', b'(', b'(', b'\x97', b'\x07', b'\x0f', b'']basically the same data but another representation. look e.g. to Raw[7] it is 0x50 but in P3.5 b'P'. Basically the same value (Decimal 80) but represented in hex or ascii.
I need to do calculations whith the data so I want to convert de hex value in an integer by
test = int(raw[7], 16)and I get the error
Error:ValueError: invalid literal found for int() with base 16: b'P'
How do I preserve the hex data in the Raw array of bytes?However it seems that the problem is occuring earlier in the process:
I use the Serial library with the following code:
response = [] serialConnection.write(command) # Wait for response to be acquired or the connection to time out while response[-2:] != [b'\x07', b'\x0f'] and time.time() - start < self.timeout: response.append (serialConnection.read())it looks to me that the response.append command interprets the bytes read from the interface and converts them into strings like b'P' for 0x50