Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chinese ESCPOS Support #285

Closed
3 tasks done
tresf opened this issue Mar 13, 2018 · 14 comments
Closed
3 tasks done

Chinese ESCPOS Support #285

tresf opened this issue Mar 13, 2018 · 14 comments
Assignees
Milestone

Comments

@tresf
Copy link
Contributor

tresf commented Mar 13, 2018

We're adding support for more character sets in ESCPOS by testing -- and documenting various languages but we don't know the status of Chinese.

This is a placeholder to track the progress with printing chinese.

  • Chinese (中文)
    • Traditional
    • Simplified

Keywords: Chinese, printer, epson, programming, 中国打印机爱普生编程


Languages already supported: https://qz.io/wiki/Raw-Encoding#escpos

  • French (Français)
  • Spanish (Español)
  • Italian (Italiano)
  • Portuguese (Português)
  • German (Deutsche)
  • Greek (Ελληνικά)
  • Vietnamese (Tiếng Việt) (2.0.6+)
@tresf tresf added this to the 2.0.6 milestone Mar 13, 2018
@liushuyu
Copy link

Hi @tresf,

A quick search showed that first you might need a Chinese capable ESCPOS which contains a set of commands for Chinese only:

e.g.
Enter Hanzi (Kanji/Chinese character) mode:
1C 26
Exit Hanzi mode:
1C 2E

@tresf
Copy link
Contributor Author

tresf commented Mar 26, 2018

@liushuyu thanks. There's a printer on order from Alibaba. We will try this as soon as it arrives.
Edit: It arrived today, March 30st, 2018.

@tresf
Copy link
Contributor Author

tresf commented Apr 6, 2018

The printer arrived. I'm updating this ticket with some emails to the printer manufacturer.

We do not yet have a successful print. Here is the email conversation. Some items have been paraphrased for clarity.

Lite wrote (to manufacturer):

What I'm sending is this:

var data = [
   '艾德蒙 AOC E2450SWH 23.6吋\n',
   ' LED液晶寬螢幕特價$ 19900'
];

This picture is what the printer gives me. Is this correct Chinese? I'm sorry, but I cannot read or write Chinese. It looks like the first three characters become five characters [...]

Self-test says default codepage is GB18030

...

Manufacturer wrote (to Lite):

For your pictures, its is Chinese language. and our printer default font library is GB18030. Please do not worry.

For language setting, I just sent you the proper printer settings electronically. You can set the language in this printer setting tool.

@liushuyu
Copy link

liushuyu commented Apr 6, 2018

It's definitely not correct Chinese. The characters were from extension area (rarely used character), and you can see the length of original text is half the length of the printed text.

@liushuyu
Copy link

liushuyu commented Apr 6, 2018

And do note your test text is in Traditional Chinese, although it's also supported in gb18030 codec.

Here's a example of a short segment of Simplified Chinese:

这句话是简体中文

(This sentence is in Simplified Chinese)

@liushuyu
Copy link

liushuyu commented Apr 6, 2018

Hi,

I think I found something you may be interested:
This is your original text:

艾德蒙 AOC E2450SWH 23.6吋\n
 LED液晶寬螢幕特價$ 19900

And when you encode it with UTF-8:

In [16]: test = '''艾德蒙 AOC E2450SWH 23.6吋\n
    ...:  LED液晶寬螢幕特價$ 19900'''

In [17]: test.encode('utf-8')
Out[17]: b'\xe8\x89\xbe\xe5\xbe\xb7\xe8\x92\x99 AOC E2450SWH 23.6\xe5\x90\x8b\n\n LED\xe6\xb6\xb2\xe6\x99\xb6\xe5\xaf\xac\xe8\x9e\xa2\xe5\xb9\x95\xe7\x89\xb9\xe5\x83\xb9$ 19900'

Then decode the encoded sequence using GB18030 (which was encoded in UTF-8), Python will give a decode error since its codec is very strict and comply with the standard.
However, let's decode partial sequence (8 bytes) instead and see what happens:

In [18]: b'\xe8\x89\xbe\xe5\xbe\xb7\xe8\x92'.decode('gb18030')
Out[18]: '鑹惧痉钂'

The output is just what was printed out (first 4 characters).

And I think what happened was qztray sent the string in UTF-8 to the printer and the printer decoded the data using GB18030 codec, and since the decoder module in the printer is not very strict, so it produced garbage characters when printing the string.

@tresf
Copy link
Contributor Author

tresf commented Apr 6, 2018

@liushuyu I had assumed the problem was improper Java decoding but I'm awaiting some more information from Lite's testing. Thank you kindly for the research. It's exactly what I was suspecting when I saw his printout. :)

@liushuyu
Copy link

liushuyu commented Apr 6, 2018

@liushuyu I had assumed the problem was improper Java decoding but I'm awaiting some more information from Lite's testing. Thank you kindly for the research. It's exactly what I was suspecting when I saw his printout. :)

Thanks for your response, and I think that's "improper Java encoding" ? Since it was the printer that did the decode job :-)

@liushuyu
Copy link

liushuyu commented Apr 6, 2018

For the reference:

Text Hex (GB18030)
艾德蒙 AOC E2450SWH 23.6吋 b0acb5c2c3c920414f432045323435305357482032332e3685bc
这句话是简体中文 d5e2bee4bbb0cac7bcf2cce5d6d0cec4

@tresf
Copy link
Contributor Author

tresf commented Apr 6, 2018

@liushuyu perhaps, but I don't think so. Encoding is two-part. 1. Java, 2. Printer.

Here's my official write-up on it. https://qz.io/wiki/Raw-Encoding#background

Chinese is not unique. Java must convert UTF-8 to gb18030 first. Without Lite's code, it's impossible to know what was sent. Note, QZ Tray can be tested using a raw output file as well, which is useful for troubleshooting.

@lite1979
Copy link
Contributor

lite1979 commented Apr 6, 2018

Though using 'encoding: 'GB18030'" was not successful, I was successful using 'encoding: 'GBK''

The printer is Fukun POS80

First, I tried the Traditional Chinese sample:

function printESCPOS() {
        var config = qz.configs.create("Fukun", {encoding: 'GBK'});  //Toggle GBK in Java (GB18030 did not work) 

        var printData = [
            '\x1B' + '\x40',
            //'\x1B' + '\x74' + '\x0E', 
            '艾德蒙 AOC E2450SWH 23.6吋\n',
            ' LED液晶寬螢幕特價$ 19900',
            '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + `'\x0A',`
            '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A',
            '\x1B' + '\x69'          // cut paper
 
            
            
        ];

And achieved correct results:
traditionalchineseprint

I then tried the Simplified Chinese example provided by @liushuyu (thank you!):

function printESCPOS() {
        var config = qz.configs.create("Fukun", {encoding: 'GBK'});  //Toggle GBK in Java (GB18030 did not work) 

        var printData = [
            '\x1B' + '\x40',
            //'\x1B' + '\x74' + '\x0E', 
            '这句话是简体中文',
            '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A',
            '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A',
            '\x1B' + '\x69'          // cut paper
            
            
            
        ];

And results were again correct.
simplifiedchineseprint

My last question for this test:

If this printer were capable of printing GBK, but GBK was not the current codepage for the printer, how, using ESC/POS, would a user change the codepage to GBK?

I will test using Enter/Exit Hanzi mode as described by @liushuyu above.

@liushuyu
Copy link

liushuyu commented Apr 6, 2018

If this printer were capable of printing GBK, but GBK was not the current codepage for the printer, how, using ESC/POS, would a user change the codepage to GBK?

As you may have known, GBK is a compatible subset of GB18030 codec, or more precisely, GB18030 (a standard published in 2006) is an extension to the original GBK (only a recommendation published in 1995).

And GB18030 added partial Japanese and Korean support (Kanji Extension A area) but still backward compatible, that's why you can print out the text correctly using GBK encoding even though the printer's current codepage was GB18030.

EDIT:

@tresf tresf modified the milestones: 2.0.6, 2.0.7 Apr 7, 2018
@tresf
Copy link
Contributor Author

tresf commented May 21, 2018

Documented here: https://qz.io/wiki/Raw-Encoding#escpos-simplified-chinese. Closing.

@tresf tresf closed this as completed May 21, 2018
@tresf
Copy link
Contributor Author

tresf commented Jul 10, 2018

Just a status update, Lite got Traditional Chinese printing on Epson TM88V-631 which was pre-configured from Epson with "Big5" support. At the time of writing this, the US models of TM88V are incapable of printing "Big5" however the Chinese models can. Furthermore, the successor -- the TM88VI can also with firmware that can be loaded by any official Epson reseller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants