diff --git a/lib/board.js b/lib/board.js index a1acf89..d29c202 100644 --- a/lib/board.js +++ b/lib/board.js @@ -32,7 +32,7 @@ var Board = function (options) { self.emit('data', data); }); - setTimeout(function(){ + self.serial.on('open', function() { self.log('info', 'board ready'); self.sendClearingBytes(); @@ -53,8 +53,10 @@ var Board = function (options) { self.processWriteBuffer(); } - self.emit('ready'); - }, 500); + setTimeout(function() { + self.emit('ready'); + }, 500); + }); } }); } @@ -92,7 +94,7 @@ Board.prototype.detect = function (callback) { } if (!err) { found = temp; - self.log('info', 'found board at ' + temp.port); + self.log('info', 'found board at ' + temp.path); break; } else { err = new Error('Could not find Arduino'); diff --git a/lib/servo.js b/lib/servo.js index de61334..2ef569d 100644 --- a/lib/servo.js +++ b/lib/servo.js @@ -18,10 +18,15 @@ var Servo = function (options) { moved: true }; - this.board.on('ready', function () { - console.log('board ready, attaching servo', this); + if (this.board.serial && this.board.serial.readStream) { + console.log('board already ready, attaching servo', this); this.attach(); - }.bind(this)); + } else { + this.board.on('ready', function () { + console.log('board ready, attaching servo', this); + this.attach(); + }.bind(this)); + } this.board.on('data', function (message) { var m = message.slice(0, -1).split('::'),