Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can I open the cash drawer? #50

Open
anastaciocintra opened this issue Sep 28, 2020 · 23 comments
Open

how can I open the cash drawer? #50

anastaciocintra opened this issue Sep 28, 2020 · 23 comments

Comments

@anastaciocintra
Copy link
Owner

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

Originally posted by @palanganero in #49 (comment)

@anastaciocintra
Copy link
Owner Author

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
Copy link

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
Copy link
Owner Author

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
Copy link
Owner Author

don't forget to send feedback ..

@palanganero
Copy link

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

@palanganero
Copy link

palanganero commented Sep 30, 2020

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

@anastaciocintra
Copy link
Owner Author

yeap,
notice that it is in decimal values.

@palanganero
Copy link

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

@anastaciocintra
Copy link
Owner Author

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

@cemkoeylue
Copy link

Hi anastaciocintra,
as far as I know the method pulsePin should open the cashdrawer, as you can see here: #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
Copy link
Owner Author

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
Copy link

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
Copy link
Owner Author

Yes
This shall open the cash drawer

Now
Remains only to test with concrete equipment.

@cemkoeylue
Copy link

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
Copy link
Owner Author

I mean
Lack to test with real cash drawer equipment

@cemkoeylue
Copy link

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

@anastaciocintra
Copy link
Owner Author

Good

@geraldzm
Copy link

#50 (comment)

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
Copy link

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
Copy link

onipun commented Aug 15, 2023

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
Copy link

VictorChavezMX commented Aug 16, 2023

@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
Copy link

onipun commented Aug 16, 2023

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants