UNPKG

node-red-contrib-omron-fins

Version:

OMRON FINS Ethernet protocol functions 'Read' and 'write' for communicating with OMRON PLCs from node-red

168 lines (155 loc) 8.01 kB
<!-- MIT License Copyright (c) 2019, 2020, 2021 Steve-Mcl Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> <script type="text/javascript"> RED.nodes.registerType('FINS Write', { category: 'OMRON', color: '#0090d4', defaults: { name: { value: "" }, connection: { type: "FINS Connection", required: true }, addressType: { value: "msg" }, address: { value: "topic", validate: RED.validators.typedInput("addressType") }, dataType: { value: "msg" }, data: { value: "payload", validate: RED.validators.typedInput("dataType") }, msgPropertyType: { value: "str" }, msgProperty: { value: "payload", validate: RED.validators.typedInput("msgPropertyType") }, }, inputs: 1, outputs: 1, inputLabels: "Trigger request", outputLabels: "Write result", align: "right", icon: "write.png", label: function () { return this.name || ((this.addressType == "str" && this.address != "") ? "Write: " + this.address : "FINS Write"); }, oneditprepare: function () { var node = this; function setupTypedInput(varName, types, def) { let varSel = '#node-input-' + varName; let typeSel = varSel + 'Type'; let varVal = node[varName]; let typeVal = node[varName + 'Type']; if (typeVal == null || typeVal === 'none') { typeVal = def; } else if (typeVal === 'string') { typeVal = "str"; } else if (typeVal === 'number') { typeVal = "num"; } $(typeSel).val(typeVal); $(varSel).typedInput({ default: def, typeField: $(typeSel), types: types }); return $(varSel).typedInput('type', typeVal); } setupTypedInput('address', ["msg","flow","global","str"], 'msg'); setupTypedInput('data', ["msg","flow","global","num", "json"], 'msg'); setupTypedInput('msgProperty', ["msg"], 'msg'); } }); </script> <script type="text/html" data-template-name="FINS Write"> <div class="form-row"> <label style="width:120px;" for="node-input-name"><i class="icon-tag"></i> <span data-i18n="write.label.name"> Name</span></label> <input style="width:70%" type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-row"> <label style="width:120px;" for="node-input-connection"><i class="icon-globe"></i><span data-i18n="write.label.connection"> Connection</span></label> <input style="width:70%" type="text" id="node-input-connection"> </div> <div class="form-row"> <label style="width:120px;" for="node-input-address"><i class="fa fa-envelope"></i> <span data-i18n="write.label.address"> Address</span></label> <input type="hidden" id="node-input-addressType"> <input style="width:70%" type="text" id="node-input-address" placeholder=""> </div> <div class="form-row"> <label style="width:120px;" for="node-input-data"><i class="fa fa-ellipsis-h"></i> <span data-i18n="write.label.data"> Data</span></label> <input type="hidden" id="node-input-dataType"> <input style="width:70%" type="text" id="node-input-data" placeholder=""> </div> <div class="form-row"> <label style="width:120px;" for="node-input-msgProperty"><i class="fa fa-sign-out"></i> <span data-i18n="write.label.msgProperty"> Output property</span></label> <input type="hidden" id="node-input-msgPropertyType"> <input style="width:70%" type="text" id="node-input-msgProperty" placeholder="payload"> </div> </script> <script type="text/html" data-help-name="FINS Write"> <p>Write 16 bit WORD or BIT data to an OMRON PLC using FINS protocol</p> <h3>Foreword</h3> <dl class="message-properties"> <dd> Example flows have been included to help you get started. Click the hamburger menu <a class="button" href="#"><i class="fa fa-bars"></i></a>, select <b>import</b> then <b>examples</b> (or press <kbd>ctrl+i</kbd>) </dd> </dl> <h3>Properties</h3> <dl class="message-properties"> <dt class="required">Connection<span class="property-type">FINS Connection</span></dt> <dd>The PLC connection</dd> <dt class="required">Address<span class="property-type">string</span></dt> <dd>PLC WORD or BIT Memory Address. Depending on the PLC Type selected in the connection, the address will use the PLC standard addressing format. Some examples... <ul> <li>CIO2000 - Core IO WORD 2000</li> <li>CIO50.0 - Core IO WORD 50 BIT 0</li> <li>D100 - Data Memory WORD 100</li> <li>D20.15 - Data Memory WORD 20 BIT 15</li> <li>E0_200 - Extended Data Memory Bank 0, WORD 200</li> <li>E1_5.7 - Extended Data Memory Bank 1, WORD 5 BIT 7</li> <li>H10 - Holding Relay WORD 10</li> <li>H9.9 - Holding Relay WORD 9 BIT 9</li> <li>W500 - Work Area WORD 500</li> <li>W0.0 - Work Area WORD 0 BIT 0</li> <li>A264 - Auxiliary Area WORD 264</li> <li>A0.1 - Auxiliary Area WORD 0 BIT 1</li> <li>DR10 - Data Register 10</li> <li>IR0 - Index Register 0</li> <li>T50 - Timer 50 PV</li> <li>C50 - Counter 50 PV</li> </ul> </dd> <dt class="required">Data<span class="property-type">number | number[] | bool | bool[] | string</span></dt> <dd>Data to write to the PLC</dd> </dl> <h3>Output</h3> <p> Upon success, the SID (Sequence ID) will be sent in <code>msg.payload</code>. This should be a number between 1 and 254. <br> Additional details are sent in <code>msg.fins</code> - use a debug node set to "show complete message" to inspect the available properties. </p> <h3>Details</h3> <p> Incoming <code>data</code> must be one of the following... <ul> <li>bool (This will be written to the BIT address provided)</li> <li>bool array (This will be written to the PLC starting at the BIT address provided)</li> <li>integer (This will be written to the WORD address provided)</li> <li>integer array (This will be written to the PLC starting at the WORD address provided)</li> <li>string containing a WORD or BIT value (This will be written to the PLC at the WORD or BIT address provided)</li> <li>comma separated list of WORD or BIT values (These will be written to the PLC starting at the WORD or BIT address provided)</li> </ul> The count of elements in <code>data</code> determines how many PLC addresses are modified. e.g.<br> * if <code>data</code> is <code>[1,2,3,4,5]</code> and <code>D100</code> is the <code>address</code>, then D100 ~ D104 will be modified.<br> * if <code>data</code> is <code>[true,false,1,0]</code> and <code>CIO7.7</code> is the <code>address</code>, then CIO7.7 ~ CIO7.10 will be modified.<br> </p> <h3>Advanced</h3> <p><code>msg.finsOptions</code> can be used to route the FINS command to another network and node. e.g. <code>msg.finsOption = {"DNA": 2, "DA1": 10}; //route this command to FINS NETWORK2, NODE10</code> </p> </script>