UNPKG

node-red-contrib-serial-modbus

Version:
259 lines (250 loc) 9.08 kB
<!-- Copyright 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. 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="modbusSerialConfig"> <div class="form-row"> <label for="node-config-input-port"><i class="fa "></i> Port</label> <input type="text" id="node-config-input-port" placeholder="/dev/ttyUSB0"> </div> <div class="form-row"> <table width="100%"> <tr> <td width="100px"><i class="fa fa-wrench"></i> Settings</td> <td width="110px">Baud Rate</td> <td with="70px">Data Bits</td> <td width="80px">Parity</td> <td width="70px">Stop Bits</td> </tr> <tr> <td>&nbsp;</td> <td> <input type="text" id="node-config-input-baud" style="width:100px"> </td> <td> <select type="text" id="node-config-input-data" 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"> <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> </td> <td> <select type="text" id="node-config-input-stop" style="width:70px"> <option value="2">2</option> <option value="1">1</option> </select> </td> </tr> </table> </div> <div class="form-row"> <label for="node-input-name"><i class="fa "></i> Name</label> <input type="text" id="node-config-input-name" placeholder="ModbusSerial"> </div> </script> <script type="text/x-red" data-help-name="modbusSerialConfig"> <p>Details of the serial port to use to connect to the RS485 bus</p> </script> <script type="text/javascript"> RED.nodes.registerType("modbusSerialConfig",{ category:'config', defaults: { port: {value: '', required: true}, baud: {value: 38400, required: true}, data: {value: 8, required: true}, parity: {value: 'none', required: true}, stop: {value: 1, required: true}, name: {value: ''} }, label: function(){ return this.name || this.port + ":" + this.baud; } }); </script> <script type="text/x-red" data-template-name="modbusSerial in"> <div class="form-row"> <label for="node-input-port"><i class="fa "></i> Port</label> <input type="text" id="node-input-port" placeholder="/dev/ttyUSB0"> </div> <!-- <div class="form-row"> <table width="100%"> <tr> <td width="100px"><i class="fa fa-wrench"></i> Settings</td> <td width="110px">Baud Rate</td> <td with="70px">Data Bits</td> <td width="80px">Parity</td> <td width="70px">Stop Bits</td> </tr> <tr> <td>&nbsp;</td> <td> <input type="text" id="node-input-baud" style="width:100px"> </td> <td> <select type="text" id="node-input-data" 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-input-parity" style="width:80px"> <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> </td> <td> <select type="text" id="node-input-stop" style="width:70px"> <option value="2">2</option> <option value="1">1</option> </select> </td> </tr> </table> </div> --> <div class="form-row"> <label for="node-input-slaves"><i class="fa "></i> Slaves</label> <input type="text" id="node-input-slaves"> </div> <div class="form-row"> <label for="node-input-dtype"><i class="fa "></i> Type</label> <select type="text" id="node-input-dtype"> <option value="descrete">Descrete</option> <option value="coil">Coil</option> <option value="input">Input Register</option> <option value="holding">Holding Register</option> </select> </div> <div class="form-row"> <label for="node-input-start"><i class="fa "></i> Start</label> <input type="text" id="node-input-start"> </div> <div class="form-row"> <label for="node-input-count"><i class="fa "></i> Count</label> <input type="text" id="node-input-count"> </div> <div class="form-row"> <label for="node-input-period"><i class="fa "></i> Poll Period</label> <input type="text" id="node-input-period"> </div> <div class="form-row"> <label for="node-input-topic"><i class="fa "></i> Topic Prefix</label> <input type="text" id="node-input-topic"> </div> <div class="form-row"> <label for="node-input-name"><i class="fa "></i> Name</label> <input type="text" id="node-input-name"> </div> </script> <script type="text/x-red" data-help-name="modbusSerial in"> <p>A Node-RED node to read values from Modus devices over a serial connection.</p> <p>The node takes a comma seperated list of slave ids and start and number of fields to read. The node will poll each slave in turn at the given interval and send one message per slave.</p> <p>The output messages have a buffer payload and the the slave id appended to the configured topic.</p> <p>For help with parsing the buffer into constituent parts see the Formating data section of the README.md</p> </script> <script type="text/javascript"> RED.nodes.registerType("modbusSerial in",{ category:'modbus', defaults: { port: {type: 'modbusSerialConfig', required: true}, // port: {value:"", required: true}, // baud: {value:38400, required: true}, // data: {value:8, required: true}, // parity: {value:'none', required: true}, // stop: {value:1, required: true}, slaves: {required: true}, start: {required:true}, count: {value:1, required: true}, dtype: {value:'coil', required: true}, period: {value:60, required: true}, topic: {value: ''}, name: {value:''} }, outputs: 1, inputs: 0, label: function() { return this.name || "Modbus-Serial In"; }, color: 'grey', icon: 'mb.png' }); </script> <script type="text/x-red" data-template-name="modbusSerial out"> <div class="form-row"> <label for="node-input-port"><i class="fa "></i> Port</label> <input type="text" id="node-input-port" placeholder="/dev/ttyUSB0"> </div> <div class="form-row"> <label for="node-input-slave"><i class="fa "></i> Slave</label> <input type="text" id="node-input-slave"> </div> <div class="form-row"> <label for="node-input-dtype"><i class="fa "></i> Type</label> <select type="text" id="node-input-dtype"> <option value="descrete">Descrete</option> <option value="coil">Coil</option> <option value="input">Input Register</option> <option value="holding">Holding Register</option> </select> </div> <div class="form-row"> <label for="node-input-start"><i class="fa "></i> Start</label> <input type="text" id="node-input-start"> </div> </script> <script type="text/x-red" data-help-name="modbusSerial out"> <p>A node to update the state of a Modbus device.</p> <p>Slave is the address of the device to update (only one device). If left blank then the msg.topic will be used if it's a integer. The last part of topic, seperated by '/' will be used</p> <p>The <i>msg.payload</i> of the input should be a buffer object formated to match what ever format the device expects. The Formating Data section of the README.md has guidence on how to do this.</p> </script> <script type="text/javascript"> RED.nodes.registerType("modbusSerial out",{ category:'modbus', defaults: { port: {type: 'modbusSerialConfig', required: true}, slave: {}, start: {required:true}, dtype: {value:'coil', required: true}, topic: {value: ''}, name: {value:''} }, outputs: 0, inputs: 1, label: function(){ return this.name || "Modbus-Serial Out"; }, color: 'grey', icon: 'mb.png' }); </script>