From e2ece7fe5d753f0c69556910f71ed1b86161e18d Mon Sep 17 00:00:00 2001 From: noopkat Date: Mon, 7 Dec 2015 18:38:24 -0800 Subject: [PATCH] add port sniffing fallback for linux/win leo reset port hopping risks --- lib/connection.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/connection.js b/lib/connection.js index e30d314..9789a98 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -117,8 +117,21 @@ Connection.prototype._pollForPort = function(callback) { if (tries < 4) { setTimeout(checkList, delay); } else { - // timeout on too many tries - return callback(new Error('could not reconnect after resetting board.')); + // try to sniff port instead (for port hopping devices) { + _this._sniffPort(function(error, port) { + if (port.length) { + // found a port, save it + _this.options.port = port[0].comName; + + // set up serialport for it + _this._setUpSerial(function(error) { + return callback(error); + }); + } else { + // timeout on too many tries + return callback(new Error('could not reconnect after resetting board.')); + } + }); } }); }