I have a serial device (loadcell) connected to pc which is constantly sending data in a fixed format. It has 2 stop bits (0x40 and 0x0b). I am trying to read until 1 stop bit so I can start reading the message from the start. The problem is the code never exits the while loop. I tried many ways to convert the bytes I am receiving from the serial port into hex but I can not manage to get out of the while loop.
I NEED to use hex here because 0x0b
value doesn't have any visual (doesn't represent any character). I can not give that input from keyboard!!
loadcell.reset_input_buffer()
some_hex_val = 0x00
def read_thrust():
global some_hex_val
while some_hex_val != 0x0b or some_hex_val != 0x40:
some_hex_val = loadcell.read().hex()
print('Exited while')
read_thrust()
How do I read each byte as hex?
Update:
The .hex()
method doesn't return anything!!? I am reading from serial port in bytes
but using the .hex()
method on it returns None
i guess (because its not printing anything?)
Printing out the types just to be sure