Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 29-Oct-16 22:47pm
Comments
Kornfeld Eliyahu Peter 28-Jul-16 9:43am    
You have to read the manual from the cash machine manufacturer...All the answers there...

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.
 
Share this answer
 
Comments
Retish Pillai 29-Jul-16 9:19am    
Thank you very much. I found one article and tested and was successful. Great help
Member 12609609 23-Aug-16 6:03am    
hi, may i know which example that u found is work? can u share to me , i also doing this project , thx
Patrice T 23-Aug-16 6:21am    
I have found an example that I know is working, because I don't use Java.
But I am familiar with raw printing with xHarbour/Harbour/Clipper/FoxPro/dBase langauges going back to DOS age.
Retish Pillai 30-Oct-16 4:52am    
Sorry...
I didnot visited this page for long time.

here i add the code which works



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());
}
}
C#
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());
        }
    }
 
Share this answer
 
Comments
Pramod Talwar 19-Aug-19 3:01am    
Can someone help with getting the cash drawer status(Open/Closed)?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900