I'm working with QZ tray to do raw printing with ESC/P (not ESC/POS) printer 9pin [1]. Basically everything works fine, until I have to set absolute horizontal position (ESC $).

the problem same with [2], but it use Java, and QZ tray using JavaScript for its example [3], and declare all the command using hexadecimal escape sequence (\xFF) [4], character from 0 - 255 (\x00 - \xFF).

here's detail about problem:

  1. set absolute horizontal position in 9-pin ESC/P [1]

    ASCII: ESC $ nL nH
    Hex:   1B 24 nL nH  
    0 <= nH <= 127
    0 <= nL <= 255
    
  2. send data to QZ tray without problem if nL value 0 to 127.

    var data = [
        '\x1B' + '\x40',                    // init
    
        '\x1B' + '\x24' + '\x10' + '\x00',  // set horizontal
        '0x10' + '\x0D' + '\x0A',           // print position ok
    
        '\x1B' + '\x24' + '\x7F' + '\x00',  // set horizontal
        '0x7F' + '\x0D' + '\x0A',           // print position ok
    
        '\x1B' + '\x24' + '\x80' + '\x00',  // set horizontal
        '0x80' + '\x0D' + '\x0A',           // print position PROBLEM
    
        '\x1B' + '\x24' + '\x00' + '\x01',  // set horizontal
        '1x00' + '\x0D' + '\x0A',           // print position ok
    
    ]
    

    how to represent character 128 using hexadecimal escape sequence, if '\x80' + '\x00' was incorrect?

  3. I tried to use JavaScript typed array Uint8Array and Uint16Array, not successfully printed, I think it's because the ESC/P protocol want it as characters (array).

I have tried to search on QZ groups and stackoverflow, but it is quite hard to find the correct keyword.

any help would be appreciated. thank you.

[1]https://files.support.epson.com/pdf/general/escp2ref.pdf

[2]ESC/P Set Absolute Horizontal Print Position

[3]https://qz.io/wiki/2.0-raw-printing

[4]https://mathiasbynens.be/notes/javascript-escapes#hexadecimal

2

There are 2 best solutions below

0
On

Force ISO-8859-1 encoding and use the raw hex object notation.

var config = qz.configs.create(printer, {encoding: 'ISO-8859-1'});

var data = [
   '...',
   '\x1B' + '\x24' + '\x80' + '\x00',  // set horizontal

   ///// RAW HEX OBJECT NOTATION /////
   { type: 'raw', format: 'hex', data: 'x80x0Dx0A' } 
   //'0x80' + '\x0D' + '\x0A',           // print position PROBLEM

   '\x1B' + '\x24' + '\x00' + '\x01',  // set horizontal
   '1x00' + '\x0D' + '\x0A',           // print position ok
   '...',
]

Note, this is the same general answer as proposed by @oon-arfiandwi, but typed out in code.

0
On

To help someone with this problem, basically I got answer from the qz-print mailing list, this is a known bugs. (but it would be hard to find the keyword, because it is about the raw encode bug).

the simplest solution for this (raw printing) with add encoding ISO-8859-1 so it would not use UTF-8 (which make character 128-255 as 2 bytes).

var config = qz.configs.create(printer, {encoding: 'ISO-8859-1'});

one other solution for this is using print raw with hex format. [1]https://qz.io/wiki/2.0-Raw-Printing#hex

here's the discussion on the mailing list: [2]https://groups.google.com/forum/#!topic/qz-print/TE0D-wsRDRg

here's the discussion before about the bug: [3]https://groups.google.com/forum/#!topic/qz-print/r3VGPDaYKKE

and last one, here's the github issue, if you want to track it someday it solved. [4]https://github.com/qzind/tray/issues/155