anastaciocintra / escpos-coffee

Java library for ESC/POS printer
https://anastaciocintra.github.io/escpos-coffee
MIT License
277 stars 72 forks source link

how can I open the cash drawer? #50

Open anastaciocintra opened 3 years ago

anastaciocintra commented 3 years ago

and what command should be sent to open the cash drawer?

Originally posted by @palanganero in https://github.com/anastaciocintra/escpos-coffee/issues/49#issuecomment-700218996

anastaciocintra commented 3 years ago

I don't have cash drawer to test it, if anyone have one best answer, please, correct me but you should use pulsePin If you have one (cash drawer), you can try to use and give us one feedback...

        // send pulse pin to pin2
        escpos.pulsePin(EscPos.PinConnector.Pin_2,25,250);

        // OR send pulse pin to pin5
        escpos.pulsePin(EscPos.PinConnector.Pin_5,25,250);
palanganero commented 3 years ago

I've googled a bit and found that each printer has a code for that, which would have to send the code like this: escpos.writeLF(chr(27). chr(112). chr(0). chr(100). chr(250)); but there must be something wrong since it marks an error in that line. Maybe it is in the character format since I think that code is in php. Is there a way to translate it to java?

anastaciocintra commented 3 years ago

java translation:

escpos.write(27).write(112).write(0).write(100).write(250);

I saw a lot of combinations on http://keyhut.com/popopen4.htm depending of your printer's brand/model you can put other values...

anastaciocintra commented 3 years ago

don't forget to send feedback ..

palanganero commented 3 years ago

i don't have a cash drawer so i cannot try it. But if i could get one i will coment it.

palanganero commented 3 years ago

and with this command you are sending the ascii codes?:escpos.write(27).write(112).write(0).write(100).write(250);

anastaciocintra commented 3 years ago

yeap, notice that it is in decimal values.

palanganero commented 3 years ago

The code is not needed to open the box as the box opens automatically when printing a ticket

anastaciocintra commented 3 years ago

I think that it is dependent of printers configuration / setup... otherwise we need to send the escpos command in question

cemkoeylue commented 3 years ago

Hi anastaciocintra, as far as I know the method pulsePin should open the cashdrawer, as you can see here: https://github.com/anastaciocintra/escpos-coffee/issues/10

So, what I don't understand is, do we need to pass the values listed here http://keyhut.com/popopen4.htm or is it enough to use the pulsePin method?

anastaciocintra commented 3 years ago

Hi @cemkoeylue,

the lib have one funtion for this, it is based on https://github.com/mike42/escpos-php. but, unfortunately, I don't have one cashdrawer to test it.

another point is that after research, we discover (here on this issue) that the sequence of commands to open the cash-drawer is dependent of brand/ model of the printer.

so, if you have one cash-drawer and what to test it, you can code something like that:

    // info on http://keyhut.com/popopen4.htm
    // manufacturer 3NSTAR
    // model LPT005
    // Drawer Codes 27,112,0,25,250
    public void myOpenCashDrawer(EscPos escPos) throws IOException {
        escPos.write(27).write(112).write(0).write(25).write(250);
    }

After all, comments regarding the tests are welcome, its to improve our lib.

cemkoeylue commented 3 years ago

Hi @anastaciocintra , thank you for your reply. For my understanding following code snippet should open a cash drawer :

  PrintService printService = PrinterOutputStream.getPrintServiceByName("printerName");
  PrinterOutputStream printerOutputStream = new PrinterOutputStream(printService);
  EscPos escpos = new EscPos(printerOutputStream);
  escpos.write(27).write(112).write(0).write(25).write(250); 
  escpos.cut(EscPos.CutMode.FULL); 
  escpos.close();

This is of course for one specific printer with a specific brand name. But let's assume that we have only printer, for example an Epson receipt printer. We pass the printer name and we send the commands (27,112....etc) to the printer and that printer should open the cash drawer, right?

anastaciocintra commented 3 years ago

Yes This shall open the cash drawer

Now Remains only to test with concrete equipment.

cemkoeylue commented 3 years ago

I have one cash drawer and a recept printer and gonna test this and gonna update you.

Thank you for your great library btw!

anastaciocintra commented 3 years ago

I mean Lack to test with real cash drawer equipment

cemkoeylue commented 3 years ago

Yes, I have a real equipment and I am going to test this.

anastaciocintra commented 3 years ago

Good

geraldzm commented 3 years ago

https://github.com/anastaciocintra/escpos-coffee/issues/50#issuecomment-740220143

I can confirm that this works. I tested it with an EPSON TM T20II, although my codes were different.

    escpos.write(27).write(112).write(0).write(55).write(121);
VictorChavezMX commented 1 year ago

I can confirm that this sequence is working with ZKTeco 5000 & ZKTeco 8000 (which are very generic printers)

escpos.write(27).write(112).write(0).write(55).write(121);

onipun commented 1 year ago

I'm using pulsePin method and it's working. The issue I'm having is the cashdrawer periodically open. I need to restart the app or the printer in order to make it work again. Any idea how can i solve this. I can confirm this is not related to hardware

VictorChavezMX commented 1 year ago

@onipun in my case I'm using this: the pin can be PIN_5 or PIN_2 (0 or 1)

    int pin_dest = pin.equals("PIN_2") ? 0 : 1;
    logger.info("Open drawer on ESCPOS device pin: " +  pin_dest);
    escpos.write(27).write(112).write(pin_dest).write(25).write(250);
    escpos.close();

check the .close() method, also use a try/catch and try to close in catch section also to be sure that the port is closed (or .close in the finally clause too)

onipun commented 1 year ago

@VictorChavezMX sorry. This is embarrassing. It is the hardware connection issue. Before this i just unplug and plug back the rj11 cable. After cleaning up a bit it's working with current pulsePin code

VictorChavezMX commented 1 year ago

nice!!! once i was testing with the rj11 plugged into the rj45 port lol!!