EPSONePOS / ePOS

EPSON ePOS Printer Sample
27 stars 4 forks source link

Calling `addImage` on Impact Printer #12

Open tjolsen-vn opened 2 months ago

tjolsen-vn commented 2 months ago

For some reason when I send a print command on a U220, addImage() isn't working as I would expect The printer doesn't seem to respect the paper width: IMG_2264

I've tried changing the width of the bitmap, but the image is still huge, it just doesn't print the full width of the paper. For example: IMG_2265

For the U220, I set up my printer like:

Printer(Printer.TM_U220, Printer.MODEL_ANK, context)

For the TM T88VII, I set up the printer like:

Printer(Printer.TM_T88, Printer.MODEL_ANK, context)

Then I call addImage():

            printer.addImage(
                printImage,
                0,
                0,
                printImage.width,
                printImage.height,
                Printer.PARAM_DEFAULT,
                Printer.PARAM_DEFAULT,
                Printer.PARAM_DEFAULT,
                3.0,
                Printer.COMPRESS_AUTO,
            )

Things work as expected on the thermal printer, but not the impact. Another interesting note, if I do Printer(Printer.TM_T88, Printer.MODEL_ANK, context) when sending a command to the U220, it fails to connect. If I do Printer(Printer.TM_U220, Printer.MODEL_ANK, context) for the TM T88VII, it will connect, but print the image blown up like in the impact prints above.

This could very well be a me issue but I'd really appreciate some guidance.

tjolsen-vn commented 2 months ago

Also, doing text based printing with:

printer.addText(text)

works as far as sizing. But it is much harder to maintain good word wrapping and text styles. It would be much better for us to be able to move away from this text based printing and move forward with bitmap printing (we create the bitmap with html which is much easier to style).

tjolsen-vn commented 2 months ago

Also tried doing things this way:

    fun createNewOrderChit(
        context: Context,
        order: Order,
        isSuites: Boolean,
    ) {
        Log.d("PRINT_TEST", "Calling createNewOrderChit...")
        val print = Print(context)

        try {
            val printerOrderData = order.toPrinterOrderData(context.resources, isSuites)
            val printImage = imageFactory.createOrderChitBitmapImage(
                context,
                printerOrderData,
                PrinterType.fromValue(order.printerType ?: ""),
            )

            if (printImage == null) {
                Log.e("TEST_PRINT", "print image is null")
                return
            }

//            val model = "TM-T88VI"
            val model = "TM-U220"
            val builder =  Builder(model, Builder.MODEL_ANK)

            builder.addImage(
                printImage,
                0,
                0,
                printImage.width,
                printImage.height,
                Printer.PARAM_DEFAULT,
                Printer.PARAM_DEFAULT,
                Printer.PARAM_DEFAULT,
                3.0,
                Printer.PARAM_DEFAULT,
            )

            // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            builder.addCut(Printer.CUT_FEED)

            val printStatusArray = intArrayOf(0)
            val batteryStatusArray = intArrayOf(0)
            print.openPrinter(Print.DEVTYPE_TCP, ipAddress)
            print.getStatus(printStatusArray, batteryStatusArray)
            print.beginTransaction()
            print.sendData(builder, 10000, printStatusArray)
            print.endTransaction()
            print.closePrinter()
        } catch (e: Exception) {
            CrashlyticsHelper.logException(e)
            PrinterLogger.logException(e, "createOrderChit", context)
            Log.e("PRINT_TEST", e.message, e)
        }
    }

As a quick test. Switching between the printer models. This also works for the TM-T88VI, but this way I get no print at all for the U220B.

tjolsen-vn commented 2 months ago

@EPSONePOS Any insights?

tjolsen-vn commented 2 months ago

I'm getting the model names from here: https://github.com/EPSONePOS/ePOS/blob/master/ePOSPrint/src/main/res/values/strings.xml