mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Check to see serialport exists before opening in Arduino node
Fixes #382 now warns if chosen serial port doesn't exist - rather than crashing. So is now recoverable without manually editing flows. (Also moved to fa-icons and Arduino category)
This commit is contained in:
parent
56768fbf2c
commit
083dc213f0
@ -15,22 +15,22 @@
|
|||||||
-->
|
-->
|
||||||
<script type="text/x-red" data-template-name="arduino in">
|
<script type="text/x-red" data-template-name="arduino in">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-arduino"><i class="icon-tasks"></i> Arduino</label>
|
<label for="node-input-arduino"><i class="fa fa-tasks"></i> Arduino</label>
|
||||||
<input type="text" id="node-input-arduino">
|
<input type="text" id="node-input-arduino">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-pin"><i class="icon-asterisk"></i> Pin</label>
|
<label for="node-input-pin"><i class="fa fa-circle"></i> Pin</label>
|
||||||
<input type="text" id="node-input-pin" placeholder="2">
|
<input type="text" id="node-input-pin" placeholder="2">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-state"><i class="icon-wrench"></i> Type</label>
|
<label for="node-input-state"><i class="fa fa-wrench"></i> Type</label>
|
||||||
<select type="text" id="node-input-state" style="width: 150px;">
|
<select type="text" id="node-input-state" style="width: 150px;">
|
||||||
<option value="INPUT">Digital pin</option>
|
<option value="INPUT">Digital pin</option>
|
||||||
<option value="ANALOG">Analogue pin</option>
|
<option value="ANALOG">Analogue pin</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||||
<input type="text" id="node-input-name" placeholder="Name">
|
<input type="text" id="node-input-name" placeholder="Name">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-tips"><b>Note:</b> You cannot use the same pin for both output and input.</div>
|
<div class="form-tips"><b>Note:</b> You cannot use the same pin for both output and input.</div>
|
||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
RED.nodes.registerType('arduino in',{
|
RED.nodes.registerType('arduino in',{
|
||||||
category: 'advanced-input',
|
category: 'Arduino',
|
||||||
color:"#3fadb5",
|
color:"#3fadb5",
|
||||||
defaults: {
|
defaults: {
|
||||||
name: {value:""},
|
name: {value:""},
|
||||||
@ -70,15 +70,15 @@
|
|||||||
|
|
||||||
<script type="text/x-red" data-template-name="arduino out">
|
<script type="text/x-red" data-template-name="arduino out">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-arduino"><i class="icon-tasks"></i> Arduino</label>
|
<label for="node-input-arduino"><i class="fa fa-tasks"></i> Arduino</label>
|
||||||
<input type="text" id="node-input-arduino">
|
<input type="text" id="node-input-arduino">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-pin"><i class="icon-asterisk"></i> Pin</label>
|
<label for="node-input-pin"><i class="fa fa-circle"></i> Pin</label>
|
||||||
<input type="text" id="node-input-pin" placeholder="13">
|
<input type="text" id="node-input-pin" placeholder="13">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-state"><i class="icon-wrench"></i> Type</label>
|
<label for="node-input-state"><i class="fa fa-wrench"></i> Type</label>
|
||||||
<select type="text" id="node-input-state" style="width: 200px;">
|
<select type="text" id="node-input-state" style="width: 200px;">
|
||||||
<option value="OUTPUT">Digital (0/1)</option>
|
<option value="OUTPUT">Digital (0/1)</option>
|
||||||
<option value="PWM">Analogue (0-255)</option>
|
<option value="PWM">Analogue (0-255)</option>
|
||||||
@ -86,7 +86,7 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||||
<input type="text" id="node-input-name" placeholder="Name">
|
<input type="text" id="node-input-name" placeholder="Name">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-tips"><b>Note:</b> You cannot use the same pin for both output and input.</div>
|
<div class="form-tips"><b>Note:</b> You cannot use the same pin for both output and input.</div>
|
||||||
@ -100,7 +100,7 @@
|
|||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
RED.nodes.registerType('arduino out',{
|
RED.nodes.registerType('arduino out',{
|
||||||
category: 'advanced-output',
|
category: 'Arduino',
|
||||||
color:"#3fadb5",
|
color:"#3fadb5",
|
||||||
defaults: {
|
defaults: {
|
||||||
name: {value:""},
|
name: {value:""},
|
||||||
@ -124,18 +124,18 @@
|
|||||||
|
|
||||||
<script type="text/x-red" data-template-name="arduino-board">
|
<script type="text/x-red" data-template-name="arduino-board">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-config-input-device"><i class="icon-random"></i> Port</label>
|
<label for="node-config-input-device"><i class="fa fa-random"></i> Port</label>
|
||||||
<input type="text" id="node-config-input-device" style="width:60%;" placeholder="/dev/ttyUSB0"/>
|
<input type="text" id="node-config-input-device" style="width:60%;" placeholder="/dev/ttyUSB0"/>
|
||||||
<a id="node-config-lookup-serial" class="btn"><i id="node-config-lookup-serial-icon" class="icon icon-search"></i></a>
|
<a id="node-config-lookup-serial" class="btn"><i id="node-config-lookup-serial-icon" class="fa fa-search"></i></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-tips"><b>Tip:</b> Leave blank for auto detect on first serial port.</div>
|
<div class="form-tips"><b>Tip:</b> Use search to try to auto-detect serial port.</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
RED.nodes.registerType('arduino-board',{
|
RED.nodes.registerType('arduino-board',{
|
||||||
category: 'config',
|
category: 'config',
|
||||||
defaults: {
|
defaults: {
|
||||||
device: {value:""}
|
device: {value:"",required:true}
|
||||||
},
|
},
|
||||||
label: function() {
|
label: function() {
|
||||||
return this.device||"arduino";
|
return this.device||"arduino";
|
||||||
|
@ -18,6 +18,8 @@ module.exports = function(RED) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
var util = require("util");
|
var util = require("util");
|
||||||
var ArduinoFirmata = require('arduino-firmata');
|
var ArduinoFirmata = require('arduino-firmata');
|
||||||
|
var fs = require('fs');
|
||||||
|
var plat = require('os').platform();
|
||||||
|
|
||||||
// The Board Definition - this opens (and closes) the connection
|
// The Board Definition - this opens (and closes) the connection
|
||||||
function ArduinoNode(n) {
|
function ArduinoNode(n) {
|
||||||
@ -26,13 +28,19 @@ module.exports = function(RED) {
|
|||||||
this.repeat = n.repeat||25;
|
this.repeat = n.repeat||25;
|
||||||
//node.log("opening connection "+this.device);
|
//node.log("opening connection "+this.device);
|
||||||
var node = this;
|
var node = this;
|
||||||
|
var pre = "\\\\.\\";
|
||||||
|
if (!plat.match(/^win/)) { pre = ""; }
|
||||||
|
|
||||||
node.board = new ArduinoFirmata();
|
node.board = new ArduinoFirmata();
|
||||||
node.board.connect(node.device);
|
if (!fs.existsSync(pre+node.device)) {
|
||||||
|
node.warn("Device "+node.device+" not found");
|
||||||
node.board.on('connect', function(){
|
}
|
||||||
node.log("version "+node.board.boardVersion);
|
else {
|
||||||
})
|
node.board.connect(node.device);
|
||||||
|
node.board.on('connect', function(){
|
||||||
|
node.log("version "+node.board.boardVersion);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
node.on('close', function() {
|
node.on('close', function() {
|
||||||
if (node.board) {
|
if (node.board) {
|
||||||
|
Loading…
Reference in New Issue
Block a user