mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Arduino - ensure port list populated on start,
also allow connect to first found board - by not specifying a port.
This commit is contained in:
parent
d28a6eaf9d
commit
72e1f20383
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
Copyright 2013,2014 IBM Corp.
|
||||
Copyright 2013,2015 IBM Corp.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@ -59,7 +59,7 @@
|
||||
icon: "arduino.png",
|
||||
label: function() {
|
||||
var a = "";
|
||||
if (this.state == "ANALOG") a = "A";
|
||||
if (this.state === "ANALOG") { a = "A"; }
|
||||
return this.name||"Pin: "+a+this.pin;
|
||||
},
|
||||
labelStyle: function() {
|
||||
@ -128,14 +128,14 @@
|
||||
<input type="text" id="node-config-input-device" style="width:60%;" placeholder="e.g. /dev/ttyUSB0 COM1"/>
|
||||
<a id="node-config-lookup-serial" class="btn"><i id="node-config-lookup-serial-icon" class="fa fa-search"></i></a>
|
||||
</div>
|
||||
<div class="form-tips"><b>Tip:</b> Use search to try to auto-detect serial port.</div>
|
||||
<div class="form-tips"><b>Tip:</b> Use search to list serial ports, or leave blank to connect to first device found.</div>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('arduino-board',{
|
||||
category: 'config',
|
||||
defaults: {
|
||||
device: {value:"",required:true}
|
||||
device: {value:""}
|
||||
},
|
||||
label: function() {
|
||||
return this.device||"arduino";
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2013,2014 IBM Corp.
|
||||
* Copyright 2013,2015 IBM Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -18,9 +18,6 @@ module.exports = function(RED) {
|
||||
"use strict";
|
||||
var ArduinoFirmata = require('arduino-firmata');
|
||||
var fs = require('fs');
|
||||
var portlist = ArduinoFirmata.list(function (err, ports) {
|
||||
portlist = ports;
|
||||
});
|
||||
|
||||
// The Board Definition - this opens (and closes) the connection
|
||||
function ArduinoNode(n) {
|
||||
@ -30,15 +27,18 @@ module.exports = function(RED) {
|
||||
//node.log("opening connection "+this.device);
|
||||
var node = this;
|
||||
node.board = new ArduinoFirmata();
|
||||
if (portlist.indexOf(node.device) === -1) {
|
||||
node.error("device "+node.device+" not found");
|
||||
}
|
||||
else {
|
||||
node.board.connect(node.device);
|
||||
}
|
||||
ArduinoFirmata.list(function (err, ports) {
|
||||
if (ports.indexOf(node.device) === -1) {
|
||||
node.board.connect();
|
||||
node.log("connecting to first device found.");
|
||||
}
|
||||
else {
|
||||
node.board.connect(node.device);
|
||||
}
|
||||
|
||||
node.board.on('boardReady', function(){
|
||||
if (RED.settings.verbose) { node.log("version "+node.board.boardVersion); }
|
||||
node.board.on('boardReady', function() {
|
||||
if (RED.settings.verbose) { node.log("version "+node.board.boardVersion); }
|
||||
});
|
||||
});
|
||||
|
||||
node.on('close', function(done) {
|
||||
|
Loading…
Reference in New Issue
Block a user