forked from webkul/py-xml-escpos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_printer.py
59 lines (51 loc) · 1.52 KB
/
test_printer.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
test_temp = """
<receipt>
<h1>Receipt!</h1>
<h2>div,span,p,ul,ol are also supported</h2>:w
<line>
<left>Product</left>
<right>0.15</right>
</line>
<hr />
<line size='double-height'>
<left>TOTAL</left>
<right>0.15</right>
</line>
<barcode encoding='ean13'>
5449000000996
</barcode>
<cashdraw />
<cut />
</receipt>
"""
from xmlescpos.exceptions import *
from xmlescpos.printer import Usb
import usb
import pprint
import sys
pp = pprint.PrettyPrinter(indent=4)
try:
printer = Usb(0x04b8,0x0202)
printer._raw('\x1D\x28\x47\x02\x00\x30\x04');
printer._raw('AAAA');
printer._raw('\x0c');
printer._raw('\x1c\x61\x31');
printer._raw('BBBB');
printer._raw('\x0c');
printer._raw('\x1d\x28\x47\x02\x00\x50\x04');
printer._raw('\x1D\x28\x47\x02\x00\x30\x04');
printer._raw('\x1D\x28\x47\x02\x00\x54\x00');
printer._raw('CCCC');
printer._raw('\x1D\x28\x47\x02\x00\x54\x01');
#printer.receipt(test_temp)
pp.pprint(printer.get_printer_status())
except NoDeviceError as e:
print "No device found %s" %str(e)
except HandleDeviceError as e:
print "Impossible to handle the device due to previous error %s" % str(e)
except TicketNotPrinted as e:
print "The ticket does not seems to have been fully printed %s" % str(e)
except NoStatusError as e:
print "Impossible to get the status of the printer %s" % str(e)
finally:
printer.close()