【问题标题】:Save serialport list with meteor用流星保存串口列表
【发布时间】:2015-04-07 08:20:18
【问题描述】:

我在我的应用程序中使用串行端口包 (https://github.com/voodootikigod/node-serialport)。 这段代码在服务器上运行良好:

Meteor.startup(function () {
  SerialPort = Meteor.npmRequire('serialport');
});


Meteor.methods({
  serialPortsRefresh: function () {

    SerialPort.list(function (err, ports) {


      ports.forEach(function(port) {
        console.log(port.comName);
      }); 
// Config.insert(ports);
      return ports;
    });  

  }
});

现在我想将此列表保存在集合中以将其公开给客户端。 什么是最好的解决方案?

当我取消注释 Config.insert(ports);我有错误:

throw new Error("Meteor code must always run within a Fiber. " +  

提前致谢!

【问题讨论】:

  • 尝试使用 wrapasync 来避免光纤问题的运行。您可以在文档中找到它

标签: javascript meteor node-serialport


【解决方案1】:

感谢埃利泽! 这是我现在的代码(对我来说不是那么容易!):

Meteor.startup(function () {
  SerialPort = Meteor.npmRequire('serialport');
  listSerialPorts = function(callback) {
    SerialPort.list(function (err, ports) {
      callback(null, ports);
    });  
  }
});


Meteor.methods({
  serialPortsRefresh: function () {
    var ports = Meteor.wrapAsync(listSerialPorts);
    var result = ports();
    debugger;
  }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-19
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多