我已经复制了这段代码:
var serialport =require("serialport");
var SerialPort = serialport.SerialPort;
var portName = process.argv[2];
var myPort = new SerialPort(portName,{
baudRate: 9600,
parser:serialport.parsers.readline("\r\n")
})
myPort.on('open',onOpen);
myPort.on('data',onData);
function onOpen(){
console.log("Open connections!");
}
function onData(data){
console.log("on Data "+data);
}
来自这个视频:https ://www.youtube.com/watch?v=rhagmAv35Kk
我想将来自我的电脑的串行端口的数据流式传输到 NJS 代码中。当我运行代码时,出现此错误:
c:\njs>node main.js
C:\njs\main.js:7
parser:serialport.parsers.readline("\r\n")
^
TypeError: serialport.parsers.readline is not a function
at Object.<anonymous> (C:\njs\main.js:7:28)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
at run (bootstrap_node.js:352:7)
at startup (bootstrap_node.js:144:9)
at bootstrap_node.js:467:3
c:\njs>
有人知道为什么它无法识别该功能吗?