你好,我正在使用 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/