0

I am trying to print a turn number from my android kiosk/tablet. User just presses on an image button and the turn should be printed. The kiosk connects to a USB Epson TM-T20 printer.

I downloaded the sample EPOS2_Printer app that epson provides, and I built it's APK, it works fine on the kiosk, so I am trying to use its code and integrate it into what I am trying to do. The problem is I am unable to get the printer to be discovered and selected without user interaction.

The sample EPSON provides has a DiscoveryActivity, where the app searches for connected devices, you select the one you want from search results and that takes you back to main activity with the target field pre-filled. I am trying to stay in the same activity, and onClick, do the discovery and get target (only 1 printer) and print to it.

Reading this: Epson printer connect fails status ERR_CONN the comment below says to use Discover.start to get the target, but how can you integrate that with Printer.connect?

I can share code, just wanted to be as short as possible here.

Any help is appreciated!

Sam
  • 73
  • 1
  • 9

1 Answers1

2

Share your code, please

Did you try something like this?

    printer = new Print(getApplicationContext());

    try {
        // Open 
        printer.openPrinter(
            connectionType,
            openDeviceName,
            Print.FALSE,
            Print.PARAM_DEFAULT,
            Print.PARAM_DEFAULT);
    }
    catch (EposException e) {
        result.setEposException(e);
        return;
    }

    try {
        // Print data if printer is printable 
        printer.getStatus(printerStatus, batteryStatus);
        result.setPrinterStatus(printerStatus[0]);
        result.setBatteryStatus(batteryStatus[0]);

        if (isPrintable(result)) {
            printerStatus[0] = 0;
            batteryStatus[0] = 0;

            printer.beginTransaction();
            isBeginTransaction = true;

            printer.sendData(builder, sendTimeout, printerStatus, batteryStatus);
            result.setPrinterStatus(printerStatus[0]);
            result.setBatteryStatus(batteryStatus[0]);
        }
    }
    catch (EposException e) {
        result.setEposException(e);
    }
    finally {
        if (isBeginTransaction) {
            try {
                printer.endTransaction();
            }
            catch (EposException e) {
                // Do nothing
            }
        }
    }

    try {
        printer.closePrinter();
    }
  • 2
    Thank you for your reply. I was able to work around the issue by adding a DiscoveryListener and save the target printer in a String: target = deviceInfo.getTarget(); That String returned the USB port address. Then I connected using mPrinter.connect(target, Printer.PARAM_DEFAULT) – Sam Mar 09 '18 at 15:55
  • what is the `result` ? Where is `isPrintable()` method implementation? – Oleksandr Nos Oct 07 '19 at 08:40