1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Cross platform fix for Arduino Serial port not there.

Fix for #428
This commit is contained in:
Dave C-J 2014-10-04 22:56:52 +01:00
parent e95d4a9010
commit 4b73a92f71

View File

@ -20,6 +20,9 @@ module.exports = function(RED) {
var ArduinoFirmata = require('arduino-firmata'); var ArduinoFirmata = require('arduino-firmata');
var fs = require('fs'); var fs = require('fs');
var plat = require('os').platform(); var plat = require('os').platform();
var portlist = ArduinoFirmata.list(function (err, ports) {
portlist = ports;
});
// The Board Definition - this opens (and closes) the connection // The Board Definition - this opens (and closes) the connection
function ArduinoNode(n) { function ArduinoNode(n) {
@ -29,17 +32,12 @@ module.exports = function(RED) {
//node.log("opening connection "+this.device); //node.log("opening connection "+this.device);
var node = this; var node = this;
node.board = new ArduinoFirmata(); node.board = new ArduinoFirmata();
if (!plat.match(/^win/)) { // not Windows if (portlist.indexOf(node.device) === -1) {
if (!fs.existsSync(node.device)) {
node.warn("Device "+node.device+" not found"); node.warn("Device "+node.device+" not found");
} }
else { else {
node.board.connect(node.device); node.board.connect(node.device);
} }
}
else { // Windows - try to connect anyway... this can be bad...
node.board.connect(node.device);
}
node.board.on('boardReady', function(){ node.board.on('boardReady', function(){
node.log("version "+node.board.boardVersion); node.log("version "+node.board.boardVersion);