-->

逆位顺序的Python? ESC / POS DLE EOT打印机状态escpos(Revers

2019-10-30 06:24发布

我有问题解码DLE EOT 1个IM思考其位顺序和缺乏前导零的

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。 实时状态可以通过位0,1,4从其他的发送数据进行区分,和图7,除了在块数据(报头- 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    |
--------------------------------------------------------------

Answer 1:

 print(bin(data[0])[2:].zfill(8)[::-1])

这将添加前导零和反向位。 其结果是:在线状态:

                            /---------Bit 3
00010110  -> reversed =  01101000
0xx1xx10b -> reversed = b01xx1xx0
                            ^---------Bit 3


文章来源: Reverse Bit Order Python? ESC/POS DLE EOT Printer status escpos