Reputation: 9
I have a piece of hardware that for instance returns the "response" below. Per the instructions, I would like to separate the response to the 1st and last 4 bits. But the lower bit response doesn't make sense when I convert it like below.
I'm quoting the instructions. The possible first 4 bits are: ['1010', '0110', '1000', '0100', '1100', '0100']
response = b'\x11' # returned by device
r_int = int(response.hex(),8) # convert to int from 8 bit
print('7', r_int>>7) # Bit 7
print('6',r_int>>6)# Bit 6
print('5',r_int>>5)# Bit 5
print('4',r_int>>4)# Bit 4
"... will respond to any code sent to it with a status update, which will be sent as 8-bit binary. The first four bits, referred to as the “upper nibble”, denote the current position. The last four bits, referred to as the “lower nibble”, denote the ‘mode’ of the wheel at the time of the status update "
Update1: I corrected the response list above. The following seems to be the right code to read the bits. For example for response = b'\x11' it returns '00010001'
response_hex = response.hex()
scale = 16
n_bits = 8
bits_read = bin(int(response_hex, scale))[2:].zfill(n_bits)
print(bits_read)
while expected "1000" the device returns "\x16" that converts to "0110".
Upvotes: -2
Views: 67
Reputation: 36
If the device is sending the x11
when initially connecting, or after the initial attempt to get data from it, it could be that it's trying to initiate a software flow control, or software flow control is enabled. Without knowing more about the device and how it's connected its hard to say for sure.
The hex code \x11
in example above is 00010001
or 0001 0001
is the ASCII control DC1, which is used for software flow control to indicate it's ready to receive commands.
https://www.asciihex.com/character/control/17/0x11/dc1-device-control-one-xon-
Upvotes: 0