PhomemoのESC/POSコマンドについて調べてみる

Phomeoのコマンドを解析しているGitのページ

github.comreceiptline-master\designer\pr.jsの内容

const ESC = 0x1B;
port = await navigator.serial.requestPort();
await port.open({ baudRate: 115200 });
writer = port.writable.getWriter();
await writer.write(new Uint8Array([ESC, 0x40, 0x02])); // reset

const conn = ReceiptSerial.connect({ baudRate: 9600 });
conn.on('status', status => {
    console.log(status);
});
conn.on('ready', async () => {
    const result = await conn.print(markdown, '-c 42');
});

const ESC = 0x1B; でESCを0x1Bに変換している?

await writer.write(new Uint8Array([ESC, 0x40, 0x02])); // reset

でプリンタのリセットをしている。

Gitから

3. Protocol for M02

After dumpping bluetooth packets, it appears to be EPSON ESC/POS Commands.
3.1. HEADER

  0x1b 0x40      -> command ESC @: initialize printer
  0x1b 0x61      -> command ESC a: select justification
  0x01           range: 0 (left-justification), 1 centered,
                        2 (right justification)
  0x1f 0x11 0x02 0x04           

となっているので、Phomemoでもリセットコマンドが実施されているはず。

Gitから

3.3. FOOTER

  0x1b 0x64      -> command ESC d : print and feed n lines
  0x02           number of line to feed
  0x1b 0x64      -> command ESC d : print and feed n lines
  0x02           number of line to feed
  0x1f 0x11 0x08
  0x1f 0x11 0x0e
  0x1f 0x11 0x07
  0x1f 0x11 0x09

となっているので、同ヶ所を

await writer.write(new Uint8Array([ESC, 0x64, 0x02]));

として、印刷してフィードされるか試してみるが何も起きなかった。

(レシートプリンターで実施しても変化なかったので、pr.jsは現在の使い方では反映されない?)

receiptline-master\designer\receipt-printer.js

に、用紙カットのコマンドが記述されている。

// cut paper: ESC d n
        cut() {
            return '\x1bd3';
        },

Gitにある用紙送りのコマンドと同じみたいなので、printer.jsonで用紙カットを有効にすればコマンドは送信されると思われるが実行しても用紙送りはされない。

 

レシートプリンタを接続後TeraTermにてシリアルポートに接続してESCキー押下後に”d””n”を押すと用紙送りされるが、Phomemoは何も起きないコマンド受付できていない?

レシートプリンタでは、returnキーで1行づつ用紙送り(ESCキー押下後に”d””n”では10cmほど)されるので制御方法がちがう?(Gitのコマンド解析が間違っている?

)Gitの内容をもっと確認する必要が有りそう。

印刷前後に

0x1b 0x40      -> command ESC @: initialize printer

を実行等できれば動作も安定しそうなんだけど。

実使用に不便が無い程度にはなったので、のんびり調べよう。