HeligPfleigh / react-native-thermal-receipt-printer

A RN library for thermal printer
169 stars 103 forks source link

How to properly closeConn()? #123

Open montanhes opened 2 years ago

montanhes commented 2 years ago

I'm using this lib to print using Bluetooth printers, It's working, but I struggling to deal with the BLEPrinter.closeConn().

I have created the function:

async function connectPrinter(receipt) {
    await BLEPrinter.init();
    await BLEPrinter.connectPrinter(printer.inner_mac_address);
    await BLEPrinter.printText(receipt);
    await BLEPrinter.closeConn();
}

The printer that I'm using has a blue led that indicates that the Bluetooth connection has established, If I call the BLEPrinter.closeConn() after the BLEPrinter.printText(receipt) it's close the connection and most of the time the print does not have time to finish the printing that stop on the middle of the receipt.

If I comment the await BLEPrinter.closeConn(), the blue led turn on and the printText print all the receipt. Do we have any method/event to know if the printText has finished his job before I call the closeConn method?

hoanganhnh2009 commented 1 year ago

why are close after print?

montanhes commented 1 year ago

why are close after print?

I added it to disconnect from the print after this finish, but it isn't working as expected for me. So I solved it by calling the closeConn() after the user navigate back to previous screen.