0

I use the serialport package in my app (https://github.com/voodootikigod/node-serialport). This code is just working fine on the server :

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;
    });  

  }
});

Now i want to save this list in a collection to expose it to the client. What is the best solution ?

When i uncomment Config.insert(ports); i've the error :

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

Thanks in advance !

4

1 回答 1

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;
  }
});
于 2015-04-07T10:20:47.467 回答