反转位序 Python? ESC/POS DLE EOT 打印机状态 escpos
Reverse Bit Order Python? ESC/POS DLE EOT Printer status escpos
我在解码 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
这就是 returns 打开门时的样子 'assume OFFLINE status':
b'\x1e'
0b11110
11110
这些是怎么翻译的?我不需要 8 位返回吗?
EPSON ESC手册摘录:
每个状态由1个字节组成,值为0xx1xx10b。
实时状态可以通过位 0、1、4 和 7 与其他传输数据区分开来,块数据 (Header – NUL) 中的数据除外。
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 |
--------------------------------------------------------------
print(bin(data[0])[2:].zfill(8)[::-1])
这将添加前导零并反转位。结果:
在线状态:
/---------Bit 3
00010110 -> reversed = 01101000
0xx1xx10b -> reversed = b01xx1xx0
^---------Bit 3
我在解码 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
这就是 returns 打开门时的样子 'assume OFFLINE status':
b'\x1e'
0b11110
11110
这些是怎么翻译的?我不需要 8 位返回吗?
EPSON ESC手册摘录:
每个状态由1个字节组成,值为0xx1xx10b。 实时状态可以通过位 0、1、4 和 7 与其他传输数据区分开来,块数据 (Header – NUL) 中的数据除外。
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 | --------------------------------------------------------------
print(bin(data[0])[2:].zfill(8)[::-1])
这将添加前导零并反转位。结果: 在线状态:
/---------Bit 3
00010110 -> reversed = 01101000
0xx1xx10b -> reversed = b01xx1xx0
^---------Bit 3