2013-09-05 16:02:48 +02:00
<!--
2014-06-08 15:57:57 +02:00
Copyright 2013,2014 IBM Corp.
2013-09-05 16:02:48 +02:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
< script type = "text/x-red" data-template-name = "serial in" >
< div class = "form-row node-input-serial" >
2014-06-08 15:57:57 +02:00
< label for = "node-input-serial" > < i class = "fa fa-random" > < / i > Serial Port< / label >
2013-09-05 16:02:48 +02:00
< input type = "text" id = "node-input-serial" >
< / div >
< div class = "form-row" >
2014-06-08 15:57:57 +02:00
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > Name< / label >
2013-09-05 16:02:48 +02:00
< input type = "text" id = "node-input-name" placeholder = "Name" >
< / div >
< / script >
< script type = "text/x-red" data-help-name = "serial in" >
2013-12-06 22:03:33 +01:00
< p > Reads data from a local serial port.< / p >
2014-06-08 15:57:57 +02:00
< p > In ascii mode keeps reading from the serial port until it sees \n (default) or the character(s) requested. Outputs < b > msg.payload< / b > as a < i > string< / i > .< / p >
< p > In binary mode can either output buffers of a fixed size, or wait for a timeout and then send whatever has accumlated. Outputs < b > msg.payload< / b > as a < i > buffer< / i > .< / p >
2013-09-05 16:02:48 +02:00
< / script >
< script type = "text/javascript" >
RED.nodes.registerType('serial in',{
category: 'input',
defaults: {
2013-12-06 22:03:33 +01:00
name: {name:""},
2013-09-05 16:02:48 +02:00
serial: {type:"serial-port",required:true}
},
color:"BurlyWood",
inputs:0,
outputs:1,
icon: "serial.png",
label: function() {
2013-09-09 10:55:50 +02:00
var serialNode = RED.nodes.node(this.serial);
2014-05-06 12:12:42 +02:00
return this.name||(serialNode?serialNode.label().split(":")[0]:"serial");
2013-09-05 16:02:48 +02:00
},
labelStyle: function() {
return this.name?"node_label_italic":"";
}
});
< / script >
< script type = "text/x-red" data-template-name = "serial out" >
< div class = "form-row node-input-serial" >
2014-06-08 15:57:57 +02:00
< label for = "node-input-serial" > < i class = "fa fa-random" > < / i > Serial Port< / label >
2013-09-05 16:02:48 +02:00
< input type = "text" id = "node-input-serial" >
< / div >
< div class = "form-row" >
2014-06-08 15:57:57 +02:00
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > Name< / label >
2013-09-05 16:02:48 +02:00
< input type = "text" id = "node-input-name" placeholder = "Name" >
< / div >
< / script >
< script type = "text/x-red" data-help-name = "serial out" >
2013-12-06 22:03:33 +01:00
< p > Provides a connection to an outbound serial port.< / p >
< p > Only the < b > msg.payload< / b > is sent.< / p >
< p > Optionally the new line character used to split the input can be appended to every message sent out to the serial port.< / p >
2013-09-05 16:02:48 +02:00
< / script >
< script type = "text/javascript" >
RED.nodes.registerType('serial out',{
category: 'output',
defaults: {
2013-12-06 22:03:33 +01:00
name: {name:""},
2013-09-05 16:02:48 +02:00
serial: {type:"serial-port",required:true}
},
color:"BurlyWood",
inputs:1,
outputs:0,
icon: "serial.png",
align: "right",
label: function() {
2013-09-09 10:55:50 +02:00
var serialNode = RED.nodes.node(this.serial);
2014-05-06 12:12:42 +02:00
return this.name||(serialNode?serialNode.label().split(":")[0]:"serial");
2013-09-05 16:02:48 +02:00
},
labelStyle: function() {
return this.name?"node_label_italic":"";
}
});
< / script >
< script type = "text/x-red" data-template-name = "serial-port" >
< div class = "form-row" >
2014-06-08 15:57:57 +02:00
< label for = "node-config-input-serialport" > < i class = "fa fa-random" > < / i > Serial Port< / label >
2014-05-05 12:39:59 +02:00
< input type = "text" id = "node-config-input-serialport" style = "width:60%;" placeholder = "/dev/ttyUSB0" / >
2014-06-08 15:57:57 +02:00
< a id = "node-config-lookup-serial" class = "btn" > < i id = "node-config-lookup-serial-icon" class = "fa fa-search" > < / i > < / a >
2013-09-05 16:02:48 +02:00
< / div >
< div class = "form-row" >
2014-04-30 15:09:08 +02:00
< table > < tr >
2014-06-08 15:57:57 +02:00
< td width = "102px" > < i class = "fa fa-wrench" > < / i > Settings< / td >
2014-04-30 15:09:08 +02:00
< td width = "100px" > Baud Rate< / td >
< td width = "80px" > Data Bits< / td >
< td width = "80px" > Parity< / td >
< td width = "80px" > Stop Bits< / td >
< / tr > < tr > < td > < / td >
< td >
< select type = "text" id = "node-config-input-serialbaud" style = "width: 100px;" >
2013-09-05 16:02:48 +02:00
< 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 >
2014-04-30 15:09:08 +02:00
< / td > < td >
< select type = "text" id = "node-config-input-databits" style = "width: 80px;" >
2014-04-21 23:35:28 +02:00
< option value = "8" > 8< / option >
< option value = "7" > 7< / option >
< option value = "6" > 6< / option >
< option value = "5" > 5< / option >
< / select >
2014-04-30 15:09:08 +02:00
< / td > < td >
< select type = "text" id = "node-config-input-parity" style = "width: 80px;" >
2014-04-21 23:35:28 +02:00
< option value = "none" > None< / option >
< option value = "even" > Even< / option >
< option value = "mark" > Mark< / option >
< option value = "odd" > Odd< / option >
< option value = "space" > Space< / option >
< / select >
2014-04-30 15:09:08 +02:00
< / td > < td >
< select type = "text" id = "node-config-input-stopbits" style = "width: 80px;" >
2014-04-21 23:35:28 +02:00
< option value = "2" > 2< / option >
< option value = "1" > 1< / option >
< / select >
2014-04-30 15:09:08 +02:00
< / td >
2014-06-08 15:57:57 +02:00
< / tr > < / table > < br / >
2013-09-05 16:02:48 +02:00
< div class = "form-row" >
2014-06-08 15:57:57 +02:00
< label for = "node-config-input-out" > < i class = "fa fa-cut" > < / i > Split input< / label >
< select type = "text" id = "node-config-input-out" style = "width:52%;" >
< option value = "char" > when character received is< / option >
< option value = "time" > after a fixed timeout of< / option >
< option value = "count" > a fixed number of characters< / option >
< / select >
< input type = "text" id = "node-config-input-newline" style = "width:50px;" >
< span id = "node-units" > < / span >
2013-09-05 16:02:48 +02:00
< / div >
2014-06-08 15:57:57 +02:00
2013-09-05 16:02:48 +02:00
< div class = "form-row" >
2014-06-08 15:57:57 +02:00
< label for = "node-config-input-bin" > < i class = "fa fa-sign-in" > < / i > and deliver< / label >
< select type = "text" id = "node-config-input-bin" style = "width: 77%;" >
< option value = "false" > ascii strings< / option >
< option value = "bin" > binary buffers< / option >
< / select >
< / div >
< br / >
< div class = "form-row" id = "node-config-addchar" >
< label for = "node-config-input-addchar" > < i class = "fa fa-sign-out" > < / i > On output< / label >
< select type = "text" id = "node-config-input-addchar" style = "width: 77%;" >
< option value = "false" > don't add 'split' character to output messages< / option >
< option value = "true" > add 'split' character to output messages< / option >
2013-12-06 22:03:33 +01:00
< / select >
2013-09-05 16:02:48 +02:00
< / div >
2014-06-08 15:57:57 +02:00
< div class = "form-tips" id = "tip-split" > Tip: the "Split on" character is used to split the input into separate messages. It can also be added to every message sent out to the serial port.< / div >
< div class = "form-tips" id = "tip-bin" hidden > Tip: In timeout mode timeout starts from arrival of first character.< / div >
< script >
var previous = null;
$("#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") {
if (previous != "char") { $("#node-config-input-newline").val("\\n"); }
$("#node-units").text("");
$("#node-config-addchar").show();
$("#tip-split").show();
$("#tip-bin").hide();
}
else if ($("#node-config-input-out").val() == "time") {
if (previous != "time") { $("#node-config-input-newline").val("0"); }
$("#node-units").text("ms");
$("#node-config-addchar").hide();
$("#node-config-input-addchar").val("false");
$("#tip-split").hide();
$("#tip-bin").show();
}
else {
if (previous != "count") { $("#node-config-input-newline").val("12"); }
$("#node-units").text("chars");
$("#node-config-addchar").hide();
$("#node-config-input-addchar").val("false");
$("#tip-split").hide();
$("#tip-bin").hide();
}
});
< / script >
2013-09-05 16:02:48 +02:00
< / script >
< script type = "text/javascript" >
RED.nodes.registerType('serial-port',{
category: 'config',
defaults: {
//name: {value:""},
serialport: {value:"",required:true},
serialbaud: {value:57600,required:true},
2014-04-21 23:35:28 +02:00
databits: {value:8,required:true},
parity: {value:"none",required:true},
stopbits: {value:1,required:true},
2013-12-06 22:03:33 +01:00
newline: {value:"\\n"},
2014-06-08 15:57:57 +02:00
bin: {value:""},
out: {value:""},
2013-12-06 22:03:33 +01:00
addchar: {value:false}
2013-09-05 16:02:48 +02:00
},
2014-04-30 15:09:08 +02:00
label: function() {
this.serialbaud = this.serialbaud || 57600;
this.databits = this.databits || 8;
this.parity = this.parity || 'none';
this.stopbits = this.stopbits || 1;
2014-04-21 23:35:28 +02:00
return this.serialport+":"+this.serialbaud+"-"+this.databits+this.parity.charAt(0).toUpperCase()+this.stopbits;
2014-05-05 12:39:59 +02:00
},
oneditprepare: function() {
2014-05-05 22:42:01 +02:00
try {
$("#node-config-input-serialport").autocomplete( "destroy" );
} catch(err) {
}
$("#node-config-lookup-serial").click(function() {
2014-06-08 15:57:57 +02:00
//$("#node-config-lookup-serial-icon").removeClass('fa fa-search');
//$("#node-config-lookup-serial-icon").addClass('fa fa-spinner');
2014-05-05 22:42:01 +02:00
$("#node-config-lookup-serial").addClass('disabled');
$.getJSON('serialports',function(data) {
2014-06-08 15:57:57 +02:00
//$("#node-config-lookup-serial-icon").addClass('fa fa-search');
//$("#node-config-lookup-serial-icon").removeClass('fa fa-spinner');
2014-05-05 22:42:01 +02:00
$("#node-config-lookup-serial").removeClass('disabled');
var ports = [];
$.each(data, function(i, port){
ports.push(port.comName);
});
$("#node-config-input-serialport").autocomplete({
source:ports,
minLength:0,
close: function( event, ui ) {
$("#node-config-input-serialport").autocomplete( "destroy" );
2014-05-05 22:44:04 +02:00
}
2014-05-05 22:42:01 +02:00
}).autocomplete("search","");
});
});
2014-05-05 12:39:59 +02:00
}
2013-09-05 16:02:48 +02:00
});
< / script >