node-escpos / driver

🖨️ ESC/POS Printer driver for Node.js.
Other
317 stars 32 forks source link

Can't use printer.getStatus #72

Open romaia opened 1 year ago

romaia commented 1 year ago

As of version 0.4.0 of @node-escpos/core, I can´t find a way to actually use printer.getStatus due to the fact that the status classes are not exported.

YovanggaAnandhika commented 1 year ago

can u show your code example ?

zaycker commented 4 months ago
/**
   * get one specific status from the printer using it's class
   * @param  {string} StatusClass
   * @return {Promise} promise returning given status
   */
  getStatus<T extends DeviceStatus>(StatusClass: StatusClassConstructor<T>): Promise<T> {
    return new Promise((resolve) => {
      this.adapter.read((data) => {
        const byte = data.readInt8(0);
        resolve(new StatusClass(byte));
      });

      StatusClass.commands().forEach((c) => {
        this.buffer.write(c);
      });
    });
  }

The JSDOC declares that StatusClass should be a string but in the later code it uses the parameter as a constructor new StatusClass(byte). it's not PHP :) At the same time the module doesn't export status classes to be able to pass it as a parameter. As a result there is no way to use getStatus()