From 4b73a92f71612f61b251e46af09132b70f5426af Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Sat, 4 Oct 2014 22:56:52 +0100 Subject: [PATCH] Cross platform fix for Arduino Serial port not there. Fix for #428 --- nodes/core/hardware/35-arduino.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/nodes/core/hardware/35-arduino.js b/nodes/core/hardware/35-arduino.js index 206fa9c75..795e99074 100644 --- a/nodes/core/hardware/35-arduino.js +++ b/nodes/core/hardware/35-arduino.js @@ -20,6 +20,9 @@ module.exports = function(RED) { var ArduinoFirmata = require('arduino-firmata'); var fs = require('fs'); var plat = require('os').platform(); + var portlist = ArduinoFirmata.list(function (err, ports) { + portlist = ports; + }); // The Board Definition - this opens (and closes) the connection function ArduinoNode(n) { @@ -29,15 +32,10 @@ module.exports = function(RED) { //node.log("opening connection "+this.device); var node = this; node.board = new ArduinoFirmata(); - if (!plat.match(/^win/)) { // not Windows - if (!fs.existsSync(node.device)) { - node.warn("Device "+node.device+" not found"); - } - else { - node.board.connect(node.device); - } + if (portlist.indexOf(node.device) === -1) { + node.warn("Device "+node.device+" not found"); } - else { // Windows - try to connect anyway... this can be bad... + else { node.board.connect(node.device); }