UNPKG

node-red-contrib-bean

Version:
131 lines (122 loc) 6.2 kB
<!-- Copyright 2014 Punch Throguh Design. 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="bean serial"> <div class="form-row node-input-bean"> <label for="node-input-bean"><i class="fa fa-random"></i> Bean</label> <input type="text" id="node-input-bean"> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-row"> <label><i class="fa fa-sign-in"></i> Incoming</label> </div> <div class="form-row" style="padding-left: 10px;"> Split input <select type="text" id="node-input-out" style="margin-left: 5px; width:200px;"> <option value="char">on the character</option> <option value="time">after a timeout of</option> <option value="count">into fixed lengths of</option> </select> <input type="text" id="node-input-newline" style="width:50px;"> <span id="node-units"></span> </div> <div class="form-row" style="padding-left: 10px;"> and deliver <select type="text" id="node-input-bin" style="margin-left: 5px; width: 150px;"> <option value="false">ascii strings</option> <option value="bin">binary buffers</option> </select> </div> <br/> <div id="node-addchar"> <div class="form-row"> <label><i class="fa fa-sign-out"></i> Outgoing</label> </div> <div class="form-row"> <input style="width: 30px;margin-left: 10px; vertical-align: top;" type="checkbox" id="node-input-addchar"><label style="width: auto;" for="node-input-addchar">add split character to outgoing messages</label> </div> </div> <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> <script type="text/x-red" data-help-name="bean serial"> <p><b>Outgoing Serial:</b></p> <p>Allows you to send serial data to a Bean.</p> <p>Only the <b>msg.payload</b> is sent.</p> <p>msg.payload can be either a utf8 encoded <b>String</b> or a <b>Buffer</b> object containing hex values</p> <p><br/></p> <p><b>Incoming Serial:</b></p> <p>Reads incoming serial data from a Bean.</p> <p>Can either <ul><li>wait for a "split" character (default \n). Also accepts hex notation (0x0a).</li> <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 <b>msg.payload</b> 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> </script> <script type="text/javascript"> RED.nodes.registerType('bean serial',{ category: 'LightBlue Bean-input', // the palette category defaults: { // defines the editable properties of the node name: {value:""}, bean: {type:"bean",required:true}, // along with default values. newline: {value:"\\n"}, bin: {value:"false"}, out: {value:"char"}, addchar: {value:false} }, inputs:1, // set the number of inputs - only 0 or 1 outputs:1, // set the number of outputs - 0 to n color: "#3FADB5", // set the icon (held in icons dir below where you save the node) icon: "serial.png", // saved in icons/myicon.png paletteLabel: "serial", label: function() { // sets the default label contents var beanNode = RED.nodes.node(this.bean); return this.name||((beanNode?beanNode.label():"Bean") + " serial"); }, labelStyle: function() { // sets the class to apply to the label return this.name?"node_label_italic":""; }, oneditprepare: function() { var previous = null; $("#node-input-out").on('focus', function () { previous = this.value; }).change(function() { if (previous == null) { previous = $("#node-input-out").val(); } if ($("#node-input-out").val() == "char") { if (previous != "char") { $("#node-input-newline").val("\\n"); } $("#node-units").text(""); $("#node-addchar").show(); $("#tip-split").show(); $("#tip-bin").hide(); } else if ($("#node-input-out").val() == "time") { if (previous != "time") { $("#node-input-newline").val("0"); } $("#node-units").text("ms"); $("#node-addchar").hide(); $("#node-input-addchar").val("false"); $("#tip-split").hide(); $("#tip-bin").show(); } else { if (previous != "count") { $("#node-input-newline").val(""); } $("#node-units").text("chars"); $("#node-addchar").hide(); $("#node-input-addchar").val("false"); $("#tip-split").hide(); $("#tip-bin").hide(); } }); } }); </script>