0
votes

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 !

1
Try using wrapasync to avoid the run in a fiber problem. You'll find it in the docs - Eliezer Steinbock

1 Answers

1
votes

Thanks Eliezer ! Here is my code now (not so easy for me !) :

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