-
-
Save gladson/3184030 to your computer and use it in GitHub Desktop.
class para comunicação com impressoras térmicas protocolo PPLA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DEVICE = "/dev/lp0"; | |
STX = chr(2); | |
CR = chr(13); | |
LF = chr(10); | |
DEFAULTS = { | |
'ori': 4, | |
'font': 2, | |
'mh': 2, | |
'mv': 2, | |
'fontsub': 0, | |
'y': 0, | |
'x': 0, | |
} | |
class Label(object): | |
def __init__(self, test=False): | |
self.lines = []; | |
self.test = test; | |
if not self.test: | |
self.device = open(DEVICE,"w"); | |
self.send_raw(STX+"L"); | |
self.send_raw("D11"); | |
self.send_raw("PE"); | |
self.send_raw("H11"); | |
def send_raw(self, data): | |
if not self.test: | |
self.device.write(data+CR); | |
self.device.flush(); | |
sys.stdout.write("[IMPRESSORA] "+ data+CR+LF); | |
sys.stdout.flush(); | |
def code(self, id, y, x, size = 22, height = 35, ori = 4): | |
command = '%dC%02d%03d%04d%04d' % (ori, size, height, y, x); | |
self.send_raw(command+str(id)); | |
def text(self, text, y, x, **args): | |
# para o remove_accents, eu estou usando https://gist.github.com/1141017 | |
text = remove_accents(text).upper(); | |
parms = DEFAULTS.copy(); | |
parms.update(args); | |
parms['y'] = y; | |
parms['x'] = x; | |
parms['font'] = allowed_font(parms['font'],len(text)); | |
command = "%(ori)1d%(font)1s%(mh)1d%(mv)1d%(fontsub)03d%(y)04d%(x)04d" % parms; | |
self.send_raw(command+text[0:40]); | |
def close(self, copies = 1): | |
self.send_raw("Q%04d" % (int(copies),) ); | |
self.send_raw("E"); | |
if not self.test: | |
self.device.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment