有没有办法通过usb端口用java连接到一台datamax打印机?

时间:2018-04-04 22:02:42

标签: java thermal-printer

我试图使用datamax中的sdk,只有你可以通过bluethoot或tcp / ip端口连接 但我需要工作的是通过USB端口

我试图做这样的事情,但没有运气

DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();

        PrintService printService[] = PrintServiceLookup.lookupPrintServices(
                flavor, pras);
        PrintService service = findPrintService(printerName, printService);

        DocPrintJob job = service.createPrintJob();

        try {

            Doc doc = new SimpleDoc(bytes, flavor, null);

            job.print(doc, null);

        } catch (Exception e) {
            e.printStackTrace();
        }

1 个答案:

答案 0 :(得分:0)

我的连接方式很好用DocFlavor.BYTE_ARRAY.AUTOSENSE ..我唯一不好的是我发送到打印机的字节数组 需要根据DPL Datamax Printer Languague

这是您需要为文本收据发送内容的示例

String STX = new Character((char) 2).toString();
String CR = new Character((char) 0x0d).toString();

String printText = STX
        + "L" + CR
        + "D11" + CR
        + "H14" + CR
        + "121100001200050" + studentname + CR
        + "121100001000050" + studentid + CR
        + "121100000800050" + date + CR
        + "121100000600050" + typeexam + CR
        + "Q0001" + CR
        + "E" + CR;

PrinterService printerService = new PrinterService();
printerService.printBytes("Datamax-O'Neil E-4304 Mark II", printText.getBytes());