我在解码DLE EOT 1时遇到问题 我认为它的位顺序和缺少前导零
import serial
x = 1
while x:
time.sleep(3)
ser.write("\x10\x04\x01".encode())
bytesToRead = ser.inWaiting()
data = ser.read(bytesToRead)
while data:
print(data)
print(bin(int.from_bytes(data, byteorder="big")))
print(bin(data[0])[2:])
data = ""
所以这是处于准备和在线状态时返回的内容:
b'\x16'
0b10110
10110
这是在门打开时返回的状态'假设离线状态':
b'\x1e'
0b11110
11110
这是怎么翻译的?我不需要8比特吗?
摘自EPSON ESC手册:
每个状态由1个字节组成,值为0xx1xx10b。 除了块数据(Header-NUL)中的数据之外,实时状态可以通过位0,1,4和7与其他传输数据区分开来。
Bit Binary Status |Hex|Decimal ====+==============================================+===+====== 0 | 0 | Fixed |00 |0 | ----+---+------------------------------------------+---+-----+ 1 | 1 | Fixed |02 |2 | ----+---+------------------------------------------+---+-----+ 2 | 0 | Drawer kick-out connector pin 3 is LOW |00 |0 | | 1 | Drawer kick-out connector pin 3 is HIGH |04 |4 | ----+---+------------------------------------------+---+-----| 3 | 0 | Online |00 |0 | | 1 | Offline |08 |8 | ----+---+------------------------------------------+---+-----| 4 | 1 | Fixed |10 |16 | ----+---+------------------------------------------+---+-----| 5 | 0 | Not waiting for online recovery |00 |0 | | 1 | Waiting for online recovery |20 |32 | ----+---+------------------------------------------+---+-----| 6 | 0 | Paper feed button is not being pressed |00 |0 | | 1 | Paper feed button is being pressed |04 |64 | ----+---+------------------------------------------+---+-----| 7 | 0 | Fixed |00 |0 | --------------------------------------------------------------
答案 0 :(得分:0)
print(bin(data[0])[2:].zfill(8)[::-1])
这将添加前导零并反转位。结果: 在线状态:
/---------Bit 3
00010110 -> reversed = 01101000
0xx1xx10b -> reversed = b01xx1xx0
^---------Bit 3