node.js - 如何将串口传入的缓冲区数据转换为nodejs

标签 node.js node-serialport

你好,我正在使用 Arduino 和 Node js 我发送和接收数据,但从 arduino 传入的数据如下:

 <Buffer 00 00 00 e0 e0 e0 00 e0 e0 e0>

<Buffer e0 e0 e0 e0 00 e0 e0 00 e0 00 e0 e0 e0>

如何将其解码为 UTF8

Arduino

int incomingByte = 0;

void setup() {

Serial.begin(9600); // opens serial port, sets data rate to 9600 bps

}

void loop() {

if (Serial.available() > 0) {

incomingByte = Serial.read(); // read the incoming byte:

Serial.print(incomingByte); 

}


}

最佳答案

您可以使用readable.setEncoding Node SerialPort 类的方法:

const SerialPort =  require('serialport');

var port = new SerialPort("COM3").setEncoding('utf8');

关于node.js - 如何将串口传入的缓冲区数据转换为nodejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48077960/

相关文章:

javascript - 如何使用 express 和 fetch 打印来自服务器的响应?

node.js - Node sass : File to import not found or unreadable: ./node_modules/

javascript - 守护进程 Node.js 使用 Monit 每 60 秒失败一次

node.js - Node 串行端口的自定义解析器?

javascript - NodeJS串口检查端口是否存在功能不起作用

node.js - "Attribute ' 程序 ' does not exist"用于基本 node.js 项目

node.js - 使用 Node 串行端口的 NodeJS 有时会变得无响应

javascript - Meteor 1.5、johnny- Five、串口连接错误

javascript - 在带有 Webpack 的 Electron 渲染器中使用 Node.js 插件

javascript - 重写这个弗兰肯斯坦 promise 链