javascriptprintingescposqz-tray

Change code page with ESC/POS on Birch printer


I am using QZ Tray tool to send raw data to thermal printer using ESC/POS commands. This is the code I'm using and it's working as expected on most printers:

data = [
    "\x1b\x40",
    "\x1b\x74\x49", // ESC t 73 - switch to Windows-1251
    text + "\r\n",
    "\x1B\x74\x48", // ESC t 72 - switch to Windows-1250
    text + "\r\n",
];

let config = qz.configs.create('printer_name', { encoding: 'windows-1251' });
qz.print(config, print_data).catch(function(e) {
    console.error(e);
});

The issues I am having are with Birch CP-Q3 printer. This printer doesn't seem to execute ESC t n command if the n is greater than 33. Like that it doesn't recognize those code pages. Command ESC t n works fine if the n is less than 33.

Strangest thing is that I can switch code page to 73 for example using printer tool, but it can't be done using ESC/POS commands. Printer self test also contains those code pages.

Is there a command that I should execute before changing code page or a printer configuration that I can change so that extended code pages can be used?


Solution

  • I emailed Birch-POS support and they say the following:

    Please suggest customer to use command \x1F\x1B\x1F\xFF\x49 to set codepage to windows-1251.

    Which matches the OPs wireshark comment, quoting:

    Using wireshark I managed to get the following HEX dump when setting code page 73 using printer tool: 1f 1b 1f ff 49 ...

    Unfortunately, JavaScript (specifically, UTF-8) does not like certain escape sequences over x7F.

    The working code should look like this:

    var text = 'Привет мир';
    
    // Use QZ's hex mode, which can workaround JavaScript not allowing certain hex values
    var data = [
       { 
        type: 'raw',
        format: 'command'
        flavor: 'hex',
        data: 'x1Fx1Bx1FxFFx49', // Instruct Birch POS: Windows-1251
        // data: 'x1Fx1Bx1FxFFx48', // Instruct Birch POS: Windows-1250
       },
       text + '\r\n'
    ];
    
    // Tell Java to use a strict 8-bit encoding
    var config = qz.configs.create('printer_name', { encoding: 'ISO-8859-1' });
    
    qz.print(config, print_data).catch(function(e) {
        console.error(e);
    });