本文介绍了如何用java程序打开现金抽屉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如果有人知道如何用java程序打开现金抽屉,请帮助我。如果打印机通过USB连接,并且现金抽屉连接到打印机(RJ12)。打印机支持ESC / POS。我参考了打印机手册并知道打开现金抽屉的命令。 {27,112,48,55,121}。



我尝试过的事情:



尝试了谷歌的几个提示

Hi,

Please help me if anybody knows how to kick open cash drawer with a java program. Provided the printer is connected via USB and the cash drawer is connected to the printer (RJ12). The printer supports ESC/POS. I referred printer manual and know the command to open cash drawer. {27, 112, 48, 55, 121}.

What I have tried:

tried with several tips in google

推荐答案


public void cashdrawerOpen() {
        
        byte[] open = {27, 112, 48, 55, 121};
//        byte[] cutter = {29, 86,49};
        String printer = PrinterName;
        PrintServiceAttributeSet printserviceattributeset = new HashPrintServiceAttributeSet();
        printserviceattributeset.add(new PrinterName(printer,null));
        PrintService[] printservice = PrintServiceLookup.lookupPrintServices(null, printserviceattributeset);
        if(printservice.length!=1){
            System.out.println("Printer not found");
        }
        PrintService pservice = printservice[0];
        DocPrintJob job = pservice.createPrintJob();
        DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
        Doc doc = new SimpleDoc(open,flavor,null);
        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
        try {
            job.print(doc, aset);
        } catch (PrintException ex) {
            System.out.println(ex.getMessage());
        }
    }


这篇关于如何用java程序打开现金抽屉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 01:07