我的目标是以编程方式打开一个现金抽屉,但我没有找到有关 Java 如何与 Windows 端口交互的详细信息,所以我无法让它工作。这些是我尝试过的方法(Java 控制台中没有错误):
public void cashdrawerOpen() {
String code1 = "27 112 0 150 250"; //decimal
String code2 = "1B 70 00 96 FA"; //hexadecimal
String code = "ESCp0û."; //ascii
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
System.out.println(service.getName());
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
DocPrintJob pj = service.createPrintJob();
byte[] bytes;
bytes=code2.getBytes();
Doc doc=new SimpleDoc(bytes,flavor,null);
try {
pj.print(doc, null);
} catch (PrintException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void cashdrawerOpen2(){
String code1 = "27 112 0 150 250";
String code2 = "1B 70 00 96 FA";
String code = "ESCp0û.";
FileOutputStream os = null;
try {
os = new FileOutputStream("USB001:POS-58");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
PrintStream ps = new PrintStream(os);
ps.print(code1.getBytes());
ps.close();
}
然后我开始玩 cmd,特别是在这个线程之后,但是当我执行命令 'copy /b open.bat USB001' 它只是说:'覆盖 USB001 ?(是/否/全部)'
任何的想法?