forked from sintrb/oneprint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
72 lines (61 loc) · 2.16 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- coding: UTF-8 -*
'''
Created on 2020-07-10
'''
from oneprint import EscPosPrint, ImageDrawPrint
def do_table_test():
import io
pt = ImageDrawPrint(encode='utf8', temp_path='/tmp/print', width=576)
with io.open('test/table.xml', 'r', encoding='utf8') as f:
# print(pt._get_char_width(' '))
pt.auto_print(f.read())
# print(pt.get_text())
# print(pt._get_char_width(' '))
pt.show()
def do_all_test():
import io
pt = ImageDrawPrint(encode='utf8', temp_path='/tmp/print', width=576)
with io.open('test/all.xml', 'r', encoding='utf8') as f:
pt.auto_print(f.read())
# print(pt.get_text())
pt.show()
def do_usb_test():
from escpos.printer import Usb
import io
pt = EscPosPrint(encode='gb2312', temp_path='/tmp/print', width=384)
with io.open('test/all.xml', 'r', encoding='utf8') as f:
pt.auto_print(f.read())
import base64
# print(base64.encodebytes(pt.get_data()))
# return
# p = Usb(0x6868, 0x0500, in_ep=0x84, out_ep=0x3)
# p = Usb(0x154f, 0x1300, in_ep=0x82, out_ep=0x01)
p = Usb(0x0483, 0x5720, in_ep=0x82, out_ep=0x02)
# p._raw(bytes([0x31,0x32,0x33,0x0A,0x1D,0x4C,0x50,0x00,0x31, 0x32,0x33, 0x0A]) + pt.get_data())
px = [
0x1B, 0x53,
0x1D, 0x57, 0x80, 0x01,
0x1D, 0x4C, 0xF0, 0x00, 0x0a,
# 0x31, 0x32, 0x33, 0x34, 0x34, 0x0A
]
b = px + [ord(c) for c in '123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklnm\n']
# b = [0x31, 0x32, 0x33, 0x0A, 0x1D, 0x4C, 0xE0, 0x00, 0x31, 0x32, 0x33, 0x0A]
b = bytes(px) + pt.get_data()[2:]
for i in b:
print(hex(i))
p._raw(bytes(b))
p.close()
def do_usb_test2():
from escpos.printer import Usb
# p = Usb(0x6868, 0x0500, in_ep=0x84, out_ep=0x3)
# p = Usb(0x2207, 0x0011, in_ep=0x02, out_ep=0x01)
# p._raw(b'\x1b\x42\x02\x01')
# p.close()
if __name__ == '__main__':
# do_table_test()
do_all_test()
# do_usb_test()
# do_usb_test()
exit()
from werkzeug._reloader import run_with_reloader
run_with_reloader(lambda: do_table_test())