节点JS serialport@6.0.0打开端口并自动closures

我使用Node JS SerialPort@6.0.0包连接到计算机端口。

我写了这个代码来获取arduino-uno数据:

 const SerialPort = require('serialport'); const port = new SerialPort('COM4',{ baudRate: 9600 }); port.on('open', function(){ console.log("port open"); port.on('data', function(data){ console.log("Data:" + data); }) }) 

当它启动时,它会自动按顺序停止。 我已经使用了一个error handling程序,但没有显示错误。 而即时通讯使用serialport@4.0.0它的工作完美无瑕。

安慰