DantSu / ESCPOS-ThermalPrinter-Android

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

Testing on Bixolon #475

Open albgen opened 9 months ago

albgen commented 9 months ago

hi There,

Really like this project because you can send "natural language" command instead of the ESC/POS :) My goal is to print on Bixolon printers. Currently i tested on SPP-R400 Printer (ESC/POS Command)

Seems though there is a problem with printing QR Codes. The following is what is printed: Bixolon SPP-R400 After this, the printer seems unstable and not usable. I need to switch it off and than back off in order to start to print.

Any idea? How to trobuleshoot?

thanks

albgen commented 9 months ago

Did another test with size of the QR code to 60 and it printed it correctly but only once. (Previous value was 20). image

Another test as well and this time some strange chars bixolo2

Another one bixolon3

Most of the times i see "Success, Congratulation! the text are printed!" but actually is not printing nothing.

albgen commented 9 months ago

After several tests, i notice that printing image and/or qrcode it breaks the printer somehow but don't know th reason.

DantSu commented 9 months ago

Hi, active ESC * command

albgen commented 9 months ago

Hi, active ESC * command

Hi, can you explain please? I'm not sure

DantSu commented 9 months ago

Look the doc :

Method : useEscAsteriskCommand(boolean enable)

Active "ESC *" command for image printing.

param boolean enable : true to use "ESC *", false to use "GS v 0"

return Printer : Fluent interface

albgen commented 9 months ago

thanks, i tried to enable the useEscAsteriskCommand and it seems a lot better but still it has issues. It printed 3 times ok, than 1 not ok, than 2 not ok, than 1 ok...

bixescon

DantSu commented 9 months ago

That's bluetooth problem. Sometime your connection lost data then error appear. Try to increase time.sleep between commands. Try to divide by 8 instead of 16.

https://github.com/DantSu/ESCPOS-ThermalPrinter-Android/blob/master/escposprinter/src/main/java/com/dantsu/escposprinter/connection/DeviceConnection.java

public void send(int addWaitingTime) throws EscPosConnectionException {
        if(!this.isConnected()) {
            throw new EscPosConnectionException("Unable to send data to device.");
        }
        try {
            this.outputStream.write(this.data);
            this.outputStream.flush();
            int waitingTime = addWaitingTime + this.data.length / 16; <======== HERE
            this.data = new byte[0];
            if(waitingTime > 0) {
                Thread.sleep(waitingTime);
            }
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
            throw new EscPosConnectionException(e.getMessage());
        }
    }
albgen commented 9 months ago

I changed and tried 4 times in a row and worked perfectly with no issues. Great!

Have a question regarding the alignement of the text and of the image. If you notice on the picture below, the image is not centered while the barcode and the QRCode are centered. image

Also, on the same image above: centering the text does not seem to work. It seems is considering in all cases a format of the paper smaller. Any idea?

Thanks.

DantSu commented 9 months ago

paste me your code.

albgen commented 9 months ago

it is the same written on the demo code. Did not changed anything

    @SuppressLint("SimpleDateFormat")
    public AsyncEscPosPrinter getAsyncEscPosPrinter(DeviceConnection printerConnection) {
        SimpleDateFormat format = new SimpleDateFormat("'on' yyyy-MM-dd 'at' HH:mm:ss");
        AsyncEscPosPrinter printer = new AsyncEscPosPrinter(printerConnection, 203, 48f, 32);
        // EscPosPrinter printer = new EscPosPrinter(printerConnection, 203, 48f, 32);
        return
               // printer.useEscAsteriskCommand(true);
                printer.addTextToPrint(
                        "[C]<img>" + PrinterTextParserImg.bitmapToHexadecimalString(printer, this.getApplicationContext().getResources().getDrawableForDensity(R.drawable.logo, DisplayMetrics.DENSITY_MEDIUM)) + "</img>\n" +
                                "[L]\n" +
                                "[C]<u><font size='big'>ORDER N°045</font></u>\n" +
                                "[L]\n" +
                                "[C]<u type='double'>" + format.format(new Date()) + "</u>\n" +
                                "[C]\n" +
                                "[C]================================\n" +
                                "[L]\n" +
                                "[L]<b>BEAUTIFUL SHIRT</b>[R]9.99€\n" +
                                "[L]  + Size : S\n" +
                                "[L]\n" +
                                "[L]<b>AWESOME HAT</b>[R]24.99€\n" +
                                "[L]  + Size : 57/58\n" +
                                "[L]\n" +
                                "[C]--------------------------------\n" +
                                "[R]TOTAL PRICE :[R]34.98€\n" +
                                "[R]TAX :[R]4.23€\n" +
                                "[L]\n" +
                                "[C]================================\n" +
                                "[L]\n" +
                                "[L]<u><font color='bg-black' size='tall'>Customer :</font></u>\n" +
                                "[L]Raymond DUPONT\n" +
                                "[L]5 rue des girafes\n" +
                                "[L]31547 PERPETES\n" +
                                "[L]Tel : +33801201456\n" +
                                "\n" +
                                "[C]<barcode type='ean13' height='10'>831254784551</barcode>\n" +
                                "[L]\n" +
                                "[C]<qrcode size='20'>https://dantsu.com/</qrcode>\n"
                );    
    }
DantSu commented 9 months ago

AsyncEscPosPrinter printer = new AsyncEscPosPrinter(printerConnection, 203, 100f, 72);

albgen commented 9 months ago

i tried with:

AsyncEscPosPrinter printer = new AsyncEscPosPrinter(printerConnection, 203, 111f, 32); where 111mm is the width and the result is as follows:

image Image is centered Barcode also centered The other elements seems not

DantSu commented 9 months ago

hmm ... try this :

AsyncEscPosPrinter printer = new AsyncEscPosPrinter(printerConnection, 203, 111f, 72); // <- 72

                                "[C]<barcode type='ean13' height='10'>831254784551</barcode>\n" +
                                "[L]blabla\n" +
                                "[C]<qrcode size='20'>https://dantsu.com/</qrcode>\n"
albgen commented 9 months ago

result with 72 No QR Code printed and and text align on the right broken. Most probably need to try with less than 72?

image

DantSu commented 9 months ago

ok 69

albgen commented 9 months ago

Seems perfect with 69. The only small issue is the QR Code which is aligned a little bit on the right instead if the center, right?

image

DantSu commented 9 months ago

Test this :

                                "[L]<barcode type='ean13' height='10'>831254784551</barcode>\n" +
                                "[L]blabla\n" +
                                "[C]<qrcode size='20'>https://dantsu.com/</qrcode>\n"
albgen commented 9 months ago

with:

 "[L]<barcode type='ean13' height='10'>831254784551</barcode>\n" +
  "[L]blabla\n" +
  "[C]<qrcode size='20'>https://dantsu.com/</qrcode>\n"

Result:

image

DantSu commented 9 months ago

ok, so it's command of barcode that move qrcode or images to the right... I will look for it.

albgen commented 9 months ago

Hello again,

just made some tests and if i send and ESC @ after the barcode, it is working as expected so QR Code is placed accordingly as the alignement used.

"[C]<barcode type='ean13' height='20'>831254784551</barcode>\n" +
"[L]blabla\n" + 
"[L]<qrcode size='40'>https://dantsu.com/</qrcode>\n"

image

image

without the ESC @ the result is image

btw i think is a problem on all devices and not only on Bixolon because the results are the same even on virtual device like the previous screenshot