def main(): """Main function.""" def auto_int(x): """Convert a string to int with auto base detection.""" return int(x, 0) parser = argparse.ArgumentParser( prog='escpos-cli', description= '%(prog)s is a command-line utility for printing stuff using pyxmlescpos' ) parser.add_argument('-dvid', '--device-vendor-id', required=True, type=auto_int) parser.add_argument('-dpid', '--device-product-id', required=True, type=auto_int) parser.add_argument('-di', '--device-interface', type=int, default=0) parser.add_argument('-die', '--device-input-endpoint', type=auto_int, default=0x82) parser.add_argument('-doe', '--device-output-endpoint', type=auto_int, default=0x01) parser.add_argument('-d', '--debug', action='store_true') parser.add_argument('-o', '--open-cashdrawer', action='store_true') parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __VERSION__) parser.add_argument('receipt_xml', type=str) args = parser.parse_args() device = Usb(args.device_vendor_id, args.device_product_id, interface=args.device_interface, in_ep=args.device_input_endpoint, out_ep=args.device_output_endpoint) if args.open_cashdrawer: device.cashdraw(2) device.cashdraw(5) if args.receipt_xml: device.receipt(args.receipt_xml)
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');
<cut /> </receipt> """ from xmlescpos.exceptions import * from xmlescpos.printer import Usb import usb import pprint import sys i = 5 pp = pprint.PrettyPrinter(indent=4) while i: i -= 1 try: printer = Usb(0x04b8, 0x0e03) 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()