ramonlopes / jzebra

Automatically exported from code.google.com/p/jzebra
0 stars 0 forks source link

QZ issue or Java bug with setEncoding() #204

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I have found a bug on qz plugin or a Java limitation.
I cannot understand what might be causing losing the encoding set.
To reproduce the problem follow the next steps.
1. Use the code I have written below in order to setEncoding("CP869") for Greek 
chars and then print 2, 3 receipts. You will probably see the Greek chars 
printed normally. Greek chars look nothing like the chinese chars. So, you will 
be probably understand if they are actually printed fine or not.
2. Then unplug the printer, without turning it off and press the print button 
2-3 times on your app. The documents to be printed will be added in the queue 
of the printer.
3. Then plug in the computer and the 2-3 documents in the printer  will be 
printed fine. The Greek encoding will be fine.
4. Then first unplug again the printer and then turn the printer OFF.
5. Then press the print button on your app to execute the same script a couple 
of times. Once again the documents will queue as the printer is Offline.
6. Then Plug in the printer and turn the power of the printer to ON.
7. You will probably then see that the Greek encoding is not working. You will 
probably see the default encoding of the printer which in my case in Chinese. 
So Greek chars will look now like Chinese.
8. And the wierd thing now, is that if you go at the same app and press for a 
new print command you will see that from now on the chars will look like 
Chinese rather than Greek. It is like the setEncoding command that exists on 
the script, stopped working even though it exists on the script and also the 
Java console shows "INFO: Current printer charset encoding: IBM869" for the new 
printing commands.
9. The only way to set the printer the encoding that I want once again, is to 
reload my application.
And that is why I can not understand if this is a limitation of Java or qz bug.

What version of the product are you using? On what operating system?
1.8

The code that is executed each time the print button is pressed in my app is 
the following:
(Let me know if you see anything abnormal for ESC/P printing)

applet.setEncoding("CP869"); //Greek chars

applet.appendHex("x1Bx61x01"); // Centering

//The following is the correct WAY TO PRINT A BARCODE.  
applet.appendHex("x1Dx68x60");//Barcode height to 70 dots default is 165. The 
value must not ralate to other actions              
applet.appendHex("x1Dx6Bx04");
applet.append("1000000345");
applet.appendHex("x00");
applet.append("*** 1000000345 ***\r\n");
applet.appendHex(ResetStyles());

applet.appendHex("x1Bx61x01"); // Centering
                        applet.append("*********************************************** \r\n");
applet.append("Πληροφορίες: 42972\r\n");
applet.appendHex(MakeStyle(false, true, false, false, false));
//applet.appendHex(MakeStyle(10, false, false, false, false));
applet.appendHex(MakeStyle(false, false, false, true, false));
applet.append("ΠΛηροφορίες: Kommm\r\n");
applet.appendHex(ResetStyles());
applet.append("Ωράριο: 14:00 01/02\r\n");
applet.append("----------------------------------------------- \r\n");
applet.appendHex("x1Bx61x00");
applet.append("Info: 42972\r\n");
applet.append("Info: Kommm\r\n");

//This can be used only with one value true at a time
applet.appendHex(MakeStyle(false, false, false, false, false));
applet.appendHex(MakeStyle(false, true, false, false, false));
applet.append("Datum: 14:00 01/02\r\n");
applet.appendHex(ResetStyles());                                    
applet.append("----------------------------------------------- \r\n");

//Printing Image. single or double affects the streching of the image. 
//Print a google 
map                     applet.appendImage("http://maps.googleapis.com/maps/api/staticmap?cente
r=%CE%A5%CF%80%CE%B1%CF%84%CE%AF%CE%B1%CF%82%2014%2054351&zoom=16&scale=2&size=2
85x110&language=el&region=gr&format=png32&sensor=false&maptype=roadmap&style=fea
ture:landscape%7Celement:geometry.fill%7Ccolor:0x000000%7Cvisibility:on&style=fe
ature:administrative%7Celement:labels%7Cweight:3.9%7Cvisibility:on%7Cinvert_ligh
tness:true&style=feature:poi%7Cvisibility:simplified&&markers=mid:tiny%7Ccolor:y
ellow%7C%CE%A5%CF%80%CE%B1%CF%84%CE%AF%CE%B1%CF%82%2014%2054351", "ESCP", 
"double");

window["qzDoneAppending"] = function() {
// Append the rest of our commands
applet.appendHex(ResetStyles());
applet.appendHex("x1Bx61x01"); // Centering
applet.append("Το στίγμα ενδέχεται να μην είναι 
ακριβές!\r\n");
//Below some new line commands to cut the paper in the right height.
applet.append("\r\n");
applet.append("\r\n");
applet.append("\r\n");
applet.append("\r\n");
applet.append("\r\n");
applet.append("\r\n");
applet.append("\r\n");
applet.append("\r\n"); 
applet.append("\r\n");

applet.print();
cutPaper();

};
function chr(i) {       //The fromCharCode() method converts Unicode values into 
characters.
              return String.fromCharCode(i);
} 
function cutPaper() {
    if(!($("#cutterTogg option:first").prop("selected")))
              document.qz.append(chr(27) + chr(105));       // cuts paper
}

Original issue reported on code.google.com by adomv...@gmail.com on 14 Jan 2014 at 10:57

GoogleCodeExporter commented 8 years ago
function cutPaper() { //without the if statement in your case
              document.qz.append(chr(27) + chr(105));       // cuts paper
}

Original comment by adomv...@gmail.com on 14 Jan 2014 at 11:06

GoogleCodeExporter commented 8 years ago
Thank you for the detailed bug report.  The printer may be auto-detecting 
character encoding/character table.

What printer model do you have?  Is there a command to force a particular 
character table?

Here is a link to Epson ESC/POS character tables:
http://support.epson.ru/products/manuals/000350/part1.pdf#page=80

Let me know if this helps.

-Tres

Original comment by tres.fin...@gmail.com on 14 Jan 2014 at 2:49

GoogleCodeExporter commented 8 years ago
To set character table I used the command setEncoding("CP869"); as described on 
the code snippet.
The printer is an OEM Chinese POS printer that supports ESC/P commands.
Character encoding/character table are different things and are set with 
different commands?
Should I use any other commands in the beginning or end of the script is order 
to be able to set the encoding?

Thank you!

Original comment by adomv...@gmail.com on 14 Jan 2014 at 3:16

GoogleCodeExporter commented 8 years ago
> To set character table I used the command setEncoding("CP869"); as described 
on the code snippet.

That only sets encoding for Java.  Your printer's internal charset is not 
affected by this command.  You still have not stated which printer make/model 
you are using.

-Tres

Original comment by tres.fin...@gmail.com on 14 Jan 2014 at 3:35

GoogleCodeExporter commented 8 years ago
The printer is called XP-80C.
It is a Chinese printer simulating the EPSON printers.

About the setEncoding("CP869"); 
I thought it was also setting the encoding for the printer internally.

So I have to set the encoding to Greek with esc/p commands too.
I will take a look at the manual and I will let you know which commands did the 
job.
Do these commands differ from model to model of printer?

Thank you!

Original comment by adomv...@gmail.com on 14 Jan 2014 at 3:48

GoogleCodeExporter commented 8 years ago
> I thought it was also setting the encoding for the printer internally.

No, not in the current version.

> Do these commands differ from model to model of printer?

Yes, they can.  ESC/POS is pretty well established standard, but the 
manufacturer's implementation of it will vary.

The applet is also used for other languages such as EPL, CPCL, ZPL, FGL, DPL, 
but ESC/POS compatible printers tend to have a high compatibly rate with 
each-other (and they are usually advertised in this fashion).

-Tres

Original comment by tres.fin...@gmail.com on 14 Jan 2014 at 3:57

GoogleCodeExporter commented 8 years ago
I have added in the beginning of the code the following command to set encoding.
The following command seems to be dependent on my printer model. As other 
printer models have different command to set the character table.
applet.appendHex("x1Bx40x1Cx2E");
applet.appendHex("x1Bx21x00x6C");

Are you able to decode and understand the commands above? I have found them 
online and pasted and luckily they work.

These seems to be working, as the Greek chars are printed fine each time and 
also the bug I mentioned seems to have dissappeared.

The issue remaining now, is the fact the these 2 commands caused the barcode to 
stopped from being printed.

Could you please reproduce this on your printer if possible?
Or do you see any reason why the barcode stopped working?

Thank you!

Original comment by adomv...@gmail.com on 14 Jan 2014 at 6:25

GoogleCodeExporter commented 8 years ago
Without your programmer's guide, I cannot understand your commands.

I have an Epson TM88V I can test on, but you should probably post the question 
to jzebra-users@googlegroups.com as there are many experienced ESC/P users that 
don't look at the bug tracker.

-Tres

Original comment by tres.fin...@gmail.com on 14 Jan 2014 at 7:02

GoogleCodeExporter commented 8 years ago
Ok I will try ssending my script snippet there too.
Let me know if the barcode works on your Epson printer too if you can.
Thank you!

Original comment by adomv...@gmail.com on 14 Jan 2014 at 7:15

GoogleCodeExporter commented 8 years ago
@Anestis,

This took me a while, but was successful.  Here are my results:  
http://i.imgur.com/Djpso7D.jpg

I noticed a typo in your example. You sent the cut receipt command after you 
called print(), but instead, it should come before print().

I used setEncoding("IBM869") and then appendHex("x1Bx74x26")and the rest was 
straight forward.

The only command that may differ with your hardware is the x1Bx74x26.  I 
couldn't find a Greek character table reference documented for my hardware 
anywhere. So I took it upon myself to write a while loop printing Greek 
characters and incrimenting the command until I came to a working hex value of 
x26.

I believe older versions of ESCP had limited memory, so they only stored 4 
character table references in ram.  First, I tried experimented with the old 
syntax, which overwrites slot 0, 1, 2, 3 in RAM, since it offered backwards 
compatibility, but I couldn't get the command to do anything.

In addition, I show the examples using Greek as well as Escaped Unicode, which 
may help others down the road.

-Tres

function printGreek() {
    // Greek charset
    qz.setEncoding("IBM869");

    // Select character code table CP869, Table 38 on Epson TM88V (x26)
    // Format: <ESC> <GS> t <value>
    qz.appendHex("x1Bx74x26");

    // Left align
    qz.appendHex("x1Bx61x00");

    qz.append("Greek typed directly into text editor:\r\n");
    // Append greek text
    qz.append("   Πληροφορίες\r\n\r\n");

    qz.append("Greek encoded (ANSI safe):\r\n");
    // Append ansi-safe greek text, converted to unicode
    qz.append("   \u03A0\u03BB\u03B7\u03C1\u03BF\u03C6\u03BF\u03C1\u03AF\u03B5\u03C2\r\n\r\n");

    qz.append("Greek typed directly into text editor:\r\n");
    // Append greek text
    qz.append("  Το στίγμα ενδέχεται να μην είναι ακριβές\r\n\r\n");

    qz.append("Greek encoded (ANSI safe):\r\n");
    // Append ansi-safe greek text, converted to unicode
    qz.append("  \u03A4\u03BF \u03C3\u03C4\u03AF\u03B3\u03BC\u03B1 \u03B5");
    qz.append("\u03BD\u03B4\u03AD\u03C7\u03B5\u03C4\u03B1\u03B9 \u03BD");
    qz.append("\u03B1 \u03BC\u03B7\u03BD \u03B5\u03AF\u03BD\u03B1\u03B9 ");
    qz.append("\u03B1\u03BA\u03C1\u03B9\u03B2\u03AD\u03C2\r\n\r\n");
    // Feed 2 lines
    qz.append("\r\n\r\n");

    // Center Align
    qz.appendHex("x1Bx61x01");

    // Append a black and white image
    qz.appendImage(getPath() + 'img/image_sample_bw.png', 'ESCP', 'double');

    // Wait for image to finish appending
    window["qzDoneAppending"] = function () {
        // Feed 20 lines
        qz.append("\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n");
        qz.append("\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n");

        // Cut receipt
        qz.appendHex("x1Bx69");

        // Send commands to printer
        qz.print();

        // Remove reference to this function
        window["qzDoneAppending"] = null;
    };
}

Closing bug and marking as invalid.  Please re-open if you believe this was 
closed in error.

-Tres

Original comment by tres.fin...@gmail.com on 15 Jan 2014 at 4:52

GoogleCodeExporter commented 8 years ago
Issue 130 has been merged into this issue.

Original comment by tres.fin...@gmail.com on 20 Jan 2014 at 1:21

GoogleCodeExporter commented 8 years ago
Issue 88 has been merged into this issue.

Original comment by tres.fin...@gmail.com on 20 Jan 2014 at 1:21

GoogleCodeExporter commented 8 years ago
Issue 165 has been merged into this issue.

Original comment by tres.fin...@gmail.com on 20 Jan 2014 at 1:22