如何用java程序打开现金抽屉 [英] How to kick open a cash drawer with java programe
本文介绍了如何用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
推荐答案
Java不是我的专长,但我知道这个问题。
你想要将转义命令作为原始数据打印到打印机。
您需要搜索互联网:
- Java打印原始数据
- Java打印转义命令
在很多论坛上都提到了这个问题,你知道哪个答案符合你的需要。
Java is not my specialty, but I know this problem.
You want to print this escape command to the printer as raw data.
You need to search internet with :
- Java print raw data
- Java print escape command
The question was asked in many forum, you hace yo see which answer will fit your needs.
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程序打开现金抽屉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文