DantSu / ESCPOS-ThermalPrinter-Android

Useful library to help Android developpers to print with (Bluetooth, TCP, USB) ESC/POS thermal printer.
MIT License
1.23k stars 376 forks source link

SUNMI "r" problem with a lots of test and extra infos #527

Open attilalenart opened 5 months ago

attilalenart commented 5 months ago

Dear @DantSu ,

Your lib is so nice, its work with the most POS printers, congrats. We used for a lot projects.

Ive a new issue with a SUNMI device, as i read some other customers has. Ofc first of all, i have read the issues here.

Most of them called an "r" problem: https://github.com/DantSu/ESCPOS-ThermalPrinter-Android/issues/509 https://github.com/DantSu/ESCPOS-ThermalPrinter-Android/issues/471 https://github.com/DantSu/ESCPOS-ThermalPrinter-Android/issues/317

Plus one, there is a tip: https://github.com/DantSu/ESCPOS-ThermalPrinter-Android/issues/204 Ive tested the suggested solution, its not working.

Below ive attached some photos about the test.

Some remark: On a full size receipt u see the "r" symbols. Its mostly at the line start and at the end. But if u look a little closer, u notice the field/column style blocks open and close tags marked by "r" char.

So, first plan was change the encoding. The lib built in encoding prints not working, but this info is online in two different docs. https://sunmi-ota.oss-cn-hangzhou.aliyuncs.com/DOC/resource/re_en/SunmiPrinter%20Developer%20documentation1.1.181207.pdf https://file.cdn.sunmi.com/SUNMIDOCS/%E5%95%86%E7%B1%B3%E5%86%85%E7%BD%AE%E6%89%93%E5%8D%B0%E6%9C%BA%E5%BC%80%E5%8F%91%E8%80%85%E6%96%87%E6%A1%A3EN-0224.pdf

If i changed the encodings the qr and barcode is printed perfect, but the texts are empty. This confirms that there is a problem with the char encoding. (cuz empty)

But! from the pdf-s only working with 15 and 16 encodings (15 "CP928"; 16 "Windows-1252";) otherwise texts are empty.

A lot times in the issues u asked the guys its the printer support ESCPOS, the answer is yes, on the pictures the qr barcode and other infomations are corrent. Only the open and close tags has a bug, or something else. https://ota.cdn.sunmi.com/DOC/resource/re_en/ESC-POS%20Command%20set.docx

Plus one more information, ive installed a RawBT application from Play store and printed a some ESCPOS examples. Do you have any ides, how to solve this problem?

IMG_1079 IMG_1078 IMG_1080 IMG_1081 IMG_1082

vikrammani-t2s commented 5 months ago

if text print not working na , can you use image printing

evgk commented 3 months ago

It seems the culprit of this problem is this piece of code in the library from printText function:

            if (!Arrays.equals(this.currentTextSize, textSize)) {
                this.printerConnection.write(textSize);
                this.currentTextSize = textSize;
            }

            if (!Arrays.equals(this.currentTextDoubleStrike, textDoubleStrike)) {
                this.printerConnection.write(textDoubleStrike);
                this.currentTextDoubleStrike = textDoubleStrike;
            }

            if (!Arrays.equals(this.currentTextUnderline, textUnderline)) {
                this.printerConnection.write(textUnderline);
                this.currentTextUnderline = textUnderline;
            }

            if (!Arrays.equals(this.currentTextBold, textBold)) {
                this.printerConnection.write(textBold);
                this.currentTextBold = textBold;
            }

            if (!Arrays.equals(this.currentTextColor, textColor)) {
                this.printerConnection.write(textColor);
                this.currentTextColor = textColor;
            }

            if (!Arrays.equals(this.currentTextReverseColor, textReverseColor)) {
                this.printerConnection.write(textReverseColor);
                this.currentTextReverseColor = textReverseColor;
            }

In case some of those commands are not supported by the printer, it might output that r character. It'll only output it once because the library only initializes it once, and saves the value into 'this.current...' variables. So you can fix it without forking if you would simply override printText function like that(Kotlin code):

class MyEscPosPrinterCommands(printerConnection: DeviceConnection?) :  EscPosPrinterCommands(printerConnection) {
    override fun printText(
        text: String?,
        textSize: ByteArray?,
        textColor: ByteArray?,
        textReverseColor: ByteArray?,
        textBold: ByteArray?,
        textUnderline: ByteArray?,
        textDoubleStrike: ByteArray?
    ): EscPosPrinterCommands {
        return super.printText(
            text,
            ByteArray(0),
            ByteArray(0),
            ByteArray(0),
            ByteArray(0),
            ByteArray(0),
            ByteArray(0)
        )
    }
}

Since the variables that it sets are initialized to ByteArray(0):

    private byte[] currentTextSize = new byte[0];
    private byte[] currentTextColor = new byte[0];
    private byte[] currentTextReverseColor = new byte[0];
    private byte[] currentTextBold = new byte[0];
    private byte[] currentTextUnderline = new byte[0];
    private byte[] currentTextDoubleStrike = new byte[0];

The Array.equals check above will return true then and the initialization will be skipped.