Fixed buggy connection to printer

This commit is contained in:
N07070 2021-01-02 17:21:41 +01:00
parent 4ed11cb078
commit c9a42a7b8b

View File

@ -31,13 +31,16 @@ class Printer(object):
self.printer = None self.printer = None
def init_printer(self, device_id,vendor_id): def init_printer(self, device_id,vendor_id):
try: try:
p = Usb(vendor_id, device_id) p = Usb(0x04b8, 0x0e28, 0)
except USBNotFoundError as e: except USBNotFoundError as e:
self.app.logger.error("The USB device is not plugged in, aborting...") self.app.logger.error("The USB device is not plugged in, aborting..." + str(e))
exit(-1) return False
waiting_elapsed = 10 waiting_elapsed = 10
# p.open()
# Is the printer online ? Is the communication with the printer successfull ? # Is the printer online ? Is the communication with the printer successfull ?
while not p.is_online(): while not p.is_online():
self.app.logger.debug('Waiting for printer to get online...') self.app.logger.debug('Waiting for printer to get online...')
@ -59,12 +62,12 @@ class Printer(object):
self.app.logger.debug('Printer has paper, good to go') self.app.logger.debug('Printer has paper, good to go')
# We're going to print a little text to let know that we're good, as a final check. # We're going to print a little text to let know that we're good, as a final check.
p.textln("Hello world ! \nStarting up at " + strftime("%Y-%m-%d %H:%M:%S", gmtime())) # p.textln("Hello world ! \nStarting up at " + strftime("%Y-%m-%d %H:%M:%S", gmtime()))
p.set(align='center', font='a', bold=False, underline=0, width=1, height=1, density=9, invert=False, smooth=False, flip=False, double_width=False, double_height=False, custom_size=False) # p.set(align='center', font='a', bold=False, underline=0, width=1, height=1, density=9, invert=False, smooth=False, flip=False, double_width=False, double_height=False, custom_size=False)
p.textln("------------------") # p.textln("------------------")
p.qr("Hello World ! :)") # p.qr("Hello World ! :)",size=1)
p.image("../configuration/hello_world.png",center=True) p.image("configuration/hello_world.png",center=True,impl='bitImageColumn')
p.cut() # p.cut()
self.printer = p; self.printer = p;
self.ready = True; self.ready = True;