Node.js 串口通讯 node-serialport

安装:npm install serialport

使用:

var SerialPort = require('serialport');
var port = new SerialPort('COM5');

port.on('open', function() {
port.write('main screen turn on', function(err) {
if (err) {
return console.log('Error on write: ', err.message);
}
console.log('message written');
});
});

要发送byte数组把发送的'main screen turn on'改为[0x01,0x02]之类的byte数组
注:版本不同可能使用方式不同,当前使用的版本是7.1.4
官方文档4.0.1地址:https://github.com/node-serialport/node-serialport/blob/4.0.1/README.md

猜你喜欢

转载自www.cnblogs.com/TLScott/p/10358534.html
今日推荐