【问题标题】:Getting Status of a usb printer on linux nodejs在 linux nodejs 上获取 USB 打印机的状态
【发布时间】:2020-06-25 19:45:27
【问题描述】:

在过去的 3 天里,我刚刚在互联网上搜索以使其正常工作。 我只需要在 /dev/usb/lp0 下找到 USB 热敏打印机上的纸张状态。

将我的代码减少到人类消费的最低限度我有这个:


const escpos = require('escpos');
escpos.USB = require('escpos-usb');
const device  = new escpos.USB();


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);
});

作为回应,我得到:

/root/totem/ser.js:9
    device.device.on('data', function (data) {
                  ^

TypeError: device.device.on is not a function
    at /root/totem/ser.js:9:19
    at Interface.<anonymous> (/root/node_modules/escpos-usb/index.js:142:23)
    at Device.<anonymous> (/root/node_modules/usb/usb.js:341:6)

以下修正建议

device.device.on
to 
device.on 

我现在明白了:

root@raspberrypi:~/totem# node ser.js
Received:


Received:


Received:


Received:
<Buffer >

root@raspberrypi:~/totem#

而不是得到一个告诉我状态的字节

【问题讨论】:

    标签: node.js linux raspberry-pi escpos


    【解决方案1】:

    代替

    设备.设备

    使用

    device.on('数据' ...

    【讨论】:

    • 谢谢,我已经按照建议更正了,但还是不行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多