[CCSDK-28] populated the seed code for dgbuilder
[ccsdk/distribution.git] / dgbuilder / core_nodes / io / 25-serial.html
1 <!--
2   Copyright 2013,2014 IBM Corp.
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8   http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15 -->
16
17 <script type="text/x-red" data-template-name="serial in">
18     <div class="form-row node-input-serial">
19         <label for="node-input-serial"><i class="fa fa-random"></i> Serial Port</label>
20         <input type="text" id="node-input-serial">
21     </div>
22     <div class="form-row">
23         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
24         <input type="text" id="node-input-name" placeholder="Name">
25     </div>
26 </script>
27
28 <script type="text/x-red" data-help-name="serial in">
29     <p>Reads data from a local serial port.</p>
30     <p>Can either <ul><li>wait for a "split" character (default \n). Also accepts hex notation (0x0a).</li>
31     <li>Wait for a timeout in milliseconds for the first character received</li>
32     <li>Wait to fill a fixed sized buffer</li></ul></p>
33     <p>It then outputs <b>msg.payload</b> as either a UTF8 ascii string or a binary Buffer object.</p>
34     <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>
35 </script>
36
37 <script type="text/javascript">
38     RED.nodes.registerType('serial in',{
39         category: 'input',
40         defaults: {
41             name: {name:""},
42             serial: {type:"serial-port",required:true}
43         },
44         color:"BurlyWood",
45         inputs:0,
46         outputs:1,
47         icon: "serial.png",
48         label: function() {
49             var serialNode = RED.nodes.node(this.serial);
50             return this.name||(serialNode?serialNode.label().split(":")[0]:"serial");
51         },
52         labelStyle: function() {
53             return this.name?"node_label_italic":"";
54         }
55     });
56 </script>
57
58 <script type="text/x-red" data-template-name="serial out">
59     <div class="form-row node-input-serial">
60         <label for="node-input-serial"><i class="fa fa-random"></i> Serial Port</label>
61         <input type="text" id="node-input-serial">
62     </div>
63     <div class="form-row">
64         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
65         <input type="text" id="node-input-name" placeholder="Name">
66     </div>
67 </script>
68
69 <script type="text/x-red" data-help-name="serial out">
70     <p>Provides a connection to an outbound serial port.</p>
71     <p>Only the <b>msg.payload</b> is sent.</p>
72     <p>Optionally the new line character used to split the input can be appended to every message sent out to the serial port.</p>
73 </script>
74
75 <script type="text/javascript">
76     RED.nodes.registerType('serial out',{
77         category: 'output',
78         defaults: {
79             name: {name:""},
80             serial: {type:"serial-port",required:true}
81         },
82         color:"BurlyWood",
83         inputs:1,
84         outputs:0,
85         icon: "serial.png",
86         align: "right",
87         label: function() {
88             var serialNode = RED.nodes.node(this.serial);
89             return this.name||(serialNode?serialNode.label().split(":")[0]:"serial");
90         },
91         labelStyle: function() {
92             return this.name?"node_label_italic":"";
93         }
94     });
95 </script>
96
97
98 <script type="text/x-red" data-template-name="serial-port">
99     <div class="form-row">
100         <label for="node-config-input-serialport"><i class="fa fa-random"></i> Serial Port</label>
101         <input type="text" id="node-config-input-serialport" style="width:60%;" placeholder="/dev/ttyUSB0"/>
102         <a id="node-config-lookup-serial" class="btn"><i id="node-config-lookup-serial-icon" class="fa fa-search"></i></a>
103     </div>
104     <div class="form-row">
105         <table><tr>
106             <td width = "102px"><i class="fa fa-wrench"></i> Settings</td>
107             <td width = "100px">Baud Rate</td>
108             <td width = "80px">Data Bits</td>
109             <td width = "80px">Parity</td>
110             <td width = "80px">Stop Bits</td>
111         </tr><tr><td>&nbsp;</td>
112         <td>
113         <select type="text" id="node-config-input-serialbaud" style="width: 100px;">
114             <option value="115200">115200</option>
115             <option value="57600">57600</option>
116             <option value="38400">38400</option>
117             <option value="19200">19200</option>
118             <option value="9600">9600</option>
119             <option value="4800">4800</option>
120             <option value="2400">2400</option>
121             <option value="1800">1800</option>
122             <option value="1200">1200</option>
123             <option value="600">600</option>
124             <option value="300">300</option>
125             <option value="200">200</option>
126             <option value="150">150</option>
127             <option value="134">134</option>
128             <option value="110">110</option>
129             <option value="75">75</option>
130             <option value="50">50</option>
131         </select>
132         </td><td>
133         <select type="text" id="node-config-input-databits" style="width: 80px;">
134             <option value="8">8</option>
135             <option value="7">7</option>
136             <option value="6">6</option>
137             <option value="5">5</option>
138         </select>
139         </td><td>
140         <select type="text" id="node-config-input-parity" style="width: 80px;">
141             <option value="none">None</option>
142             <option value="even">Even</option>
143             <option value="mark">Mark</option>
144             <option value="odd">Odd</option>
145             <option value="space">Space</option>
146         </select>
147         </td><td>
148         <select type="text" id="node-config-input-stopbits" style="width: 80px;">
149             <option value="2">2</option>
150             <option value="1">1</option>
151         </select>
152     </td>
153     </tr></table><br/>
154
155     <div class="form-row">
156         <label for="node-config-input-out"><i class="fa fa-cut"></i> Split input</label>
157         <select type="text" id="node-config-input-out" style="width:52%;">
158             <option value="char">when character received is</option>
159             <option value="time">after a fixed timeout of</option>
160             <option value="count">a fixed number of characters</option>
161         </select>
162         <input type="text" id="node-config-input-newline"  style="width:50px;">
163         <span id="node-units"></span>
164     </div>
165
166     <div class="form-row">
167         <label for="node-config-input-bin"><i class="fa fa-sign-in"></i> and deliver</label>
168         <select type="text" id="node-config-input-bin" style="width: 77%;">
169             <option value="false">ascii strings</option>
170             <option value="bin">binary buffers</option>
171         </select>
172     </div>
173     <br/>
174     <div class="form-row" id="node-config-addchar">
175         <label for="node-config-input-addchar"><i class="fa fa-sign-out"></i> On output</label>
176         <select type="text" id="node-config-input-addchar" style="width: 77%;">
177             <option value="false">don't add 'split' character to output messages</option>
178             <option value="true">add 'split' character to output messages</option>
179         </select>
180     </div>
181     <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>
182     <div class="form-tips" id="tip-bin" hidden>Tip: In timeout mode timeout starts from arrival of first character.</div>
183     <script>
184         var previous = null;
185         $("#node-config-input-out").on('focus', function () { previous = this.value; }).change(function() {
186             if (previous == null) { previous = $("#node-config-input-out").val(); }
187             if ($("#node-config-input-out").val() == "char") {
188                 if (previous != "char") { $("#node-config-input-newline").val("\\n"); }
189                 $("#node-units").text("");
190                 $("#node-config-addchar").show();
191                 $("#tip-split").show();
192                 $("#tip-bin").hide();
193             }
194             else if ($("#node-config-input-out").val() == "time") {
195                 if (previous != "time") { $("#node-config-input-newline").val("0"); }
196                 $("#node-units").text("ms");
197                 $("#node-config-addchar").hide();
198                 $("#node-config-input-addchar").val("false");
199                 $("#tip-split").hide();
200                 $("#tip-bin").show();
201             }
202             else {
203                 if (previous != "count") { $("#node-config-input-newline").val("12"); }
204                 $("#node-units").text("chars");
205                 $("#node-config-addchar").hide();
206                 $("#node-config-input-addchar").val("false");
207                 $("#tip-split").hide();
208                 $("#tip-bin").hide();
209             }
210         });
211
212     </script>
213 </script>
214
215 <script type="text/javascript">
216     RED.nodes.registerType('serial-port',{
217         category: 'config',
218         defaults: {
219             //name: {value:""},
220             serialport: {value:"",required:true},
221             serialbaud: {value:57600,required:true},
222             databits: {value:8,required:true},
223             parity: {value:"none",required:true},
224             stopbits: {value:1,required:true},
225             newline: {value:"\\n"},
226             bin: {value:""},
227             out: {value:""},
228             addchar: {value:false}
229         },
230         label: function() {
231             this.serialbaud = this.serialbaud || 57600;
232             this.databits = this.databits || 8;
233             this.parity = this.parity || 'none';
234             this.stopbits = this.stopbits || 1;
235             return this.serialport+":"+this.serialbaud+"-"+this.databits+this.parity.charAt(0).toUpperCase()+this.stopbits;
236         },
237         oneditprepare: function() {
238             try {
239                 $("#node-config-input-serialport").autocomplete( "destroy" );
240             } catch(err) {
241             }
242             $("#node-config-lookup-serial").click(function() {
243                 //$("#node-config-lookup-serial-icon").removeClass('fa fa-search');
244                 //$("#node-config-lookup-serial-icon").addClass('fa fa-spinner');
245                 $("#node-config-lookup-serial").addClass('disabled');
246                 $.getJSON('serialports',function(data) {
247                     //$("#node-config-lookup-serial-icon").addClass('fa fa-search');
248                     //$("#node-config-lookup-serial-icon").removeClass('fa fa-spinner');
249                     $("#node-config-lookup-serial").removeClass('disabled');
250                     var ports = [];
251                     $.each(data, function(i, port){
252                         ports.push(port.comName);
253                     });
254                     $("#node-config-input-serialport").autocomplete({
255                         source:ports,
256                         minLength:0,
257                         close: function( event, ui ) {
258                             $("#node-config-input-serialport").autocomplete( "destroy" );
259                         }
260                     }).autocomplete("search","");
261                 });
262             });
263         }
264     });
265 </script>