我正在使用Yoctoo 3.10开发英特尔Edison,我在/ dev / hidraw0上有一个条形码扫描器,我想使用运行hexdump /dev/hidraw0
时输出的确切行作为程序的输入用节点js写的。
节点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);
})
我试过正常的管道:
hexdump /dev/hidraw0 | node program.js
但我什么都没得到,我认为这与hexdump不写的事实有关\ n因此缓冲区不会写出它的内容。
我也尝试将/ 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'));
});
});
使用像hexy这样的六角形翻斗车,但在这种情况下,我得到一些十六行,但与hexdump不同,这是我需要的。
只需使用hexdump /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
答案 0 :(得分:0)
以下适用于我:
process.stdin.setEncoding('utf8');
process.stdin.on('readable', function () {
var chunk = process.stdin.read();
if (chunk !== null) {
console.log(chunk);
}
});
运行:
sudo hexdump /dev/hidraw0 | node this-script.js
示例输出(当我移动无线鼠标时):
0000000 0120 0002 fd00 ffcf 0000 0000 0000 2000
0000010 0201 0000 cffc 00ff 0000 0000 0000 0120
...