java - How to send command to a usb printer? -
i need open cash drawer cmd. started java (with app) didn't found detailed information classes , how them interact windows ports couldn't working. these method tried(neither errors neither open cash drawer):
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(); }
then started testing cmd, following this thread, when execute command 'copy /b open.bat usb001' says: 'overwrite usb001 ? (yes/no/all)'
any idea?
well...the usb001 file must exist in location you're copying , it's asking if want overwrite since you're copying open.bat same usb001 file name.
if want overwrite usb001 file use /y switch well, example:
copy /b /y open.bat usb001
you can view switches copy @ command prompt entering:
copy /?
Comments
Post a Comment