反向位顺序Python? ESC/POS DLE EOT打印机状态保留 [英] Reverse Bit Order Python? ESC/POS DLE EOT Printer status escpos

查看:212
本文介绍了反向位顺序Python? ESC/POS DLE EOT打印机状态保留的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在解码DLE EOT 1时遇到问题 我在想它的位顺序和前导零的缺乏

I am having issues decoding DLE EOT 1 im thinking its the bit order and the lack of leading zeros

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 = ""

因此,这是处于就绪和联机状态时返回的内容:

so this is what is returned when in ready and online status:

b'\x16'
0b10110
10110

这是当门打开时假定处于脱机状态"时返回的内容:

this is what returns when the Door is open 'assume OFFLINE status':

b'\x1e'
0b11110
11110

其中的任何一个如何翻译?我不需要8位吗?

how does any of that translate? dont i need 8bits back?

摘录自EPSON ESC手册:

每个状态由1个字节组成,值为0xx1xx10b. 实时状态可以通过位0、1、4和7与其他传输数据区分开,块数据中的数据除外(标头– NUL).

Each status consists of 1 byte, and the value is 0xx1xx10b. The real time status can be differentiated by the bits 0, 1, 4, and 7 from other transmission data, except for data in block data (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])

这将添加前导零并反转位.结果: 在线状态:

this will add leading zeros and reverse the bits. The result: status online:

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

这篇关于反向位顺序Python? ESC/POS DLE EOT打印机状态保留的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆