gpt4 book ai didi

Node.js 串行端口 - 类型错误 : "offset" is not an integer

转载 作者:太空宇宙 更新时间:2023-11-03 23:57:00 24 4
gpt4 key购买 nike

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

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 分支。

关于Node.js 串行端口 - 类型错误 : "offset" is not an integer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56627266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com