2017-02-16 66 views
0

我嘗試使用這兩個庫以檢測NFC標籤(https://github.com/mitchellparsons/rc522-rfid-promise),並控制上的樹莓裨一個MPD服務器(https://github.com/andrewrk/mpd.js)。我在Raspbian Jessie上使用Node v6.9.5(2017-01-11)。回調庫都阻斷節點

當執行下面的代碼僅執行MPD監聽器。有沒有我做錯了或誤解了Nodejs的概念?

var mpd = require('mpd') 
var rc522 = require("rc522-rfid-promise") 

var client = mpd.connect({ 
    port: 6600, 
    host: 'localhost', 
}) 

rc522.startListening() 
    .then(function(rfidTag){ 
    console.log('Got RFID tag') 
}) 

client.on('ready', function() { 
    console.log("MPD ready") 
}) 

謝謝!

回答

1

嘗試監聽的錯誤事件:

client.on('error', function (err) { 
    console.log('Error:', err) 
}); 
+0

錯誤事件不會解僱了。我現在使用另一個庫(https://github.com/ocsacesar/rc522),並通過https://github.com/weixiyen/messenger.js解耦NFC閱讀器和主邏輯 – Philluxx