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

SAM*_*SOL 5 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>
Run Code Online (Sandbox Code Playgroud)

我怎样才能将其解码为UTF8

阿尔杜伊诺

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); 

}


}
Run Code Online (Sandbox Code Playgroud)

std*_*b-- 2

在node.js中你可以使用toString

console.log(incomeBuffer.toString('utf8'))
Run Code Online (Sandbox Code Playgroud)

  • console.log(venueBuffer.toString('utf8')) 不起作用 (2认同)