From 886c1480458b85fd07aa8bb57adc847d6b589956 Mon Sep 17 00:00:00 2001 From: Jam Date: Tue, 20 Oct 2015 00:43:59 +0100 Subject: [PATCH] fix mixup in error handling when opening a serialport connection --- lib/adaptors/serialport.js | 4 ++-- lib/sphero.js | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/adaptors/serialport.js b/lib/adaptors/serialport.js index afe3813..afc42b8 100644 --- a/lib/adaptors/serialport.js +++ b/lib/adaptors/serialport.js @@ -50,13 +50,13 @@ util.inherits(Adaptor, EventEmitter); */ Adaptor.prototype.open = function open(callback) { var self = this, - port = this.serialport = new serialport.SerialPort(this.conn, {}); + port = this.serialport = new serialport.SerialPort(this.conn, {}, false); function emit(name) { return self.emit.bind(self, name); } - port.on("open", function(error) { + port.open(function(error) { if (error) { callback(error); return; diff --git a/lib/sphero.js b/lib/sphero.js index d92e20c..49940c4 100644 --- a/lib/sphero.js +++ b/lib/sphero.js @@ -89,7 +89,11 @@ Sphero.prototype.connect = function(callback) { connection.on("open", emit("open")); - connection.open(function() { + connection.open(function(error) { + if(error) { + callback(error); + return; + } self.ready = true; connection.onRead(function(payload) {