node.js serialport - TypeError: "offset" is not an integer

node.js serialport - TypeError: "offset" is not an integer

我正在尝试打开串口并读取传入数据:

const SerialPort = require('serialport');

var port = new SerialPort(
  "/dev/ttyUSB0",
  { baudRate: 115200 }
);

port.on('data', data => {
  console.log(data);
});

port.on('error', err => {
  console.log('Error', err);
});

port.on('close', err => {
  console.log('Closed', err);
});

每当新数据到达时,上面的示例都会失败并显示 TypeError: "offset" is not an integer

Closed { TypeError: "offset" is not an integer
    at LinuxBinding.read (/home/kristupas/projects/node-factory-worker/node_modules/@serialport/binding-abstract/binding-abstract.js:89:13)
    at LinuxBinding.read (/home/kristupas/projects/node-factory-worker/node_modules/@serialport/bindings/lib/linux.js:63:17)
    at SerialPort._read (/home/kristupas/projects/node-factory-worker/node_modules/@serialport/stream/stream.js:374:16)
    at SerialPort.Readable.read (_stream_readable.js:462:10)
    at maybeReadMore_ (_stream_readable.js:610:12)
    at processTicksAndRejections (internal/process/task_queues.js:81:17) disconnected: true }

我已经尝试 @serialport/terminal (source here) 并且它按预期工作,所以很明显我的代码有问题,但据我所知我正确地遵循了文档.

您使用的是哪个版本的串口?确保您没有使用 8.0.0 分支。