Search code examples
kotlincharacter-encodingescposescp

How to set character set using ESC/POS?


More specifically, what is the difference between ESC t and ESC R and when should i use them?

How does it tie with the character encoding of the byte arrays i may send to the printer?

Edit

As a follow-up,

  • the text to be printed is coming as ISO-8859-1 from the software and includes typical "Latin 1" Portuguese characters such as á é ã ç and
  • i'm setting ESC t to WPC1252 (0x10) and have also tried PC860 (0x03) to no avail
  • there is no ESC R that corresponds to Portuguese, so i tried
    • noy providing ESC R
    • using Spain I and II (0x07 and 0x0B respectively)

unsuccessfully.

I'm testing with multiple devices and the non-ASCII characters are always printed as "garbage".

A cheap Bluetooth printer prints Kanji characters, the test page shows "Codepage: GBK" but I can't find it in the reference; nor can i find "ANK" which is also referenced.

An Android device with built-in Bluetooth printer prints Greek characters and the test page says "Chinese mode: no" as well as
"Resident character:
Alphanumeric
GB1312<more kanji characters here>"

Edit

Ok, ANK is Alphabet Numeric Kana, so i assume Japanese.
GBK is Guojia Biaozhun and mostly Chinese.
Neither are relevant to me.


Solution

  • ESC t toggles characters in the range 0x80-0xFF.

    It is the main part of the process, the so-called code page or encoding.

    ESC R toggles some characters in the range 0x20-0x7E.

    Probably the handling of characters called the National Replacement Character Set.

    National Replacement Character Set - Wikipedia

    If necessary, you will need to combine and properly configure both to correspond to the code page and encoding.