-
-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
class QR204(object):
_printer = None
CODEPAGE = {
"CHINESE":255,
"BIG5":254,
"UTF-8":253,
"SHIFT-JIS":252,
"EUC-KR":251,
"CP437":0,
"Katakana":1,
"CP850":2,
"CP860":3,
"CP863":4,
"CP865":5,
"CP1251":6,
"CP866":7,
"MIK":8,
"CP755":9,
"Iran":10,
"CP862":15,
"CP1252":16,
"CP1253":17,
"CP852":18,
"CP858":19,
"Iran II":20,
"Latvian":21,
"CP864":22,
"ISO-8859-1":23,
"CP737":24,
"CP1257":25,
"Thai":26,
"CP720":27,
"CP855":28,
"CP857":29,
"CP1250":30,
"CP775":31,
"CP1254":32,
"CP1255":33,
"CP1256":34,
"CP1258":35,
"ISO-8859-2":36,
"ISO-8859-3":37,
"ISO-8859-4":38,
"ISO-8859-5":39,
"ISO-8859-6":40,
"ISO-8859-7":41,
"ISO-8859-8":42,
"ISO-8859-9":43,
"ISO-8859-15":44,
"Thai2":45,
"CP856":46,
"Cp874":47,
}
def __init__(self, uart):
self._printer = uart
self._printer.write(b'\x03\xFF\x20\x00\x00\x00\x00\x00\x08\x00\xD4\x18DEVICE??')
self._printer.read(12)
self.model = self._printer.read(8)
self.config()
self._printer.write(b'\x1b\x40')
self._printer.write(b'\x1b\x37')
self._printer.write(b'\x14\x96\x50')
self._printer.write(b'\x12\x23\xff')
def test(self):
self.write("\x12\x54")
def setpage(self, codepage="UTF-8"):
self.codepage = codepage
self._printer.write(b'\x1bt%c'%self.CODEPAGE[codepage])
def config(self, codepage="UTF-8", baud=9600, sn="000000"):
self.codepage = codepage
sn = int(sn,16)
cfg =b'\x00\x00%c%c%c%c%c%c'%(
baud//256,baud%256,
self.CODEPAGE[codepage],
(sn>>16)%256,(sn>>8)%256,sn%256)
s = 0
for x in cfg:
s = s^x
self._printer.write(b'\x03\xFF\x60\x00\x00\x00\x00\x00\x08\x00\x94%c%s'%(s,cfg))
return self._printer.read(12)
def newline(self, n=3):
self._printer.write(b'\x0a' * n)
def inverse_enbl(self):
self._printer.write(b'\x1d\x42\x01')
def inverse_dsbl(self):
self._printer.write(b'\x1d\x42\x00')
def bold_enbl(self):
self._printer.write(b'\x1b\x45\x01')
def bold_dsbl(self):
self._printer.write(b'\x1b\x45\x00')
def font_b(self):
self._printer.write(b'\x1b\x21\x01')
def font_a(self):
self._printer.write(b'\x1b\x21\x00')
def font_size(self,w,h):
self._printer.write(b'\x1d\x21%c'%((w*16+h%16)%256))
def uline_enbl(self):
self._printer.write(b'\x1b\x2d\x01')
def uline_dsbl(self):
self._printer.write(b'\x1b\x2d\x00')
def align(self, arg='<'):
if '<' in arg:
self._printer.write(b'\x1b\x61\x00')
elif '>' in arg:
self._printer.write(b'\x1b\x61\x02')
else:
self._printer.write(b'\x1b\x61\x01')
def write(self, text):
self._printer.write(bytes(text,self.codepage))
def writeln(self, text):
self.write(text+'\n')
'''Example
printer = QR204(port)
printer.uline_enbl()
printer.write('Underline')
printer.uline_dsbl()
printer.newline(1)
printer.bold_enbl()
printer.write('Bold')
printer.bold_dsbl()
printer.newline(1)
printer.inverse_enbl()
printer.write('Inverse')
printer.inverse_dsbl()
printer.newline(1)
printer.font_b()
printer.write('Font B')
printer.font_a()
printer.newline(3)
'''Добавил настройку кодировки, скорости связи и установку размеров шрифта. так как тестил на компе с питоном 3 то записал отправку строк как bytes(text,self.codepage)
вот тут выложил https://gist.github.com/NeiroNx/df26db4afafa9801e66d92fdbc49990d
Metadata
Metadata
Assignees
Labels
No labels