2015-06-13 19:45:38 +02:00
|
|
|
|
|
|
|
<script type="text/x-red" data-template-name="serial in">
|
|
|
|
<div class="form-row node-input-serial">
|
2015-06-16 11:36:19 +02:00
|
|
|
<label for="node-input-serial"><i class="fa fa-random"></i> <span data-i18n="serial.label.serialport"></span></label>
|
2015-06-13 19:45:38 +02:00
|
|
|
<input type="text" id="node-input-serial">
|
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
2015-06-16 12:16:29 +02:00
|
|
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
|
|
|
|
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
|
2015-06-13 19:45:38 +02:00
|
|
|
</div>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/x-red" data-help-name="serial in">
|
|
|
|
<p>Reads data from a local serial port.</p>
|
|
|
|
<p>Can either <ul><li>wait for a "split" character (default \n). Also accepts hex notation (0x0a).</li>
|
2015-06-16 11:36:19 +02:00
|
|
|
<li>Wait for a timeout in milliseconds for the first character received</li>
|
|
|
|
<li>Wait to fill a fixed sized buffer</li></ul></p>
|
2016-02-12 14:14:12 +01:00
|
|
|
<p>It then outputs <code>msg.payload</code> as either a UTF8 ascii string or a binary Buffer object.</p>
|
2016-04-01 09:55:50 +02:00
|
|
|
<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>
|
2015-06-13 19:45:38 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
RED.nodes.registerType('serial in',{
|
|
|
|
category: 'input',
|
|
|
|
defaults: {
|
|
|
|
name: {name:""},
|
|
|
|
serial: {type:"serial-port",required:true}
|
|
|
|
},
|
|
|
|
color:"BurlyWood",
|
|
|
|
inputs:0,
|
|
|
|
outputs:1,
|
|
|
|
icon: "serial.png",
|
|
|
|
label: function() {
|
|
|
|
var serialNode = RED.nodes.node(this.serial);
|
2015-06-16 11:36:19 +02:00
|
|
|
return this.name||(serialNode?serialNode.label().split(":")[0]:this._("serial.label.serial"));
|
2015-06-13 19:45:38 +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">
|
2015-06-16 11:36:19 +02:00
|
|
|
<label for="node-input-serial"><i class="fa fa-random"></i> <span data-i18n="serial.label.serialport"></span></label>
|
2015-06-13 19:45:38 +02:00
|
|
|
<input type="text" id="node-input-serial">
|
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
2015-06-16 12:16:29 +02:00
|
|
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
|
|
|
|
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
|
2015-06-13 19:45:38 +02:00
|
|
|
</div>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/x-red" data-help-name="serial out">
|
|
|
|
<p>Provides a connection to an outbound serial port.</p>
|
2016-02-12 14:14:12 +01:00
|
|
|
<p>Only the <code>msg.payload</code> is sent.</p>
|
2015-06-13 19:45:38 +02:00
|
|
|
<p>Optionally the new line character used to split the input can be appended to every message sent out to the serial port.</p>
|
2016-02-12 14:14:12 +01:00
|
|
|
<p>Binary payloads can be sent by using a Buffer object.</p>
|
2015-06-13 19:45:38 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
RED.nodes.registerType('serial out',{
|
|
|
|
category: 'output',
|
|
|
|
defaults: {
|
|
|
|
name: {name:""},
|
|
|
|
serial: {type:"serial-port",required:true}
|
|
|
|
},
|
|
|
|
color:"BurlyWood",
|
|
|
|
inputs:1,
|
|
|
|
outputs:0,
|
|
|
|
icon: "serial.png",
|
|
|
|
align: "right",
|
|
|
|
label: function() {
|
|
|
|
var serialNode = RED.nodes.node(this.serial);
|
2015-06-16 11:36:19 +02:00
|
|
|
return this.name||(serialNode?serialNode.label().split(":")[0]:this._("serial.label.serial"));
|
2015-06-13 19:45:38 +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">
|
2015-06-16 11:36:19 +02:00
|
|
|
<label for="node-config-input-serialport"><i class="fa fa-random"></i> <span data-i18n="serial.label.serialport"></span></label>
|
|
|
|
<input type="text" id="node-config-input-serialport" style="width:60%;" data-i18n="[placeholder]serial.placeholder.serialport">
|
2015-06-13 19:45:38 +02:00
|
|
|
<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">
|
2016-04-01 09:55:50 +02:00
|
|
|
<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>
|
2015-06-16 11:36:19 +02:00
|
|
|
<td width="80px" data-i18n="serial.label.parity"></td>
|
2016-04-01 09:55:50 +02:00
|
|
|
<td width="70px" data-i18n="serial.label.stopbits"></td>
|
2015-06-13 19:45:38 +02:00
|
|
|
</tr><tr><td> </td>
|
|
|
|
<td>
|
2016-04-01 09:55:50 +02:00
|
|
|
<input type="text" id="node-config-input-serialbaud" style="width:100px">
|
2015-06-13 19:45:38 +02:00
|
|
|
</td><td>
|
2016-04-01 09:55:50 +02:00
|
|
|
<select type="text" id="node-config-input-databits" style="width:70px;">
|
2015-06-13 19:45:38 +02:00
|
|
|
<option value="8">8</option>
|
|
|
|
<option value="7">7</option>
|
|
|
|
<option value="6">6</option>
|
|
|
|
<option value="5">5</option>
|
|
|
|
</select>
|
|
|
|
</td><td>
|
2016-04-01 09:55:50 +02:00
|
|
|
<select type="text" id="node-config-input-parity" style="width:80px;">
|
2015-06-16 11:36:19 +02:00
|
|
|
<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>
|
|
|
|
<option value="odd" data-i18n="serial.parity.odd"></option>
|
|
|
|
<option value="space" data-i18n="serial.parity.space"></option>
|
2015-06-13 19:45:38 +02:00
|
|
|
</select>
|
|
|
|
</td><td>
|
2016-04-01 09:55:50 +02:00
|
|
|
<select type="text" id="node-config-input-stopbits" style="width:70px;">
|
2015-06-13 19:45:38 +02:00
|
|
|
<option value="2">2</option>
|
|
|
|
<option value="1">1</option>
|
|
|
|
</select>
|
|
|
|
</td>
|
2016-04-01 09:55:50 +02:00
|
|
|
</tr></table></div>
|
|
|
|
<br/>
|
2015-06-13 19:45:38 +02:00
|
|
|
<div class="form-row">
|
2015-06-16 11:36:19 +02:00
|
|
|
<label><i class="fa fa-sign-in"></i> <span data-i18n="serial.label.input"></span></label>
|
2015-06-13 19:45:38 +02:00
|
|
|
</div>
|
|
|
|
<div class="form-row" style="padding-left: 10px;">
|
2015-06-16 11:36:19 +02:00
|
|
|
<span data-i18n="serial.label.split"></span>
|
2015-06-13 19:45:38 +02:00
|
|
|
<select type="text" id="node-config-input-out" style="margin-left: 5px; width:200px;">
|
2015-06-16 11:36:19 +02:00
|
|
|
<option value="char" data-i18n="serial.split.character"></option>
|
|
|
|
<option value="time" data-i18n="serial.split.timeout"></option>
|
|
|
|
<option value="count" data-i18n="serial.split.lengths"></option>
|
2015-06-13 19:45:38 +02:00
|
|
|
</select>
|
|
|
|
<input type="text" id="node-config-input-newline" style="width:50px;">
|
|
|
|
<span id="node-units"></span>
|
|
|
|
</div>
|
|
|
|
<div class="form-row" style="padding-left: 10px;">
|
2015-06-16 11:36:19 +02:00
|
|
|
<span data-i18n="serial.label.deliver"></span>
|
2015-06-13 19:45:38 +02:00
|
|
|
<select type="text" id="node-config-input-bin" style="margin-left: 5px; width: 150px;">
|
2015-06-16 11:36:19 +02:00
|
|
|
<option value="false" data-i18n="serial.output.ascii"></option>
|
|
|
|
<option value="bin" data-i18n="serial.output.binary"></option>
|
2015-06-13 19:45:38 +02:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<br/>
|
|
|
|
<div id="node-config-addchar">
|
|
|
|
<div class="form-row">
|
2015-06-16 11:36:19 +02:00
|
|
|
<label><i class="fa fa-sign-out"></i> <span data-i18n="serial.label.output"></span></label>
|
2015-06-13 19:45:38 +02:00
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
2015-06-16 11:36:19 +02:00
|
|
|
<input style="width: 30px;margin-left: 10px; vertical-align: top;" type="checkbox" id="node-config-input-addchar"><label style="width: auto;" for="node-config-input-addchar"><span data-i18n="serial.addsplit"></span></label>
|
2015-06-13 19:45:38 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2015-06-16 11:36:19 +02:00
|
|
|
<div class="form-tips" id="tip-split"><span data-i18n="serial.tip.split"></span></div>
|
|
|
|
<div class="form-tips" id="tip-bin" hidden><span data-i18n="serial.tip.timeout"></span></div>
|
2015-06-13 19:45:38 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
RED.nodes.registerType('serial-port',{
|
|
|
|
category: 'config',
|
|
|
|
defaults: {
|
|
|
|
//name: {value:""},
|
|
|
|
serialport: {value:"",required:true},
|
2016-04-01 09:55:50 +02:00
|
|
|
serialbaud: {value:"57600",required:true,validate:RED.validators.number()},
|
2015-06-13 19:45:38 +02:00
|
|
|
databits: {value:8,required:true},
|
|
|
|
parity: {value:"none",required:true},
|
|
|
|
stopbits: {value:1,required:true},
|
|
|
|
newline: {value:"\\n"},
|
|
|
|
bin: {value:"false"},
|
|
|
|
out: {value:"char"},
|
|
|
|
addchar: {value:false}
|
|
|
|
},
|
|
|
|
label: function() {
|
|
|
|
this.serialbaud = this.serialbaud || 57600;
|
|
|
|
this.databits = this.databits || 8;
|
2015-06-16 11:36:19 +02:00
|
|
|
this.parity = this.parity || this._("serial.label.none");
|
2015-06-13 19:45:38 +02:00
|
|
|
this.stopbits = this.stopbits || 1;
|
|
|
|
return this.serialport+":"+this.serialbaud+"-"+this.databits+this.parity.charAt(0).toUpperCase()+this.stopbits;
|
|
|
|
},
|
|
|
|
oneditprepare: function() {
|
|
|
|
var previous = null;
|
2016-04-01 09:55:50 +02:00
|
|
|
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
|
|
|
|
});
|
|
|
|
|
2015-06-13 19:45:38 +02:00
|
|
|
$("#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(""); }
|
|
|
|
$("#node-units").text("chars");
|
|
|
|
$("#node-config-addchar").hide();
|
|
|
|
$("#node-config-input-addchar").val("false");
|
|
|
|
$("#tip-split").hide();
|
|
|
|
$("#tip-bin").hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
$("#node-config-input-serialport").autocomplete( "destroy" );
|
|
|
|
} catch(err) {
|
|
|
|
}
|
|
|
|
$("#node-config-lookup-serial").click(function() {
|
|
|
|
$("#node-config-lookup-serial").addClass('disabled');
|
|
|
|
$.getJSON('serialports',function(data) {
|
|
|
|
$("#node-config-lookup-serial").removeClass('disabled');
|
|
|
|
var ports = [];
|
2016-04-01 09:55:50 +02:00
|
|
|
$.each(data, function(i, port) {
|
2015-06-13 19:45:38 +02:00
|
|
|
ports.push(port.comName);
|
|
|
|
});
|
|
|
|
$("#node-config-input-serialport").autocomplete({
|
|
|
|
source:ports,
|
|
|
|
minLength:0,
|
|
|
|
close: function( event, ui ) {
|
|
|
|
$("#node-config-input-serialport").autocomplete( "destroy" );
|
|
|
|
}
|
|
|
|
}).autocomplete("search","");
|
|
|
|
});
|
|
|
|
});
|
2016-04-01 09:55:50 +02:00
|
|
|
},
|
|
|
|
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');
|
2015-06-13 19:45:38 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|