Javascript 管道hextump输出到节点js程序

Javascript 管道hextump输出到节点js程序,javascript,node.js,linux,intel,intel-edison,Javascript,Node.js,Linux,Intel,Intel Edison,我正在使用Yoctoo 3.10开发Intel Edison,我在/dev/hidraw0上有一个条形码扫描仪,我想使用运行hextump/dev/hidraw0时输出的精确行作为在node js中编写的程序的输入 0000000 0000 0020 0000 0000 0000 0000 0000 0000 0000010 0000 0020 0000 0000 0000 001f 0000 0000 0000020 0000 0027 0000 0000 0000 0026 0000 000

我正在使用Yoctoo 3.10开发Intel Edison,我在/dev/hidraw0上有一个条形码扫描仪,我想使用运行
hextump/dev/hidraw0
时输出的精确行作为在node js中编写的程序的输入

0000000 0000 0020 0000 0000 0000 0000 0000 0000
0000010 0000 0020 0000 0000 0000 001f 0000 0000
0000020 0000 0027 0000 0000 0000 0026 0000 0000
0000030 0000 0025 0000 0000 0000 0000 0000 0000
0000040 0000 0025 0000 0000 0000 0024 0000 0000
0000050 0000 0021 0000 0000 0000 0025 0000 0000
0000060 0000 0028 0000 0000 0000 0000 0000 0000
node js程序如下所示:

var readline = require('readline');
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

rl.on('line', function(line){
    console.log(line);
})
0000000 0000 0020 0000 0000 0000 0000 0000 0000
0000010 0000 0020 0000 0000 0000 001f 0000 0000
0000020 0000 0027 0000 0000 0000 0026 0000 0000
0000030 0000 0025 0000 0000 0000 0000 0000 0000
0000040 0000 0025 0000 0000 0000 0024 0000 0000
0000050 0000 0021 0000 0000 0000 0025 0000 0000
0000060 0000 0028 0000 0000 0000 0000 0000 0000
我试过正常使用管道:

hexdump /dev/hidraw0 | node program.js
0000000 0000 0020 0000 0000 0000 0000 0000 0000
0000010 0000 0020 0000 0000 0000 001f 0000 0000
0000020 0000 0027 0000 0000 0000 0026 0000 0000
0000030 0000 0025 0000 0000 0000 0000 0000 0000
0000040 0000 0025 0000 0000 0000 0024 0000 0000
0000050 0000 0021 0000 0000 0000 0025 0000 0000
0000060 0000 0028 0000 0000 0000 0000 0000 0000
但是我什么也没有得到,我认为这与hexdump不写\n所以缓冲区不写它的内容这一事实有关

0000000 0000 0020 0000 0000 0000 0000 0000 0000
0000010 0000 0020 0000 0000 0000 001f 0000 0000
0000020 0000 0027 0000 0000 0000 0026 0000 0000
0000030 0000 0025 0000 0000 0000 0000 0000 0000
0000040 0000 0025 0000 0000 0000 0024 0000 0000
0000050 0000 0021 0000 0000 0000 0025 0000 0000
0000060 0000 0028 0000 0000 0000 0000 0000 0000
我还尝试将/dev/hidraw0作为文件打开,如下所示:

var fs = require('fs');
fs.open('/dev/hidraw0', 'r', function(status, fd) {
    if (status) {
        console.log(status.message);
        return;
    }
    var buffer = new Buffer(100);
    fs.read(fd, buffer, 0, 100, 0, function(err, num) {
        console.log(buffer.toString('hex'));
    });
}); 
0000000 0000 0020 0000 0000 0000 0000 0000 0000
0000010 0000 0020 0000 0000 0000 001f 0000 0000
0000020 0000 0027 0000 0000 0000 0026 0000 0000
0000030 0000 0025 0000 0000 0000 0000 0000 0000
0000040 0000 0025 0000 0000 0000 0024 0000 0000
0000050 0000 0021 0000 0000 0000 0025 0000 0000
0000060 0000 0028 0000 0000 0000 0000 0000 0000
使用一些十六进制转储程序,比如hexy,但在本例中,我得到了一些十六进制行,但与hextump不同,这是我需要的

0000000 0000 0020 0000 0000 0000 0000 0000 0000
0000010 0000 0020 0000 0000 0000 001f 0000 0000
0000020 0000 0027 0000 0000 0000 0026 0000 0000
0000030 0000 0025 0000 0000 0000 0000 0000 0000
0000040 0000 0025 0000 0000 0000 0024 0000 0000
0000050 0000 0021 0000 0000 0000 0025 0000 0000
0000060 0000 0028 0000 0000 0000 0000 0000 0000
仅使用hextump/dev/hidraw0就可以得到以下信息 (当我使用卡片时)

0000000 0000 0020 0000 0000 0000 0000 0000 0000
0000010 0000 0020 0000 0000 0000 001f 0000 0000
0000020 0000 0027 0000 0000 0000 0026 0000 0000
0000030 0000 0025 0000 0000 0000 0000 0000 0000
0000040 0000 0025 0000 0000 0000 0024 0000 0000
0000050 0000 0021 0000 0000 0000 0025 0000 0000
0000060 0000 0028 0000 0000 0000 0000 0000 0000

以下是我的作品:

0000000 0000 0020 0000 0000 0000 0000 0000 0000
0000010 0000 0020 0000 0000 0000 001f 0000 0000
0000020 0000 0027 0000 0000 0000 0026 0000 0000
0000030 0000 0025 0000 0000 0000 0000 0000 0000
0000040 0000 0025 0000 0000 0000 0024 0000 0000
0000050 0000 0021 0000 0000 0000 0025 0000 0000
0000060 0000 0028 0000 0000 0000 0000 0000 0000
process.stdin.setEncoding('utf8');
process.stdin.on('readable', function () {
  var chunk = process.stdin.read();
  if (chunk !== null) {
    console.log(chunk);
  }
});
运行:

0000000 0000 0020 0000 0000 0000 0000 0000 0000
0000010 0000 0020 0000 0000 0000 001f 0000 0000
0000020 0000 0027 0000 0000 0000 0026 0000 0000
0000030 0000 0025 0000 0000 0000 0000 0000 0000
0000040 0000 0025 0000 0000 0000 0024 0000 0000
0000050 0000 0021 0000 0000 0000 0025 0000 0000
0000060 0000 0028 0000 0000 0000 0000 0000 0000
sudo hexdump /dev/hidraw0 | node this-script.js
示例输出(当我移动无线鼠标时):

0000000 0000 0020 0000 0000 0000 0000 0000 0000
0000010 0000 0020 0000 0000 0000 001f 0000 0000
0000020 0000 0027 0000 0000 0000 0026 0000 0000
0000030 0000 0025 0000 0000 0000 0000 0000 0000
0000040 0000 0025 0000 0000 0000 0024 0000 0000
0000050 0000 0021 0000 0000 0000 0025 0000 0000
0000060 0000 0028 0000 0000 0000 0000 0000 0000

仍然没有什么,知道运行lsusb设备被识别为以下内容可能会有所帮助:总线001设备002:ID 13ba:0018 PCP播放条形码PCP-BCG4209@NachoRasche,仅运行
hextump/dev/hidraw0
时会显示什么?我的意思是HID设备的状态应该在显示某些内容之前改变。你确定HID设备状态改变了吗(有东西要打印)?是的,只要运行hextump/dev/hidraw0就可以了,当我使用其中一张卡时,它会显示一些十六进制行(我在问题上编辑的那些),问题是当我尝试将此输出重定向到另一个程序时,它什么也不显示。我已经尝试将cat/dev/hidraw0的结果写入一个文件(cat/dev/hidraw0>out),然后hextump out,这也可以很好地工作,即使使用hextump out | node script.js工作,但只有当我使用hextump/dev/hidraw0 | node script.js直接重定向它时,它才不会工作(这是我想要的,因为我希望它能够实时工作)