[英]Incorrect data received from serial port nodejs serial port module
I am trying to read from serial port that receives data from an Arduino nanodevice, I already have matlab implementation of it and it reads the correct data,我正在尝试从从 Arduino 纳米设备接收数据的串行端口读取数据,我已经实现了 matlab 并且它读取了正确的数据,
However, I am trying to migrate it to node js, and I am having following issue, The data that should be received as ']<N ÿÿ¢ ÿÿò½·½ÓïÏÜÔιõa' is actually getting received as ']<N�������������������P�k�z^�y|但是,我正在尝试将其迁移到节点 js,我遇到了以下问题,应该作为 ']<N ÿÿ¢ ÿÿò½·½ÓïÏÜÔιõa' 接收的数据实际上是作为 ']<N���� ��������������P�k�z^�y| zz{zz|{|��s?f���>oC���B�'
zz{zz|{|��s?f���>oC���B�'
The first frame above is how I am receiving it in matlab and therefore I am able to use it, in node js for some reason the whole frame is replaced by '?'.上面的第一帧是我在 matlab 中接收它的方式,因此我可以在节点 js 中使用它,由于某种原因,整个帧被替换为“?”。 especially characters such as 'ÿ' are replaced by '?'.
尤其是诸如“ÿ”之类的字符被替换为“?”。 I am using the serial port module used a read line parser the snippet looks like,
我正在使用串行端口模块使用读取行解析器片段看起来像,
myPort.on("data", data => {
console.log(data);
});
This definitely not a baudrate issue as other data is received perfectly.这绝对不是波特率问题,因为其他数据可以完美接收。 it has something to do with the encoding.
它与编码有关。
I was using the wrong parsers.我使用了错误的解析器。 The deadline parser was trying to read the bytes and converted the extended ascii characters into?.
截止日期解析器试图读取字节并将扩展的 ascii 字符转换为?。 Using byte parser fixed the issue.
使用字节解析器解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.