Search code examples
node.jsprintingescpos

Epson thermal printer status from NodeJS with ESC/POS


I have created an Electron app to configure and launch a NodeJS printer server. The NodeJS part is using https://github.com/song940/node-escpos to send ESC/POS command to an Epson thermal printer on a serial port. That's work fine, I am able to print something.

Now, I am trying to get real-time status from the printer (printer status or roll paper sensor status or ink status). There is an ESC/POS command DLE EOT: https://www.epson-biz.com/modules/ref_escpos/index.php?content_id=118

I tried something like this, using node-serial object (node-escpos dependency) to be able to read a return (device.device.on(...)):

const escpos = require('escpos');
const _ = require('escpos/commands');

const device = new escpos.Serial('COM1');
const printer = new escpos.Printer(device);

device.open(function (err) {
    device.device.on('data', function (data) {
        console.log(data);
        console.log(data.toString('hex'));
    });

    device.write(_.DLE);
    device.write(_.EOT);
    device.write(String.fromCharCode(1));

    setTimeout(() => {
        printer.close();
    }, 1000);
});

But the result doesn't seem to match the doc, I got:

{ type: 'Buffer', data: [ 22 ] }
16

Does anybody ever try this? Am I misunderstanding the Epson's documentation?

Thank you


Solution

  • It seems that the obtained value is appropriate.

    The value of Printer status (n = 1): you got is 0x16, and it is 0b00010110 in binary, and it is as follows when it is applied to the description of the document.

    0:Fixed
    1:Fixed
    1:Drawer kick-out connector pin 3 is HIGH
    0:Online
    1:Fixed
    0:Not waiting for online recovery
    0:Paper feed button is not being pressed
    0:Fixed