gpt4 book ai didi

java - 如何打开连接到电脑的钱箱

转载 作者:搜寻专家 更新时间:2023-11-01 03:05:18 27 4
gpt4 key购买 nike

我最近创建了一个 java 程序,它可以打印收据并打开连接到打印机的现金抽屉。

现在我需要打开将通过 RJ11 直接连接到计算机的现金抽屉。

因为我不会将现金抽屉连接到打印机,所以我的 feedPrinter 将毫无用处。那么我该如何调用并向现金抽屉发送命令呢?

这是我的代码

public String openDrawer()
{
final byte[] openCD={27,112,0,60,120};
String s=new String(openCD);
commandSet+=s;
return s;
}


public static void main(String args[])
{
PrinterOptions p=new PrinterOptions();
p.openDrawer();
feedPrinter(p.finalCommandSet().getBytes());
}


private static boolean feedPrinter(byte[] b)
{
try
{

AttributeSet attrSet = new HashPrintServiceAttributeSet(new PrinterName("PRINTERNAME", null));
//what should I change PRINTERNAME to connect directly to cash drawer
DocPrintJob job = PrintServiceLookup.lookupPrintServices(null, attrSet)[0].createPrintJob();
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
Doc doc = new SimpleDoc(b, flavor, null);
PrintJobWatcher pjDone = new PrintJobWatcher(job);

job.print(doc, null);
pjDone.waitForDone();
System.out.println("Done !");
}
catch(javax.print.PrintException pex)
{

System.out.println("Printer Error " + pex.getMessage());
return false;
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
return true;
}

public String finalCommandSet()
{
return commandSet;
}

最佳答案

首先,也是最重要的,从 http://keyhut.com/popopen4.htm

Drawer code for my printer is = 27,112,0,100,250

然后,使用下面的代码打开您的现金抽屉。

public void openCashDrawer() {

byte[] open = {27,112,0,100,(byte) 250};
// byte[] cutter = {29, 86,49};
PrintService pservice =
PrintServiceLookup.lookupDefaultPrintService();
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 - 如何打开连接到电脑的钱箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24860063/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com