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

Add "other" baud rates to serialport

to Close #194
Uses typed widget so needs NR 0.13.4.
This commit is contained in:
Dave Conway-Jones 2016-04-01 08:55:50 +01:00
parent b5f0823bd4
commit 68bd4cc036
2 changed files with 53 additions and 40 deletions

View File

@ -1,5 +1,5 @@
<!--
Copyright 2013,2014 IBM Corp.
Copyright 2013,2016 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -31,7 +31,8 @@
<li>Wait for a timeout in milliseconds for the first character received</li>
<li>Wait to fill a fixed sized buffer</li></ul></p>
<p>It then outputs <code>msg.payload</code> as either a UTF8 ascii string or a binary Buffer object.</p>
<p>If no split character is specified, or a timeout or buffer size of 0, then a stream of single characters is sent - again either as ascii chars or size 1 binary buffers.</p>
<p>If no split character is specified, or a timeout or buffer size of 0, then a stream of single characters
is sent - again either as ascii chars or size 1 binary buffers.</p>
</script>
<script type="text/javascript">
@ -103,42 +104,24 @@
<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-row">
<table><tr>
<td width="102px"><i class="fa fa-wrench"></i> <span data-i18n="serial.label.settings"></span></td>
<td width="100px" data-i18n="serial.label.baudrate"></td>
<td width="80px" data-i18n="serial.label.databits"></td>
<table width="100%"><tr>
<td width="100px"><i class="fa fa-wrench"></i> <span data-i18n="serial.label.settings"></span></td>
<td width="110px" data-i18n="serial.label.baudrate"></td>
<td width="70px" data-i18n="serial.label.databits"></td>
<td width="80px" data-i18n="serial.label.parity"></td>
<td width="80px" data-i18n="serial.label.stopbits"></td>
<td width="70px" data-i18n="serial.label.stopbits"></td>
</tr><tr><td>&nbsp;</td>
<td>
<select type="text" id="node-config-input-serialbaud" style="width: 100px;">
<option value="115200">115200</option>
<option value="57600">57600</option>
<option value="38400">38400</option>
<option value="19200">19200</option>
<option value="9600">9600</option>
<option value="4800">4800</option>
<option value="2400">2400</option>
<option value="1800">1800</option>
<option value="1200">1200</option>
<option value="600">600</option>
<option value="300">300</option>
<option value="200">200</option>
<option value="150">150</option>
<option value="134">134</option>
<option value="110">110</option>
<option value="75">75</option>
<option value="50">50</option>
</select>
<input type="text" id="node-config-input-serialbaud" style="width:100px">
</td><td>
<select type="text" id="node-config-input-databits" style="width: 80px;">
<select type="text" id="node-config-input-databits" style="width:70px;">
<option value="8">8</option>
<option value="7">7</option>
<option value="6">6</option>
<option value="5">5</option>
</select>
</td><td>
<select type="text" id="node-config-input-parity" style="width: 80px;">
<select type="text" id="node-config-input-parity" style="width:80px;">
<option value="none" data-i18n="serial.parity.none"></option>
<option value="even" data-i18n="serial.parity.even"></option>
<option value="mark" data-i18n="serial.parity.mark"></option>
@ -146,13 +129,13 @@
<option value="space" data-i18n="serial.parity.space"></option>
</select>
</td><td>
<select type="text" id="node-config-input-stopbits" style="width: 80px;">
<select type="text" id="node-config-input-stopbits" style="width:70px;">
<option value="2">2</option>
<option value="1">1</option>
</select>
</td>
</tr></table><br/>
</tr></table></div>
<br/>
<div class="form-row">
<label><i class="fa fa-sign-in"></i> <span data-i18n="serial.label.input"></span></label>
</div>
@ -192,7 +175,7 @@
defaults: {
//name: {value:""},
serialport: {value:"",required:true},
serialbaud: {value:57600,required:true},
serialbaud: {value:"57600",required:true,validate:RED.validators.number()},
databits: {value:8,required:true},
parity: {value:"none",required:true},
stopbits: {value:1,required:true},
@ -210,6 +193,32 @@
},
oneditprepare: function() {
var previous = null;
var blist = [
{value:"115200",label:"115200",hasValue:false},
{value:"57600",label:"57600",hasValue:false},
{value:"38400",label:"38400",hasValue:false},
{value:"19200",label:"19200",hasValue:false},
{value:"9600",label:"9600",hasValue:false},
{value:"4800",label:"4800",hasValue:false},
{value:"2400",label:"2400",hasValue:false},
{value:"1200",label:"1200",hasValue:false},
{value:"600",label:"600",hasValue:false},
{value:"300",label:"300",hasValue:false},
{label:"other",value:"other",icon:"red/images/typedInput/09.png",validate:/^[0-9]*$/}
];
var serialbaudType = "custom";
for (var i in blist) {
if (this.serialbaud == blist[i].value) {
serialbaudType = this.serialbaud;
}
}
$("#node-config-input-serialbaud").typedInput({
default: this.serialbaud,
types:blist
});
$("#node-config-input-out").on('focus', function () { previous = this.value; }).change(function() {
if (previous == null) { previous = $("#node-config-input-out").val(); }
if ($("#node-config-input-out").val() == "char") {
@ -242,15 +251,11 @@
} catch(err) {
}
$("#node-config-lookup-serial").click(function() {
//$("#node-config-lookup-serial-icon").removeClass('fa fa-search');
//$("#node-config-lookup-serial-icon").addClass('fa fa-spinner');
$("#node-config-lookup-serial").addClass('disabled');
$.getJSON('serialports',function(data) {
//$("#node-config-lookup-serial-icon").addClass('fa fa-search');
//$("#node-config-lookup-serial-icon").removeClass('fa fa-spinner');
$("#node-config-lookup-serial").removeClass('disabled');
var ports = [];
$.each(data, function(i, port){
$.each(data, function(i, port) {
ports.push(port.comName);
});
$("#node-config-input-serialport").autocomplete({
@ -262,6 +267,13 @@
}).autocomplete("search","");
});
});
},
oneditsave: function() {
var mytype = $("#node-config-input-serialbaud").typedInput('type');
if (mytype !== "other") {
$("#node-config-input-serialbaud").typedInput('value',mytype);
}
this.serialbaud = $("#node-config-input-serialbaud").typedInput('value');
}
});
</script>

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-serialport",
"version" : "0.1.2",
"version" : "0.2.0",
"description" : "Node-RED nodes to talk to an serial port",
"dependencies" : {
"serialport" : "2.0.*"
@ -11,8 +11,9 @@
},
"license": "Apache-2.0",
"keywords": [ "node-red", "serial" ],
"node-red" : {
"nodes" : {
"node-red": {
"version": ">=0.13.0",
"nodes": {
"serialport": "25-serial.js"
}
},