我在节点js上使用了以下代码。我想知道如何在节点js中获取连接的设备端口号。
var serialport = require('serialport');
var serialportRef = serialport.SerialPort;
var portname = process.argv[2];
var UAQPort = new serialportRef(portname,{baudRate:9600,
parser:serialport.parsers.readline("\r\n")});
serialport.list(function (err, ports) {ports.forEach(function(port) {
ports.forEach(function(port) {
console.log(port.comName);
});
});
console.log(port.comName);});
UAQPort.on('open',onOpen);
UAQPort.on('data',onData);
function onOpen(){
console.log('connected port');}
function onData(){
console.log('deveice data '+data);}