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

The connectPrinter method of BLEPrinter does not throw any error when it fails to connect to the printer #130

Open
akmalhisyammm opened this issue Oct 10, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@akmalhisyammm
Copy link

Hi, I have a problem with the connectPrinter method in BLEPrinter. When it fails to connect to the printer, it does not throw any error, so the application crashes while printing the receipt. I think this problem is quite crucial in the receipt printing process. Is there any alternative way to solve this problem?

@akmalhisyammm akmalhisyammm changed the title connectPrinter method in BLEPrinter is not throw any error when it fails to connect to the printer connectPrinter method of BLEPrinter does not throw any error when it fails to connect to the printer Oct 10, 2024
@akmalhisyammm akmalhisyammm changed the title connectPrinter method of BLEPrinter does not throw any error when it fails to connect to the printer The connectPrinter method of BLEPrinter does not throw any error when it fails to connect to the printer Oct 10, 2024
@thiendangit thiendangit added the enhancement New feature or request label Oct 11, 2024
@felixoakz
Copy link

Did anyone find a workaround for this?

I even did, using some then/catch, but it just stopped working when updated to android SDK to 34.

Basically printer works fine, but then app crashes if printer is turned off. With no way to catch error nor displaying unreachable BLE printer message to user whatsoever.

any help would be appreciated!
thanks in advance and have a great day you'all :)

@francesco-clementi-92
Copy link
Contributor

Can you show the code you are using to print?

@felixoakz
Copy link

Sure:

        try {
            if (isPrinting) return "Printing...";
            setIsPrinting(true);

            await BLEPrinter.closeConn();
            await BLEPrinter.connectPrinter(foundSettings.default_printer.inner_mac_address);
            BLEPrinter.printText(text);

            return "Text printed."
        } catch (err) {
            return "Printer disconnected, verify connection."
        } finally {
            setIsPrinting(false);
        }

This code prints ok, but wont fall to the catch exception (or any other) if printer is off. Tried some variations of this, with no success.

Thanks in advance for the help @francesco-clementi-92

@thiendangit
Copy link
Owner

To work around you can use a timeout to check you connect, if more than 3s (or any seconds) then return "disconnect" @francesco-clementi-92 @felixoakz

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

No branches or pull requests

4 participants