Skip to content

Commit b88bfa4

Browse files
committed
add a method byte_to_bits
1 parent 1b8cf9e commit b88bfa4

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

epson_printer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
__version__ = "1.10.0"
2+
__version__ = "1.11.0"
33

44
__all__ = ["epsonprinter","testpage"]
55

epson_printer/epsonprinter.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from contextlib import contextmanager
33
import usb.core
44
import usb.util
5-
import time
65

6+
from .utils import to_hex, byte_to_bits
77

88

99
ESC = 27
@@ -148,7 +148,7 @@ def in_endpoint_match(ep):
148148

149149

150150
def write_bytes(self, byte_array, timeout=5000):
151-
msg = ''.join([chr(b) for b in byte_array])
151+
msg = to_hex(byte_array)
152152
self.write(msg, timeout)
153153

154154
def write(self, msg, timeout=5000):
@@ -247,7 +247,8 @@ def paper_present(self):
247247
self.transmit_real_time_status(4)
248248
with time_limit(1):
249249
data = self.blocking_read()
250-
return data == 18
250+
bits = byte_to_bits(data)
251+
return bits[5] == 0
251252
except:
252253
return False
253254

epson_printer/utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import math
2+
3+
4+
def to_hex(arr):
5+
""" convert a decimal array to an hexadecimal String"""
6+
return ''.join(chr(b) for b in arr)
7+
8+
9+
def byte_to_bits(b):
10+
11+
assert b <= 255
12+
13+
r = b
14+
15+
bits = {}
16+
17+
for i in range(0, 8):
18+
a = math.pow(2, 7 - i)
19+
bits[7 - i] = int(r // a)
20+
r = r % a
21+
22+
return bits

0 commit comments

Comments
 (0)