SerialPort没有方法'列表'

时间:2013-01-27 18:49:02

标签: javascript node.js serial-port node-serialport

我有一个非常简单的脚本,只有可用的串口,然后连接到一个,写一个字符并将响应放在控制台上。 CODE HERE

在我的脚本目录中,我做了:

#npm install serialport
#npm list
 /home/uminded/Programming/nodeJS/test
 └─┬ serialport@1.0.8
   ├── async@0.1.18
     etc...
#node test.js
   spits out entire serialport.js to command line then...
 has no method 'list'
 at Object.<anonymous> (/home/uminded/Programming/nodeJS/test/test.js:4:12)
 at Module._compile (module.js:449:26)
 at Object.Module._extensions..js (module.js:467:10)
 at Module.load (module.js:356:32)
 at Function.Module._load (module.js:312:12)
 at Module.runMain (module.js:492:10)
 at process.startup.processNextTick.process._tickCallback (node.js:244:9)

serialport.js脚本确实有Seri​​alPort.list的导出,为什么找不到它?

你们用什么程序来编写和调试节点相关的js?

1 个答案:

答案 0 :(得分:14)

listproperty of the serialport module,而不是serialport.SerialPort。替换第一行,如下所示:

var serialport = require("serialport");
var SerialPort = serialport.SerialPort;
var util = require("util"), repl = require("repl");

serialport.list(function (err, ports) {
  ports.forEach(function(port) {
    console.log(port.comName);
    console.log(port.pnpId);
    console.log(port.manufacturer);
  });
});