diff --git a/lib/board.js b/lib/board.js index 770d4c8..0712e56 100644 --- a/lib/board.js +++ b/lib/board.js @@ -71,38 +71,28 @@ util.inherits(Board, events.EventEmitter); Board.prototype.detect = function (callback) { this.log('info', 'attempting to find Arduino board'); var self = this; - child.exec('ls /dev | grep usb', function(err, stdout, stderr){ - var usb = stdout.slice(0, -1).split('\n'), - found = false, - err = null, - possible, temp; - while ( usb.length ) { - possible = usb.pop(); + serial.list(function (err, ports) { + ports.forEach(function(port) { + + + if(port.manufacturer.indexOf("Arduino") != -1) + { - if (possible.slice(0, 2) !== 'cu') { try { - temp = new serial.SerialPort('/dev/' + possible, { - baudrate: 115200, - parser: serial.parsers.readline('\n') - }); + var sp = new serial.SerialPort(port.comName, { + baudrate: 115200, + parser: serial.parsers.readline('\n') + }); + + callback(null, sp ); } catch (e) { - err = e; - } - if (!err) { - found = temp; - self.log('info', 'found board at ' + temp.port); - break; - } else { - err = new Error('Could not find Arduino'); + callback(e, null); } } - } - - callback(err, found); + }); }); } - /* * The board will eat the first 4 bytes of the session * So we give it crap to eat