你好我使用的是Arduino和节点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);
}
}
答案 0 :(得分:1)
在node.js中,您可以使用toString
:
console.log(incomeBuffer.toString('utf8'))
答案 1 :(得分:0)
答案 2 :(得分:0)
您可以使用Node SerialPort类中的readable.setEncoding
方法:
const SerialPort = require('serialport');
var port = new SerialPort("COM3").setEncoding('utf8');