tr3v3r / react-native-esc-pos-printer

An unofficial React Native library for printing on an EPSON TM printer with the Epson ePOS SDK for iOS and Epson ePOS SDK for Android
MIT License
161 stars 72 forks source link

How to trigger the printer to open the cash drawer ? #17

Closed MinaZakaria closed 2 years ago

tr3v3r commented 3 years ago

@MinaZakaria Hi! What do you mean by Cash Drawer?

MinaZakaria commented 3 years ago

The Cash Drawer is the place that contains the money. So times we need to open the drawer when printing the receipt to add more money. There is a cable that connects from the Epson printer to the drawer. and then it wait for a command from the printer to open the cash drawer 81CfVLfnBnL _AC_SL1500_

tr3v3r commented 3 years ago

@MinaZakaria Thanks for the explanation! Actually, to provide this functionality we need to add the corresponding method addPulse to handleCommand method for iOS and Android. Unfortunately, at the time I don't have the capacity to add it. But if you have, I'd really appreciate it )

https://github.com/tr3v3r/react-native-esc-pos-printer/blob/ba2ed89970993471d4538f1be6146be7a89ff671/ios/EscPosPrinter.m#L481

https://github.com/tr3v3r/react-native-esc-pos-printer/blob/ba2ed89970993471d4538f1be6146be7a89ff671/android/src/main/java/com/reactnativeescposprinter/EscPosPrinterModule.java#L487

Than we can just use it like:

 printing()
 .addText('text')
 .addImage('logo.png`)
 .addPulse( // args )
 .addCut()

Here the method specification: image

ahaikal commented 2 years ago

@MinaZakaria a quick way to do this

import Encoder from 'esc-pos-encoder';
       ....
        const encoder = new Encoder();
        const printing = new EscPosPrinter.printing();
        encoder.pulse(0, 100, 100);
        const status = await printing.data(encoder.encode()).send();

This works for me

tr3v3r commented 2 years ago

Version 1.5.0 adds this functionality