以前做斑马打印机的时候用过ZPL指令通过并口发送的方式控制打印机(C++的), 扫描枪就比较简单了,你可以把它直接看成键盘,扫描的过程就是输入的过程
FileOutputStream os = new FileOutputStream("LPT1"); os.write(yourData); os.flush();
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null); PrintService printService = null; if (services != null && services.length > 0) { String printerName = "zebra";// something like this for (PrintService service : services) { if (service.getAttribute(PrinterName.class).getValue().equals(printerName)) { printService = service; break; } } } if (printService == null) { //do what you want } DocPrintJob job = printService.createPrintJob(); DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; Doc doc = new SimpleDoc(new ByteArrayInputStream(yourData), flavor, null); try { job.print(doc, null); } catch (PrintException e) { //handle exception }
CommPortIdentifier port = CommPortIdentifier.getPortIdentifier(outputDest); ParallelPort parallelPort = (ParallelPort) port.open("some owner", 50); OutputStream outputStream = parallelPort.getOutputStream(); outputStream.write(uccLabelData); outputStream.flush();