2015-04-07 52 views
0

我在我的應用程序中使用serialport軟件包(https://github.com/voodootikigod/node-serialport)。 該代碼只是工作正常的服務器上:保存與流星的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(端口);我有錯誤:

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

在此先感謝!

+0

嘗試。你會在文檔中找到它 –

回答

1

謝謝埃利澤! 這裏是我的代碼現在(不是那麼容易的,我!):使用wrapasync避免在纖維問題來看

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