@ali-pay/node-red-contrib-s7 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/red/s7.html ADDED
@@ -0,0 +1,1444 @@
1
+ <!--
2
+ Copyright: (c) 2016-2020, ST-One Ltda., Guilherme Francescon Cittolin <guilherme@st-one.io>
3
+ GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
4
+ -->
5
+
6
+ <script type="text/x-red" data-template-name="s7 endpoint">
7
+ <div class="form-row">
8
+ <ul style="background: #fff; min-width: 600px; margin-bottom: 20px;" id="node-config-s7-endpoint-tabs"></ul>
9
+ </div>
10
+ <div id="node-config-s7-endpoint-tabs-content" style="min-height: 170px;">
11
+ <div id="s7-endpoint-tab-connection" style="display:none">
12
+ <div class="form-row">
13
+ <label for="node-config-input-transport"><i class="fa fa-plug"></i> <span data-i18n="s7.endpoint.label.transport"></span></label>
14
+ <select type="text" id="node-config-input-transport">
15
+ <option value="iso-on-tcp" data-i18n="s7.endpoint.transport.iso-on-tcp"></option>
16
+ <option value="mpi-s7" data-i18n="s7.endpoint.transport.mpi-s7"></option>
17
+ </select>
18
+ </div>
19
+ <div id="s7-endpoint-transport-iso-on-tcp" style="display:none; padding-left: 20px;">
20
+ <div class="form-row">
21
+ <label for="node-config-input-address"><i class="fa fa-globe"></i> <span data-i18n="s7.endpoint.label.address"></span></label>
22
+ <input class="input-append-left" type="text" id="node-config-input-address" data-i18n="[placeholder]s7.endpoint.placeholder.address" style="width: 40%;">
23
+ <label for="node-config-input-port" style="margin-left: 10px; width: auto; "> <span data-i18n="s7.endpoint.label.port"></span></label>
24
+ <input type="text" id="node-config-input-port" data-i18n="[placeholder]s7.endpoint.label.port" style="width: 50px; margin-right: 10px;">
25
+ <a id="node-config-lookup-plc-pn" class="btn red-ui-button disabled" data-i18n="[title]s7.endpoint.label.search"><i class="fa fa-search"></i></a>
26
+ <a id="node-config-flash-plc-pn" class="btn red-ui-button disabled" data-i18n="[title]s7.endpoint.label.flash-led"><i class="fa fa-lightbulb-o"></i></a>
27
+ </div>
28
+ <div class="form-row">
29
+ <label for="node-config-input-connmode"><i class="fa fa-sliders"></i> <span data-i18n="s7.endpoint.label.connmode"></span></label>
30
+ <select type="text" id="node-config-input-connmode">
31
+ <option value="rack-slot" data-i18n="s7.endpoint.connmode.rack-slot"></option>
32
+ <option value="tsap" data-i18n="s7.endpoint.connmode.tsap"></option>
33
+ </select>
34
+ </div>
35
+ <div class="form-row" id="node-config-s7-endpoint-mode-rackslot">
36
+ <label for="node-config-input-rack"><i class="fa fa-sitemap"></i> <span data-i18n="s7.endpoint.label.rack"></span></label>
37
+ <input class="input-append-left" type="text" id="node-config-input-rack" data-i18n="[placeholder]s7.endpoint.label.rack" style="width: 50px">
38
+ <label for="node-config-input-slot" style="margin-left: 10px; width: 35px; "> <span data-i18n="s7.endpoint.label.slot"></span></label>
39
+ <input type="text" id="node-config-input-slot" data-i18n="[placeholder]s7.endpoint.label.slot" style="width:50px">
40
+ </div>
41
+ <div class="form-row" id="node-config-s7-endpoint-mode-tsap">
42
+ <label for="node-config-input-localtsaphi"><i class="fa fa-exchange"></i> <span data-i18n="s7.endpoint.label.tsap-local"></span></label>
43
+ <input class="input-append-left" type="text" id="node-config-input-localtsaphi" style="width: 35px"><span><b>.</b></span>
44
+ <input class="input-append-left" type="text" id="node-config-input-localtsaplo" style="width: 35px">
45
+ <label for="node-config-input-remotetsaphi" style="margin-left: 10px"> <span data-i18n="s7.endpoint.label.tsap-remote"></span></label>
46
+ <input class="input-append-left" type="text" id="node-config-input-remotetsaphi" style="width: 35px"><span><b>.</b></span>
47
+ <input class="input-append-left" type="text" id="node-config-input-remotetsaplo" style="width: 35px">
48
+ </div>
49
+ </div>
50
+ <div id="s7-endpoint-transport-mpi-s7" style="display:none; padding-left: 20px;">
51
+ <div class="form-row">
52
+ <label for="node-config-input-adapter"><i class="fa fa-exchange"></i> <span data-i18n="s7.endpoint.label.adapter"></span></label>
53
+ <input type="text" id="node-config-input-adapter" data-i18n="[placeholder]s7.endpoint.label.adapter">
54
+ <input type="text" id="s7-endpoint-adapter-placeholder" data-i18n="[placeholder]s7.endpoint.label.adapterplaceholder" disabled style="display:none">
55
+ </div>
56
+ <div class="form-row">
57
+ <label for="node-config-input-busaddr"><i class="fa fa-sitemap"></i> <span data-i18n="s7.endpoint.label.busaddr"></span></label>
58
+ <input type="text" id="node-config-input-busaddr" style="width: 60px;">
59
+ </div>
60
+ </div>
61
+ <div class="form-row">
62
+ <label for="node-config-input-cycletime"><i class="fa fa-refresh"></i> <span data-i18n="s7.endpoint.label.cycletime"></span></label>
63
+ <input type="text" id="node-config-input-cycletime" data-i18n="[placeholder]s7.endpoint.label.cycletime" style="width: 60px;"> <span>ms</span>
64
+ </div>
65
+ <div class="form-row">
66
+ <label for="node-config-input-timeout"><i class="fa fa-clock-o"></i> <span data-i18n="s7.endpoint.label.timeout"></span></label>
67
+ <input type="text" id="node-config-input-timeout" data-i18n="[placeholder]s7.endpoint.label.timeout" style="width: 60px;"> <span>ms</span>
68
+ </div>
69
+ <div class="form-row">
70
+ <label for="node-config-input-name"><i class="fa fa-tag"></i> <span data-i18n="s7.label.name"></span></label>
71
+ <input type="text" id="node-config-input-name" data-i18n="[placeholder]s7.label.name">
72
+ </div>
73
+ </div>
74
+ <div id="s7-endpoint-tab-variables" style="display:none">
75
+ <div class="form-row" style="margin-bottom:0;">
76
+ <label><i class="fa fa-list"></i> <span data-i18n="s7.endpoint.label.variables.list"></span></label>
77
+ </div>
78
+ <div class="form-row node-input-variables-container-row" style="margin-bottom: 0px;">
79
+ <div id="node-config-input-variables-container-div" style="box-sizing: border-box; border-radius: 5px; height: 300px; padding: 5px; border: 1px solid #ccc; overflow-y:scroll;">
80
+ <ol id="node-config-input-variables-container" style=" list-style-type:none; margin: 0;"></ol>
81
+ </div>
82
+ </div>
83
+ <div class="form-row">
84
+ <a href="#" class="editor-button editor-button-small" id="node-config-s7-endpoint-var-export" style="margin: 4px; float: right"><i class="fa fa-download"></i> <span data-i18n="s7.endpoint.label.variables.export"></span></a>
85
+ <input type="file" id="node-config-s7-endpoint-var-import" style="display: none"/>
86
+ <a href="#" class="editor-button editor-button-small" id="node-config-s7-endpoint-var-import-btn" style="margin: 4px; float: right"><i class="fa fa-upload"></i> <span data-i18n="s7.endpoint.label.variables.import"></span></a>
87
+ <a href="#" class="editor-button editor-button-small" id="node-config-input-add-variable" style="margin: 4px;"><i class="fa fa-plus"></i> <span data-i18n="s7.endpoint.label.variables.add"></span></a>
88
+ <a href="#" class="editor-button editor-button-small" id="node-config-s7-endpoint-var-clean" style="margin: 4px;"><i class="fa fa-trash-o"></i> <span data-i18n="s7.endpoint.label.variables.clean"></span></a>
89
+ </div>
90
+ </div>
91
+ </div>
92
+ </script>
93
+
94
+ <script type="text/x-red" data-help-name="s7 endpoint">
95
+ <p>Configures the connection to a PLC</p>
96
+ <p>This node was created as part of the <a href="https://st-one.io" target="_blank">ST-One</a> project</p>
97
+
98
+ <h3>Details</h3>
99
+ <p>
100
+ The <b>Cycle time</b> configuration specifies the time interval in which
101
+ all variables will be read from the PLC. A value of <code>0</code> disables
102
+ automatic reading, and then a manual triggering is required from the
103
+ <i>s7 control</i> node
104
+ </p>
105
+ <p>
106
+ The <b>Timeout</b> parameter sets the maximum amount of time that the PLC
107
+ may take to answer our requests. It may be desirable to raise this time if
108
+ the network is busy of it's latency is high
109
+ </p>
110
+ <p>
111
+ It's possible to log the PLC communication by setting the <b>Debug</b> option
112
+ to "On" of "Off". By default, the behavior is controlled by the <code>-v</code>
113
+ command-line parameter when running Node-RED
114
+ </p>
115
+ <p>
116
+ In the <b>Transport</b> option it is possible to select method used
117
+ to reach the PLC. Different connection options are available depending
118
+ on the selected option:
119
+ </p>
120
+ <h4><i>Ethernet (ISO-on-TCP)</i></h4>
121
+ <p>
122
+ Connects to the specified ethernet address and port number of the PLC.
123
+ </p>
124
+ <ul>
125
+ <li>
126
+ <b>Mode</b>: selects between <i>Rack/Slot</i> and <i>TSAP</i>
127
+ connection modes. Usually the <i>Rack/Slot</i> mode is used, except when
128
+ connecting to Logo devices where the only option is the <i>TSAP</i>
129
+ method
130
+ </li>
131
+ </ul>
132
+ <h4><i>MPI/PPI/DP Adapter</i></h4>
133
+ <p>
134
+ Connects to the PLC using MPI/PPI/DP Adapters available on the system. Requires
135
+ the installation of <code>node-red-contrib-mpi-s7</code>.
136
+ </p>
137
+ <ul>
138
+ <li>
139
+ <b>Address</b>: specifies the address on the bus of the PLC
140
+ that we will communicate to.
141
+ </li>
142
+ </ul>
143
+
144
+
145
+ <h3>Notes on S7-1200/S7-1500</h3>
146
+ <p>
147
+ Some extra configuration may be needed on the S7-1200 and S7-1500 series
148
+ of PLCS in order to access their data:
149
+ <ul>
150
+ <li>
151
+ "Optimized block access" must be disabled for the DBs we want
152
+ to access
153
+ </li>
154
+ <li>
155
+ In the "Protection" section of the CPU Properties, enable the
156
+ "Permit access with PUT/GET" checkbox
157
+ </li>
158
+ </ul>
159
+ </p>
160
+
161
+ <h3>Variable addressing</h3>
162
+ <p>
163
+ The variables and their addresses configured on the <strong>S7 Endpoint</strong>
164
+ follow a slightly different scheme than used on Step 7 or TIA Portal.
165
+ Here are some examples that may guide you on addressing your variables:
166
+ </p>
167
+ <style>
168
+ table {
169
+ padding: 0; }
170
+ table tr {
171
+ border-top: 1px solid #cccccc;
172
+ background-color: white;
173
+ margin: 0;
174
+ padding: 0; }
175
+ table tr:nth-child(2n) {
176
+ background-color: #f8f8f8; }
177
+ table tr th {
178
+ font-weight: bold;
179
+ border: 1px solid #cccccc;
180
+ text-align: left;
181
+ margin: 0;
182
+ padding: 6px 13px; }
183
+ table tr td {
184
+ border: 1px solid #cccccc;
185
+ text-align: left;
186
+ margin: 0;
187
+ padding: 6px 13px; }
188
+ table tr th :first-child, table tr td :first-child {
189
+ margin-top: 0; }
190
+ table tr th :last-child, table tr td :last-child {
191
+ margin-bottom: 0; }
192
+ </style>
193
+ <table>
194
+ <thead>
195
+ <tr>
196
+ <th>Address</th>
197
+ <th>Step7 equivalent</th>
198
+ <th>JS Data type</th>
199
+ <th>Description</th>
200
+ </tr>
201
+ </thead>
202
+ <tbody>
203
+ <tr>
204
+ <td><code>DB5,X0.1</code></td>
205
+ <td><code>DB5.DBX0.1</code></td>
206
+ <td>Boolean</td>
207
+ <td>Bit 1 of byte 0 of DB 5</td>
208
+ </tr>
209
+ <tr>
210
+ <td><code>DB23,B1</code> or <code>DB23,BYTE1</code></td>
211
+ <td><code>DB23.DBB1</code></td>
212
+ <td>Number</td>
213
+ <td>Byte 1 (0-255) of DB 23</td>
214
+ </tr>
215
+ <tr>
216
+ <td><code>DB100,C2</code> or <code>DB100,CHAR2</code></td>
217
+ <td><code>DB100.DBB2</code></td>
218
+ <td>String</td>
219
+ <td>Byte 2 of DB 100 as a Char</td>
220
+ </tr>
221
+ <tr>
222
+ <td><code>DB42,I3</code> or <code>DB42,INT3</code></td>
223
+ <td><code>DB42.DBW3</code></td>
224
+ <td>Number</td>
225
+ <td>Signed 16-bit number at byte 3 of DB 42</td>
226
+ </tr>
227
+ <tr>
228
+ <td><code>DB57,WORD4</code></td>
229
+ <td><code>DB57.DBW4</code></td>
230
+ <td>Number</td>
231
+ <td>Unsigned 16-bit number at byte 4 of DB 57</td>
232
+ </tr>
233
+ <tr>
234
+ <td><code>DB13,DI5</code> or <code>DB13,DINT5</code></td>
235
+ <td><code>DB13.DBD5</code></td>
236
+ <td>Number</td>
237
+ <td>Signed 32-bit number at byte 5 of DB 13</td>
238
+ </tr>
239
+ <tr>
240
+ <td><code>DB19,DW6</code> or <code>DB19,DWORD6</code></td>
241
+ <td><code>DB19.DBD6</code></td>
242
+ <td>Number</td>
243
+ <td>Unsigned 32-bit number at byte 6 of DB 19</td>
244
+ </tr>
245
+ <tr>
246
+ <td><code>DB21,R7</code> or <code>DB21,REAL7</code></td>
247
+ <td><code>DB19.DBD7</code></td>
248
+ <td>Number</td>
249
+ <td>Floating point 32-bit number at byte 7 of DB 21</td>
250
+ </tr>
251
+ <tr>
252
+ <td><code>DB2,S7.10</code>*</td>
253
+ <td>-</td>
254
+ <td>String</td>
255
+ <td>String of length 10 starting at byte 7 of DB 2</td>
256
+ </tr>
257
+ <tr>
258
+ <td><code>I1.0</code> or <code>E1.0</code></td>
259
+ <td><code>I1.0</code> or <code>E1.0</code></td>
260
+ <td>Boolean</td>
261
+ <td>Bit 0 of byte 1 of input area</td>
262
+ </tr>
263
+ <tr>
264
+ <td><code>Q2.1</code> or <code>A2.1</code></td>
265
+ <td><code>Q2.1</code> or <code>A2.1</code></td>
266
+ <td>Boolean</td>
267
+ <td>Bit 1 of byte 2 of output area</td>
268
+ </tr>
269
+ <tr>
270
+ <td><code>M3.2</code></td>
271
+ <td><code>QM3.2</code></td>
272
+ <td>Boolean</td>
273
+ <td>Bit 2 of byte 3 of memory area</td>
274
+ </tr>
275
+ <tr>
276
+ <td><code>IB4</code> or <code>EB4</code></td>
277
+ <td><code>IB4</code> or <code>EB4</code></td>
278
+ <td>Number</td>
279
+ <td>Byte 4 (0 -255) of input area</td>
280
+ </tr>
281
+ <tr>
282
+ <td><code>QB5</code> or <code>AB5</code></td>
283
+ <td><code>QB5</code> or <code>AB5</code></td>
284
+ <td>Number</td>
285
+ <td>Byte 5 (0 -255) of output area</td>
286
+ </tr>
287
+ <tr>
288
+ <td><code>MB6</code></td>
289
+ <td><code>MB6</code></td>
290
+ <td>Number</td>
291
+ <td>Byte 6 (0 -255) of memory area</td>
292
+ </tr>
293
+ <tr>
294
+ <td><code>IC7</code> or <code>EC7</code></td>
295
+ <td><code>IB7</code> or <code>EB7</code></td>
296
+ <td>String</td>
297
+ <td>Byte 7 of input area as a Char</td>
298
+ </tr>
299
+ <tr>
300
+ <td><code>QC8</code> or <code>AC8</code></td>
301
+ <td><code>QB8</code> or <code>AB8</code></td>
302
+ <td>String</td>
303
+ <td>Byte 8 of output area as a Char</td>
304
+ </tr>
305
+ <tr>
306
+ <td><code>MC9</code></td>
307
+ <td><code>MB9</code></td>
308
+ <td>String</td>
309
+ <td>Byte 9 of memory area as a Char</td>
310
+ </tr>
311
+ <tr>
312
+ <td><code>II10</code> or <code>EI10</code></td>
313
+ <td><code>IW10</code> or <code>EW10</code></td>
314
+ <td>Number</td>
315
+ <td>Signed 16-bit number at byte 10 of input area</td>
316
+ </tr>
317
+ <tr>
318
+ <td><code>QI12</code> or <code>AI12</code></td>
319
+ <td><code>QW12</code> or <code>AW12</code></td>
320
+ <td>Number</td>
321
+ <td>Signed 16-bit number at byte 12 of output area</td>
322
+ </tr>
323
+ <tr>
324
+ <td><code>MI14</code></td>
325
+ <td><code>MW14</code></td>
326
+ <td>Number</td>
327
+ <td>Signed 16-bit number at byte 14 of memory area</td>
328
+ </tr>
329
+ <tr>
330
+ <td><code>IW16</code> or <code>EW16</code></td>
331
+ <td><code>IW16</code> or <code>EW16</code></td>
332
+ <td>Number</td>
333
+ <td>Unsigned 16-bit number at byte 16 of input area</td>
334
+ </tr>
335
+ <tr>
336
+ <td><code>QW18</code> or <code>AW18</code></td>
337
+ <td><code>QW18</code> or <code>AW18</code></td>
338
+ <td>Number</td>
339
+ <td>Unsigned 16-bit number at byte 18 of output area</td>
340
+ </tr>
341
+ <tr>
342
+ <td><code>MW20</code></td>
343
+ <td><code>MW20</code></td>
344
+ <td>Number</td>
345
+ <td>Unsigned 16-bit number at byte 20 of memory area</td>
346
+ </tr>
347
+ <tr>
348
+ <td><code>IDI22</code> or <code>EDI22</code></td>
349
+ <td><code>ID22</code> or <code>ED22</code></td>
350
+ <td>Number</td>
351
+ <td>Signed 32-bit number at byte 22 of input area</td>
352
+ </tr>
353
+ <tr>
354
+ <td><code>QDI24</code> or <code>ADI24</code></td>
355
+ <td><code>QD24</code> or <code>AD24</code></td>
356
+ <td>Number</td>
357
+ <td>Signed 32-bit number at byte 24 of output area</td>
358
+ </tr>
359
+ <tr>
360
+ <td><code>MDI26</code></td>
361
+ <td><code>MD26</code></td>
362
+ <td>Number</td>
363
+ <td>Signed 32-bit number at byte 26 of memory area</td>
364
+ </tr>
365
+ <tr>
366
+ <td><code>ID28</code> or <code>ED28</code></td>
367
+ <td><code>ID28</code> or <code>ED28</code></td>
368
+ <td>Number</td>
369
+ <td>Unsigned 32-bit number at byte 28 of input area</td>
370
+ </tr>
371
+ <tr>
372
+ <td><code>QD30</code> or <code>AD30</code></td>
373
+ <td><code>QD30</code> or <code>AD30</code></td>
374
+ <td>Number</td>
375
+ <td>Unsigned 32-bit number at byte 30 of output area</td>
376
+ </tr>
377
+ <tr>
378
+ <td><code>MD32</code></td>
379
+ <td><code>MD32</code></td>
380
+ <td>Number</td>
381
+ <td>Unsigned 32-bit number at byte 32 of memory area</td>
382
+ </tr>
383
+ <tr>
384
+ <td><code>IR34</code> or <code>ER34</code></td>
385
+ <td><code>IR34</code> or <code>ER34</code></td>
386
+ <td>Number</td>
387
+ <td>Floating point 32-bit number at byte 34 of input area</td>
388
+ </tr>
389
+ <tr>
390
+ <td><code>QR36</code> or <code>AR36</code></td>
391
+ <td><code>QR36</code> or <code>AR36</code></td>
392
+ <td>Number</td>
393
+ <td>Floating point 32-bit number at byte 36 of output area</td>
394
+ </tr>
395
+ <tr>
396
+ <td><code>MR38</code></td>
397
+ <td><code>MR38</code></td>
398
+ <td>Number</td>
399
+ <td>Floating point 32-bit number at byte 38 of memory area</td>
400
+ </tr>
401
+ <tr>
402
+ <td><code>DB1,DT0</code></td>
403
+ <td><code>-</code></td>
404
+ <td>Date**</td>
405
+ <td>A timestamp in the DATE_AND_TIME format</td>
406
+ </tr>
407
+ <tr>
408
+ <td><code>DB1,DTZ10</code></td>
409
+ <td><code>-</code></td>
410
+ <td>Date**</td>
411
+ <td>A timestamp in the DATE_AND_TIME format, in UTC</td>
412
+ </tr>
413
+ <tr>
414
+ <td><code>DB2,DTL2</code></td>
415
+ <td><code>-</code></td>
416
+ <td>Date**</td>
417
+ <td>A timestamp in the DTL format</td>
418
+ </tr>
419
+ <tr>
420
+ <td><code>DB1,DTLZ12</code></td>
421
+ <td><code>-</code></td>
422
+ <td>Date**</td>
423
+ <td>A timestamp in the DTL format, in UTC</td>
424
+ </tr>
425
+ <tr>
426
+ <td><code>DB57,RWORD4</code></td>
427
+ <td><code>DB57.DBW4</code></td>
428
+ <td>Number</td>
429
+ <td>Unsigned 16-bit number at byte 4 of DB 57, interpreted as Little-Endian</td>
430
+ </tr>
431
+ <tr>
432
+ <td><code>DB13,RDI5</code> or <code>DB13,RDINT5</code></td>
433
+ <td><code>DB13.DBD5</code></td>
434
+ <td>Number</td>
435
+ <td>Signed 32-bit number at byte 5 of DB 13, interpreted as Little-Endian</td>
436
+ </tr>
437
+ <tr>
438
+ <td><code>MRW20</code></td>
439
+ <td><code>MRW20</code></td>
440
+ <td>Number</td>
441
+ <td>Unsigned 16-bit number at byte 20 of memory area, interpreted as Little-Endian</td>
442
+ </tr>
443
+ </tbody>
444
+ </table>
445
+
446
+ <p>*) Note that strings on the PLC uses 2 extra bytes at start for size/length of the string</p>
447
+ <p>**) Note that javascript's <code>Date</code> are <i>always</i> represented in UTC. Please use other nodes like <a href="https://flows.nodered.org/node/node-red-contrib-moment" target="_blank">node-red-contrib-moment</a> to properly handle type conversions</p>
448
+ </script>
449
+
450
+ <script type="text/javascript">
451
+ /*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
452
+ var saveAs = saveAs || function (e) { "use strict"; if (typeof e === "undefined" || typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) { return } var t = e.document, n = function () { return e.URL || e.webkitURL || e }, r = t.createElementNS("http://www.w3.org/1999/xhtml", "a"), o = "download" in r, a = function (e) { var t = new MouseEvent("click"); e.dispatchEvent(t) }, i = /constructor/i.test(e.HTMLElement) || e.safari, f = /CriOS\/[\d]+/.test(navigator.userAgent), u = function (t) { (e.setImmediate || e.setTimeout)(function () { throw t }, 0) }, s = "application/octet-stream", d = 1e3 * 40, c = function (e) { var t = function () { if (typeof e === "string") { n().revokeObjectURL(e) } else { e.remove() } }; setTimeout(t, d) }, l = function (e, t, n) { t = [].concat(t); var r = t.length; while (r--) { var o = e["on" + t[r]]; if (typeof o === "function") { try { o.call(e, n || e) } catch (a) { u(a) } } } }, p = function (e) { if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)) { return new Blob([String.fromCharCode(65279), e], { type: e.type }) } return e }, v = function (t, u, d) { if (!d) { t = p(t) } var v = this, w = t.type, m = w === s, y, h = function () { l(v, "writestart progress write writeend".split(" ")) }, S = function () { if ((f || m && i) && e.FileReader) { var r = new FileReader; r.onloadend = function () { var t = f ? r.result : r.result.replace(/^data:[^;]*;/, "data:attachment/file;"); var n = e.open(t, "_blank"); if (!n) e.location.href = t; t = undefined; v.readyState = v.DONE; h() }; r.readAsDataURL(t); v.readyState = v.INIT; return } if (!y) { y = n().createObjectURL(t) } if (m) { e.location.href = y } else { var o = e.open(y, "_blank"); if (!o) { e.location.href = y } } v.readyState = v.DONE; h(); c(y) }; v.readyState = v.INIT; if (o) { y = n().createObjectURL(t); setTimeout(function () { r.href = y; r.download = u; a(r); h(); c(y); v.readyState = v.DONE }); return } S() }, w = v.prototype, m = function (e, t, n) { return new v(e, t || e.name || "download", n) }; if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) { return function (e, t, n) { t = t || e.name || "download"; if (!n) { e = p(e) } return navigator.msSaveOrOpenBlob(e, t) } } w.abort = function () { }; w.readyState = w.INIT = 0; w.WRITING = 1; w.DONE = 2; w.error = w.onwritestart = w.onprogress = w.onwrite = w.onabort = w.onerror = w.onwriteend = null; return m }(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this.content); if (typeof module !== "undefined" && module.exports) { module.exports.saveAs = saveAs } else if (typeof define !== "undefined" && define !== null && define.amd !== null) { define("FileSaver.js", function () { return saveAs }) }
453
+ </script>
454
+
455
+ <script type="text/javascript">
456
+
457
+ function validateS7Address(address) {
458
+
459
+ if (!address) return 'ERR_PARSE_EMPTY';
460
+
461
+ var NODES7_REGEX_ADDR = /^(?:DB(\d+),)?([A-Z]+)(\d+)(?:\.(\d+))?(?:\.(\d+))?$/;
462
+ var NODES7_ADDRTYPE = ["E", "I", "A", "Q", "P", "M", "T", "C"];
463
+ var NODES7_DATATYPE = ["X", "B", "C", "I", "DI", "W", "D", "DW", "R", "RI", "RDI", "RW", "RD", "RDW", "RR"];
464
+ var NODES7_DATATYPE_DB = ["X", "BYTE", "CHAR", "STRING", "INT", "DINT", "WORD", "DWORD", "REAL", "RINT", "RDINT", "RWORD", "RDWORD", "RREAL", "DT", "DTZ", "DTL", "DTLZ", "B", "C", "S", "I", "DI", "W", "D", "DW", "R", "RI", "RDI", "RW", "RD", "RDW", "RR"];
465
+
466
+ var match = address.match(NODES7_REGEX_ADDR);
467
+ if (!match) return 'ERR_PARSE_UNKNOWN_FORMAT';
468
+
469
+ var match_db = match[1];
470
+ var match_area = match[2];
471
+ var match_addr = match[3];
472
+ var match_bitAddr = parseInt(match[4]);
473
+ var match_arrLen = parseInt(match[5]);
474
+
475
+ var addrType, dataType, addressOffset, dbNumber;
476
+
477
+ addressOffset = parseInt(match_addr)
478
+ if (isNaN(addressOffset)) return 'ERR_PARSE_ADDR_OFFSET';
479
+
480
+ if (match_db) {
481
+ dbNumber = parseInt(match_db);
482
+ if (dbNumber < 1 || isNaN(dbNumber)) return 'ERR_PARSE_DB_NUMBER';
483
+ }
484
+
485
+ if (dbNumber) {
486
+ if (!NODES7_DATATYPE_DB.includes(match_area)) return 'ERR_PARSE_DB_DATATYPE';
487
+ dataType = match_area;
488
+ } else {
489
+ // the first char indicates the PLC area (I, Q, M, P, ...)
490
+ addrType = match_area.charAt(0);
491
+ // the data type (if area is P, skip the first char (I,E,Q,A))
492
+ dataType = match_area.substr(addrType === "P" ? 2 : 1);
493
+
494
+ // validate address type
495
+ if (!NODES7_ADDRTYPE.includes(addrType)) return 'ERR_PARSE_AREA';
496
+
497
+ if (dataType === "" && addrType !== "T" && addrType !== "C") {
498
+ dataType = "X";
499
+ }
500
+
501
+ // validate data type
502
+ if (!NODES7_DATATYPE.includes(dataType)) return 'ERR_PARSE_DATATYPE';
503
+ }
504
+
505
+ if (dataType === "X") {
506
+ // handle array lengths and bit address
507
+ if (isNaN(match_bitAddr)) return 'ERR_PARSE_BIT_OFFSET';
508
+ if (match_bitAddr > 7) return 'ERR_PARSE_BIT_OFFSET';
509
+
510
+ } else if (dataType === "STRING" || dataType === "S") {
511
+ // match_bitAddr is the string length for string types
512
+ if (isNaN(match_bitAddr) || match_bitAddr < 1) return 'ERR_PARSE_STRING_LEN';
513
+
514
+ } else {
515
+ // the array length should be at the bitAddr field, this is a syntax error
516
+ if (!isNaN(match_arrLen)) return 'ERR_PARSE_INVALID_BIT_OFFSET';
517
+
518
+ // the bitAddr field is actually the array length
519
+ if (!isNaN(match_bitAddr) && match_bitAddr < 1) return 'ERR_PARSE_INVALID_ARR_LEN';
520
+ }
521
+
522
+ return null;
523
+ }
524
+
525
+ function validateAddressList(list) {
526
+ for (var i = 0; i < list.length; i++){
527
+ var elm = list[i];
528
+ if (!elm.name) return false;
529
+ if (validateS7Address(elm.addr)) return false;
530
+ }
531
+ return true;
532
+ }
533
+
534
+ function validateTSAP(num) {
535
+ num = num.toString();
536
+ if (num.length != 2) return false;
537
+ if (!(/^[0-9a-fA-F]+$/.test(num))) return false;
538
+ var i = parseInt(num, 16);
539
+ if (isNaN(i) || i < 0 || i > 0xff) return false;
540
+ return true;
541
+ }
542
+
543
+ RED.nodes.registerType('s7 endpoint', {
544
+ category: 'config',
545
+ defaults: {
546
+ transport: {
547
+ value: "iso-on-tcp"
548
+ },
549
+ address: {
550
+ value: "",
551
+ validate: function(v) {return this.transport == 'iso-on-tcp' ? !!v : true}
552
+ },
553
+ port: {
554
+ value: "102",
555
+ validate: RED.validators.number()
556
+ },
557
+ rack: {
558
+ value: "0",
559
+ validate: RED.validators.number()
560
+ },
561
+ slot: {
562
+ value: "2",
563
+ validate: RED.validators.number()
564
+ },
565
+ localtsaphi: {
566
+ value: "01",
567
+ validate: validateTSAP
568
+ },
569
+ localtsaplo: {
570
+ value: "00",
571
+ validate: validateTSAP
572
+ },
573
+ remotetsaphi: {
574
+ value: "01",
575
+ validate: validateTSAP
576
+ },
577
+ remotetsaplo: {
578
+ value: "00",
579
+ validate: validateTSAP
580
+ },
581
+ connmode: {
582
+ value: "rack-slot"
583
+ },
584
+ adapter: {
585
+ value: "",
586
+ type: "mpi-s7 adapter",
587
+ validate: function(v) {return this.transport != "mpi-s7" || !!v }
588
+ },
589
+ busaddr: {
590
+ value: 2
591
+ },
592
+ cycletime: {
593
+ value: 1000
594
+ },
595
+ timeout: {
596
+ value: 2000
597
+ },
598
+ name: {
599
+ value: ""
600
+ },
601
+ vartable: {
602
+ value: [{
603
+ name: "",
604
+ addr: ""
605
+ }],
606
+ validate: validateAddressList
607
+ }
608
+ },
609
+ label: function () {
610
+ if (this.name) {
611
+ return this.name
612
+ } else if (this.transport == "iso-on-tcp") {
613
+ return this.address + ":" + this.port + "@" + (
614
+ this.connmode == 'tsap' ?
615
+ (this.localtsaphi + "." + this.localtsaplo + "/" + this.remotetsaphi + "." + this.remotetsaplo) :
616
+ (this.rack + ":" + this.slot))
617
+ } else if (this.transport == "mpi-s7") {
618
+ var adapterNode = RED.nodes.node(this.adapter);
619
+ if (adapterNode) {
620
+ return adapterNode.label() + "/" + this.busaddr;
621
+ }
622
+ return "MPI/PPI/DP @ ??/" + this.busaddr;
623
+ } else {
624
+ return "s7 endpoint";
625
+ }
626
+ },
627
+ oneditprepare: function () {
628
+ var self = this;
629
+ var tt = this._.bind(this);
630
+ var labelName = this._("s7.endpoint.label.variables.name");
631
+ var labelAddr = this._("s7.endpoint.label.variables.addr");
632
+ var labelDel = this._("s7.endpoint.label.variables.del");
633
+
634
+ var connTypeList = $('#node-config-input-connmode');
635
+ var rackSlotRow = $('#node-config-s7-endpoint-mode-rackslot');
636
+ var tsapRow = $('#node-config-s7-endpoint-mode-tsap');
637
+
638
+ var transportList = $('#node-config-input-transport');
639
+ var transportIsoOnTCPGroup = $('#s7-endpoint-transport-iso-on-tcp');
640
+ var transportMpiS7Group = $('#s7-endpoint-transport-mpi-s7');
641
+
642
+ var fieldAddressIsoOnTcp = $('#node-config-input-address');
643
+ var fieldName = $('#node-config-input-name');
644
+
645
+ var lookupPlcPNBtn = $('#node-config-lookup-plc-pn');
646
+ var flashPlcPNBtn = $('#node-config-flash-plc-pn');
647
+
648
+ // put a placeholder for mpi-s7 adapter if not installed
649
+ if (!RED.nodes.getType('mpi-s7 adapter')){
650
+ $('#node-config-input-adapter').hide();
651
+ $('#s7-endpoint-adapter-placeholder').show();
652
+ }
653
+
654
+ // Prepare tabs
655
+ var tabs = RED.tabs.create({
656
+ id: "node-config-s7-endpoint-tabs",
657
+ onchange: function (tab) {
658
+ $("#node-config-s7-endpoint-tabs-content").children().hide();
659
+ $("#" + tab.id).show();
660
+ }
661
+ });
662
+ tabs.addTab({
663
+ id: "s7-endpoint-tab-connection",
664
+ label: this._("s7.endpoint.label.tabs.connection")
665
+ });
666
+ tabs.addTab({
667
+ id: "s7-endpoint-tab-variables",
668
+ label: this._("s7.endpoint.label.tabs.variables")
669
+ });
670
+ setTimeout(function () {
671
+ tabs.resize()
672
+ }, 0);
673
+
674
+ function generateVariable(variable) {
675
+ var curTooltip;
676
+ var previousValue = variable.addr;
677
+ var container = $('<li/>', {
678
+ style: "background: #fff; margin:0; padding:8px 0px; border-bottom: 1px solid #ccc;"
679
+ });
680
+ var row1 = $('<div/>').appendTo(container);
681
+
682
+ var variableAddr = $('<input/>', {
683
+ style: "width: 110px; margin-right: 10px;",
684
+ class: "node-config-input-variable-addr",
685
+ type: "text",
686
+ placeholder: labelAddr
687
+ }).appendTo(row1);
688
+
689
+ var variableName = $('<input/>', {
690
+ style: "width: 250px",
691
+ class: "node-config-input-variable-name",
692
+ type: "text",
693
+ placeholder: labelName
694
+ }).appendTo(row1);
695
+
696
+ var finalspan = $('<span/>', {
697
+ style: "float: right; margin-right: 10px;"
698
+ }).appendTo(row1);
699
+ var deleteButton = $('<a/>', {
700
+ href: "#",
701
+ class: "editor-button editor-button-small",
702
+ style: "margin-top: 7px; margin-left: 5px;",
703
+ title: labelDel
704
+ }).appendTo(finalspan);
705
+
706
+ $('<i/>', {
707
+ class: "fa fa-remove"
708
+ }).appendTo(deleteButton);
709
+
710
+ deleteButton.click(function () {
711
+ container.css({
712
+ "background": "#fee"
713
+ });
714
+ container.fadeOut(150, function () {
715
+ $(this).remove();
716
+ });
717
+ if (curTooltip) curTooltip.close();
718
+ });
719
+
720
+ variableAddr.change(function () {
721
+ //validate address
722
+ var curVal = variableAddr.val();
723
+ var valError = validateS7Address(curVal);
724
+ if (valError) {
725
+ variableAddr.addClass('input-error')
726
+ var errorText = tt("s7.validation." + valError);
727
+ if (curTooltip) {
728
+ curTooltip.setContent(errorText);
729
+ curTooltip.open();
730
+ } else if (RED.popover && RED.popover.tooltip){
731
+ curTooltip = RED.popover.tooltip(variableAddr, errorText);
732
+ curTooltip.open();
733
+ }
734
+ } else {
735
+ variableAddr.removeClass('input-error');
736
+ if(curTooltip) {
737
+ curTooltip.close();
738
+ curTooltip.setContent('');
739
+ //hack to remove the popup, as Node-RED don't offer
740
+ // and "unbind" function. May break in the future
741
+ variableAddr.off('mouseenter mouseleave disabled');
742
+ curTooltip = null;
743
+ }
744
+ }
745
+
746
+ //update name if matching old one
747
+ if (previousValue && variableName.val() == previousValue) {
748
+ variableName.val(curVal);
749
+ }
750
+ previousValue = curVal;
751
+ });
752
+
753
+ //populate data
754
+ variableAddr.val(variable.addr);
755
+ variableName.val(variable.name);
756
+ variableAddr.change();
757
+
758
+ $("#node-config-input-variables-container").append(container);
759
+ }
760
+
761
+ function cleanVarTable() {
762
+ $("#node-config-input-variables-container").children().remove();
763
+ }
764
+
765
+ function populateVarTable() {
766
+ if (self.vartable) {
767
+ if (typeof self.vartable == 'string') {
768
+ self.vartable = JSON.parse(self.vartable);
769
+ }
770
+ for (var i = 0; i < self.vartable.length; i++) {
771
+ generateVariable(self.vartable[i]);
772
+ }
773
+ }
774
+ }
775
+
776
+ $("#node-config-input-add-variable").click(function () {
777
+ generateVariable({
778
+ name: "",
779
+ addr: ""
780
+ });
781
+ });
782
+
783
+ $("#node-config-input-cycletime").spinner({
784
+ min: 0
785
+ });
786
+
787
+ $("#node-config-input-timeout").spinner({
788
+ min: 500
789
+ });
790
+
791
+ $("#node-config-input-busaddr").spinner({
792
+ min: 0,
793
+ max: 127
794
+ });
795
+
796
+ $("#node-config-s7-endpoint-var-clean").click(cleanVarTable);
797
+
798
+ populateVarTable();
799
+
800
+ // export
801
+ function exportCSV() {
802
+ var vars = $("#node-config-input-variables-container").children();
803
+ var lines = [];
804
+
805
+ vars.each(function (i) {
806
+ var elm = $(this);
807
+ lines.push([
808
+ elm.find(".node-config-input-variable-addr").val(), //addr
809
+ elm.find(".node-config-input-variable-name").val() //name
810
+ ].join(';'));
811
+ });
812
+
813
+ saveAs(new Blob([lines.join('\r\n')]), 's7endpoint' + (self.name ? '_' + self.name : '') + '.csv');
814
+ }
815
+ $('#node-config-s7-endpoint-var-export').click(exportCSV);
816
+
817
+ // import
818
+ function importCSV(e) {
819
+ var file = e.target.files[0];
820
+ if (!file) {
821
+ return;
822
+ }
823
+ var reader = new FileReader();
824
+ reader.onload = function (e) {
825
+ var res = [], i, fields;
826
+ var contents = e.target.result || '';
827
+ var lines = contents.split(/[\r\n]+/);
828
+
829
+ if (!lines.length) {
830
+ alert('file is empty!');
831
+ return;
832
+ }
833
+
834
+ for (i = 0; i < lines.length; i++) {
835
+
836
+ lines[i] = lines[i].trim();
837
+ if (lines[i] == '') continue;
838
+
839
+ fields = lines[i].split(/[\t;]/);
840
+
841
+ if (fields.length < 2) {
842
+ alert('line must have at least two parameters, address and name');
843
+ return;
844
+ }
845
+ res.push({
846
+ addr: fields[0],
847
+ name: fields[1]
848
+ });
849
+ }
850
+
851
+ if (res.length) {
852
+ cleanVarTable();
853
+ self.vartable = res;
854
+ populateVarTable();
855
+ }
856
+ };
857
+ reader.readAsText(file);
858
+ }
859
+ $('#node-config-s7-endpoint-var-import').on('change', importCSV);
860
+ $('#node-config-s7-endpoint-var-import-btn').click(function () {
861
+ $('#node-config-s7-endpoint-var-import').click();
862
+ })
863
+
864
+ //set defaults for old flows
865
+
866
+ if (self.connmode === undefined) {
867
+ console.log('defaults conmode to "rack-slot"');
868
+ self.connmode = 'rack-slot';
869
+ self.localtsaphi = "01";
870
+ self.localtsaplo = "00";
871
+ self.remotetsaphi = "01";
872
+ self.remotetsaplo = "00";
873
+ $("#node-config-input-localtsaphi").val(self.localtsaphi);
874
+ $("#node-config-input-localtsaplo").val(self.localtsaplo);
875
+ $("#node-config-input-remotetsaphi").val(self.remotetsaphi);
876
+ $("#node-config-input-remotetsaplo").val(self.remotetsaplo);
877
+ connTypeList.val(self.connmode);
878
+ }
879
+
880
+ if (self.timeout === undefined) {
881
+ self.timeout = 1500;
882
+ $("#node-config-input-timeout").val(self.timeout);
883
+ }
884
+
885
+ if (self.verbose === undefined) {
886
+ self.verbose = 'default';
887
+ $("#node-config-input-verbose").val(self.verbose);
888
+ }
889
+
890
+ if (self.transport === undefined) {
891
+ self.transport = 'iso-on-tcp';
892
+ transportList.val(self.transport);
893
+ }
894
+
895
+ connTypeList.change(function () {
896
+ if (connTypeList.val() == "rack-slot") {
897
+ rackSlotRow.show();
898
+ tsapRow.hide();
899
+ } else if (connTypeList.val() == "tsap") {
900
+ rackSlotRow.hide();
901
+ tsapRow.show();
902
+ } else {
903
+ rackSlotRow.hide();
904
+ tsapRow.hide();
905
+ }
906
+ });
907
+ connTypeList.change();
908
+
909
+ transportList.change(function() {
910
+ var curVal = transportList.val();
911
+ if(curVal == "iso-on-tcp") {
912
+ transportIsoOnTCPGroup.show();
913
+ transportMpiS7Group.hide();
914
+ } else if (curVal == "mpi-s7") {
915
+ transportIsoOnTCPGroup.hide();
916
+ transportMpiS7Group.show();
917
+ } else {
918
+ transportIsoOnTCPGroup.hide();
919
+ transportMpiS7Group.hide();
920
+ }
921
+ });
922
+ transportList.change();
923
+
924
+ $.getJSON('__node-red-contrib-s7/discover/available/iso-on-tcp', function(data) {
925
+ if (data) {
926
+ lookupPlcPNBtn.removeClass('disabled');
927
+ }
928
+ });
929
+
930
+ var lookupPlcPNValue = null;
931
+ fieldAddressIsoOnTcp.change(function() {
932
+ lookupPlcPNValue = null;
933
+ flashPlcPNBtn.addClass('disabled');
934
+ })
935
+
936
+ lookupPlcPNBtn.click(function () {
937
+ if (lookupPlcPNBtn.hasClass('disabled')) return;
938
+
939
+ lookupPlcPNBtn.addClass('disabled');
940
+ var iconLookup = lookupPlcPNBtn.children('i');
941
+ iconLookup.removeClass('fa-search').addClass('fa-spinner fa-spin fa-fw');
942
+
943
+ $.getJSON('__node-red-contrib-s7/discover/iso-on-tcp', function (data) {
944
+ console.log("node-red-contrib-s7 discovered PLCs", data)
945
+
946
+ var listData = $.map(data, function(val){
947
+ return { label: val, value: val['IP Address']}
948
+ })
949
+
950
+ fieldAddressIsoOnTcp.autocomplete({
951
+ source: listData,
952
+ minLength: 0,
953
+ create: function (event, ui) {
954
+ $(this).data('ui-autocomplete')._renderItem = function (ul, elm) {
955
+ var item = elm.label;
956
+ elmHtml = '<a>'
957
+ + '<small style="float: right;">' + item['Vendor Value'] + '</small>'
958
+ + '<b>' + item['Station Name'] + '</b>'
959
+ + '<br/>'
960
+ + '<small style="float: right;">' + item['MAC Address'] + '</small>'
961
+ + item['IP Address']
962
+ + '</a>'
963
+ return $('<li style="padding: 2px">').attr("data-value", elm.value).append(elmHtml).appendTo(ul);
964
+ };
965
+ },
966
+ select: function (event, ui) {
967
+ var elm = ui.item.label
968
+
969
+ event.preventDefault();
970
+ event.stopPropagation();
971
+ fieldAddressIsoOnTcp.val(elm['IP Address']);
972
+ fieldAddressIsoOnTcp.change();
973
+
974
+
975
+ if (!fieldName.val()){
976
+ fieldName.val(elm['Station Name']);
977
+ }
978
+
979
+ lookupPlcPNValue = elm;
980
+ flashPlcPNBtn.removeClass('disabled');
981
+ }
982
+ });
983
+
984
+ fieldAddressIsoOnTcp.focus(function() {
985
+ fieldAddressIsoOnTcp.autocomplete("search", "")
986
+ });
987
+ fieldAddressIsoOnTcp.focus();
988
+ }).always(function() {
989
+ iconLookup.removeClass('fa-spinner fa-spin fa-fw').addClass('fa-search');
990
+ lookupPlcPNBtn.removeClass('disabled');
991
+ });
992
+ });
993
+
994
+ flashPlcPNBtn.click(function() {
995
+ if (flashPlcPNBtn.hasClass('disabled')) return;
996
+
997
+ if (!lookupPlcPNValue) {
998
+ flashPlcPNBtn.addClass('disabled');
999
+ return;
1000
+ }
1001
+
1002
+ var macaddr = lookupPlcPNValue['MAC Address'].replace(/:/g, '-');
1003
+ var tgtUrl = '__node-red-contrib-s7/flashled/iso-on-tcp/' + macaddr;
1004
+ $.getJSON(tgtUrl);
1005
+ });
1006
+
1007
+ },
1008
+ oneditsave: function () {
1009
+ var node = this;
1010
+ var vars = $("#node-config-input-variables-container").children();
1011
+ node.vartable = [];
1012
+
1013
+ vars.each(function (i) {
1014
+ var elm = $(this);
1015
+ var addr = elm.find(".node-config-input-variable-addr").val();
1016
+ var name = elm.find(".node-config-input-variable-name").val();
1017
+ var v = {
1018
+ addr: addr,
1019
+ name: name || addr
1020
+ }
1021
+ node.vartable.push(v);
1022
+ });
1023
+ }
1024
+ });
1025
+ </script>
1026
+
1027
+ <!-- ######################################################################################## -->
1028
+
1029
+ <script type="text/x-red" data-template-name="s7 in">
1030
+ <div class="form-row">
1031
+ <label for="node-input-endpoint"><i class="fa fa-bolt"></i> <span data-i18n="s7.in.label.endpoint"></span></label>
1032
+ <input type="text" id="node-input-endpoint" data-i18n="[placeholder]s7.in.label.endpoint">
1033
+ </div>
1034
+ <div class="form-row">
1035
+ <label for="node-input-mode"><i class="fa fa-sliders"></i> <span data-i18n="s7.in.label.mode"></span></label>
1036
+ <select type="text" id="node-input-mode">
1037
+ <option value="single" data-i18n="s7.in.mode.single"></option>
1038
+ <option value="all-split" data-i18n="s7.in.mode.all-split"></option>
1039
+ <option value="all" data-i18n="s7.in.mode.all"></option>
1040
+ </select>
1041
+ </div>
1042
+ <div class="form-row s7-input-var-row">
1043
+ <label for="node-input-variable"><i class="fa fa-random"></i> <span data-i18n="s7.in.label.variable"></span></label>
1044
+ <select type="text" id="node-input-variable">
1045
+ </select>
1046
+ <span id="s7-custom-var-addr"></span>
1047
+ </div>
1048
+ <div class="form-row">
1049
+ <label>&nbsp;</label>
1050
+ <input type="checkbox" id="node-input-diff" style="display: inline-block; width: auto; vertical-align: top;">
1051
+ <label for="node-input-diff" style="width:70%;"><span data-i18n="s7.in.label.diff"></span></label>
1052
+ </div>
1053
+ <div class="form-row">
1054
+ <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="s7.label.name"></span></label>
1055
+ <input type="text" id="node-input-name" data-i18n="[placeholder]s7.label.name">
1056
+ </div>
1057
+ </script>
1058
+
1059
+ <script type="text/x-red" data-help-name="s7 in">
1060
+ <p>Reads data from a S7 PLC</p>
1061
+ <p>This node was created as part of the <a href="https://st-one.io" target="_blank">ST-One</a> project</p>
1062
+
1063
+ <h3>Outputs</h3>
1064
+ <dl class="message-properties">
1065
+ <dt>payload<span class="property-type">any</span></dt>
1066
+ <dd>
1067
+ The value(s) as read from the PLC. The format and type of the payload
1068
+ depends on the configured "Mode"
1069
+ </dd>
1070
+
1071
+ <dt>topic<span class="property-type">string</span></dt>
1072
+ <dd>
1073
+ The name of the variable, when the message refers to a single variable
1074
+ (that is, when mode is "Single Variable" or "All variables, one per
1075
+ message")
1076
+ </dd>
1077
+ </dl>
1078
+
1079
+ <h3>Details</h3>
1080
+ <p>
1081
+ All data is read cyclically from the PLC as configured in the <i>s7 endpoint</i>,
1082
+ but there are three modes of making it available in a flow:
1083
+ </p>
1084
+ <ul>
1085
+ <li>
1086
+ <b>Single variable:</b> A single variable can be selected from the configured
1087
+ variables, and a message is sent every cycle, or only when it changes if
1088
+ <i>diff</i> is checked. <code>msg.payload</code> contains the variable's value
1089
+ and <code>msg.topic</code> has the variable's name.
1090
+ </li>
1091
+ <li>
1092
+ <b>All variables, one per message:</b> Like the <i>Single variable</i> mode,
1093
+ but for all variables configured. If <i>diff</i> is checked, a message is sent
1094
+ everytime any variable changes. If <i>diff</i> is unchecked, one message is sent
1095
+ for every variable, in every cycle. Care must be taken about the number of
1096
+ messages per second in this mode.
1097
+ </li>
1098
+ <li>
1099
+ <b>All variables:</b> In this mode, <code>msg.payload</code> contains an object
1100
+ with all configured variables and their values. If <i>diff</i> is checked, a
1101
+ message is sent if at least one of the variables changes its value.
1102
+ </li>
1103
+ </ul>
1104
+ </script>
1105
+
1106
+ <script type="text/javascript">
1107
+ RED.nodes.registerType('s7 in', {
1108
+ category: 'plc',
1109
+ defaults: {
1110
+ endpoint: {
1111
+ value: "",
1112
+ type: "s7 endpoint",
1113
+ required: true
1114
+ },
1115
+ mode: {
1116
+ value: "single"
1117
+ },
1118
+ variable: {
1119
+ value: ""
1120
+ },
1121
+ diff: {
1122
+ value: true
1123
+ },
1124
+ name: {
1125
+ value: ""
1126
+ }
1127
+ },
1128
+ color: "#3FADB5",
1129
+ inputs: 0,
1130
+ outputs: 2,
1131
+ icon: "serial.png",
1132
+ label: function () {
1133
+ var self = this;
1134
+
1135
+ if (this.name) return this.name;
1136
+
1137
+ var endpointNode = RED.nodes.node(this.endpoint);
1138
+ if (endpointNode) {
1139
+ return (this.mode == 'single' ? this.variable : null) || endpointNode.label();
1140
+ }
1141
+ return this._("s7.in.label.name");
1142
+ },
1143
+ labelStyle: function () {
1144
+ return this.name ? "node_label_italic" : "";
1145
+ },
1146
+ oneditprepare: function () {
1147
+ var self = this;
1148
+
1149
+ var varList = $('#node-input-variable');
1150
+ var varAddr = $('#s7-custom-var-addr');
1151
+ var modeList = $('#node-input-mode');
1152
+ var endpointList = $("#node-input-endpoint");
1153
+ var vars = [];
1154
+
1155
+ function updateVarList(endpointId) {
1156
+ $('#node-input-variable option').remove();
1157
+
1158
+ var endpointNode = RED.nodes.node(endpointId);
1159
+ if (!endpointNode) return;
1160
+ vars = endpointNode.vartable || [];
1161
+ if (typeof vars === 'string') vars = JSON.parse(vars);
1162
+
1163
+ varList.append($('<option/>', {
1164
+ disabled: "disabled",
1165
+ selected: "selected",
1166
+ style: "display:none;",
1167
+ text: vars.length ? self._("s7.in.label.variable-select") : self._("s7.in.label.variable-novar")
1168
+ }));
1169
+
1170
+ $.each(vars, function (i, val) {
1171
+ varList.append($('<option/>', {
1172
+ value: val.name || val.addr,
1173
+ text: val.name || val.addr
1174
+ }));
1175
+ if (val.name == self.variable) {
1176
+ varList.val(self.variable);
1177
+ }
1178
+ });
1179
+ }
1180
+
1181
+ varList.change(function () {
1182
+ $.each(vars, function (i, val) {
1183
+ if (varList.val() == val.name) {
1184
+ varAddr[0].innerText = val.addr;
1185
+ return true;
1186
+ }
1187
+ });
1188
+ });
1189
+
1190
+ endpointList.change(function () {
1191
+ updateVarList(endpointList.val());
1192
+ });
1193
+ updateVarList(self.endpoint);
1194
+
1195
+ modeList.change(function () {
1196
+ if (modeList.val() == "single") {
1197
+ varList.parent().show();
1198
+ } else {
1199
+ varList.parent().hide();
1200
+ }
1201
+ });
1202
+ modeList.change();
1203
+ }
1204
+ });
1205
+ </script>
1206
+
1207
+ <!-- ######################################################################################## -->
1208
+
1209
+ <script type="text/x-red" data-template-name="s7 out">
1210
+ <div class="form-row">
1211
+ <label for="node-input-endpoint"><i class="fa fa-bolt"></i> <span data-i18n="s7.out.label.endpoint"></span></label>
1212
+ <input type="text" id="node-input-endpoint" data-i18n="[placeholder]s7.out.label.endpoint">
1213
+ </div>
1214
+ <div class="form-row s7-input-var-row">
1215
+ <label for="node-input-variable"><i class="fa fa-random"></i> <span data-i18n="s7.out.label.variable"></span></label>
1216
+ <select type="text" id="node-input-variable">
1217
+ </select>
1218
+ <span id="s7-custom-var-addr"></span>
1219
+ </div>
1220
+ <div class="form-row">
1221
+ <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="s7.label.name"></span></label>
1222
+ <input type="text" id="node-input-name" data-i18n="[placeholder]s7.label.name">
1223
+ </div>
1224
+ <div class="form-tips"><span data-i18n="[html]s7.out.disclaimer"></span></div>
1225
+ </script>
1226
+
1227
+ <script type="text/x-red" data-help-name="s7 out">
1228
+ <p>Writes to a memory area in a S7 PLC</p>
1229
+ <p>This node was created as part of the <a href="https://st-one.io" target="_blank">ST-One</a> project</p>
1230
+
1231
+ <p class="form-tips">
1232
+ <b>Caution when writing data to production PLCs!</b><br/>
1233
+ Fully test everything you do. The authors cannot be liable for any
1234
+ damage or injury caused by the use of this node
1235
+ </p>
1236
+
1237
+ <h3>Inputs</h3>
1238
+ <dl class="message-properties">
1239
+ <dt>payload<span class="property-type">string | number | boolean | array</span></dt>
1240
+ <dd>
1241
+ the data to be written. It will be casted to the required data type
1242
+ whenever possible.
1243
+ </dd>
1244
+
1245
+ <dt>variable<span class="property-type">string | array</span></dt>
1246
+ <dd>
1247
+ the variable to write to on the PLC, according to the variable list
1248
+ on the PLC endpoint. This takes effect <i>only</i> if the "Variable"
1249
+ field is left empty on the configuration.
1250
+ </dd>
1251
+ </dl>
1252
+
1253
+ <h3>Details</h3>
1254
+ <p>
1255
+ Writes data to the PLC on the variable specified on the node configuration
1256
+ or on <code>msg.variable</code>.
1257
+ </p>
1258
+ <p>
1259
+ It is possible to write to multiple variables at once, by setting both
1260
+ <code>msg.variable</code> and <code>msg.payload</code> to arrays containing
1261
+ the variable names and their values, respectively. Note that they may not be
1262
+ written in the same write cycle to the PLC, depending on the amount of variables
1263
+ to be written.
1264
+ </p>
1265
+ </script>
1266
+
1267
+ <script type="text/javascript">
1268
+ RED.nodes.registerType('s7 out', {
1269
+ category: 'plc',
1270
+ defaults: {
1271
+ endpoint: {
1272
+ value: "",
1273
+ type: "s7 endpoint",
1274
+ required: true
1275
+ },
1276
+ variable: {
1277
+ value: ""
1278
+ },
1279
+ name: {
1280
+ value: ""
1281
+ }
1282
+ },
1283
+ color: "#3FADB5",
1284
+ inputs: 1,
1285
+ outputs: 1,
1286
+ icon: "serial.png",
1287
+ align: 'right',
1288
+ label: function () {
1289
+ var self = this;
1290
+
1291
+ if (this.name) return this.name;
1292
+
1293
+ var endpointNode = RED.nodes.node(this.endpoint);
1294
+ if (endpointNode) {
1295
+ return this.variable || endpointNode.label();
1296
+ }
1297
+ return this._("s7.out.label.name");
1298
+ },
1299
+ labelStyle: function () {
1300
+ return this.name ? "node_label_italic" : "";
1301
+ },
1302
+ oneditprepare: function () {
1303
+ var self = this;
1304
+
1305
+ var varList = $('#node-input-variable');
1306
+ var varAddr = $('#s7-custom-var-addr')[0];
1307
+ var endpointList = $("#node-input-endpoint");
1308
+ var vars = [];
1309
+
1310
+ function updateVarList(endpointId) {
1311
+ $('#node-input-variable option').remove();
1312
+
1313
+ varList.append($('<option/>', {
1314
+ //disabled: "disabled",
1315
+ selected: "selected",
1316
+ //style: "display:none;",
1317
+ text: self._("s7.out.label.variable-select"),
1318
+ value: ""
1319
+ }));
1320
+
1321
+ var endpointNode = RED.nodes.node(endpointId);
1322
+ if (!endpointNode) return;
1323
+ vars = endpointNode.vartable || [];
1324
+ if (typeof vars === 'string') vars = JSON.parse(vars);
1325
+
1326
+ $.each(vars, function (i, val) {
1327
+ varList.append($('<option/>', {
1328
+ value: val.name || val.addr,
1329
+ text: val.name || val.addr
1330
+ }));
1331
+ if (val.name == self.variable) {
1332
+ varList.val(self.variable);
1333
+ }
1334
+ });
1335
+ }
1336
+
1337
+ varList.change(function () {
1338
+ varAddr.innerText = ""
1339
+ $.each(vars, function (i, val) {
1340
+ if (varList.val() == val.name) {
1341
+ varAddr.innerText = val.addr;
1342
+ return true;
1343
+ }
1344
+ });
1345
+ });
1346
+
1347
+ endpointList.change(function () {
1348
+ updateVarList(endpointList.val());
1349
+ });
1350
+ updateVarList(self.endpoint);
1351
+ }
1352
+ });
1353
+ </script>
1354
+
1355
+ <!-- ######################################################################################## -->
1356
+
1357
+ <script type="text/x-red" data-template-name="s7 control">
1358
+ <div class="form-row">
1359
+ <label for="node-input-endpoint"><i class="fa fa-bolt"></i> <span data-i18n="s7.control.label.endpoint"></span></label>
1360
+ <input type="text" id="node-input-endpoint" data-i18n="[placeholder]s7.control.label.endpoint">
1361
+ </div>
1362
+ <div class="form-row">
1363
+ <label for="node-input-function"><i class="fa fa-sliders"></i> <span data-i18n="s7.control.label.function"></span></label>
1364
+ <select type="text" id="node-input-function">
1365
+ <option value=""></option>
1366
+ <option value="cycletime" data-i18n="s7.control.function.cycletime"></option>
1367
+ <option value="trigger" data-i18n="s7.control.function.trigger"></option>
1368
+ </select>
1369
+ </div>
1370
+ <div class="form-row">
1371
+ <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="s7.label.name"></span></label>
1372
+ <input type="text" id="node-input-name" data-i18n="[placeholder]s7.label.name">
1373
+ </div>
1374
+ </script>
1375
+
1376
+ <script type="text/x-red" data-help-name="s7 control">
1377
+ <p>Enables advanced control of the PLC and the connection</p>
1378
+ <p>This node was created as part of the <a href="https://st-one.io" target="_blank">ST-One</a> project</p>
1379
+
1380
+ <h3>Details</h3>
1381
+ <p>The behavior of this node is changed according to the selected function. Each function
1382
+ has its own configuration, expects different parameters in the messages, and sends
1383
+ different messages out
1384
+ </p>
1385
+ <dl class="message-properties">
1386
+ <dt>Cycle Time</dt>
1387
+ <dd>
1388
+ Changes the time interval between each cyclic read
1389
+ of variables. It expects a message with <code>payload</code> with a
1390
+ positive number, being the time in milliseconds between each read. A
1391
+ value of zero disables the cyclic read.
1392
+ </dd>
1393
+
1394
+ <dt>Trigger read</dt>
1395
+ <dd>
1396
+ Manually triggers a read cycle. No message parameters are used and the
1397
+ same message is sent on the output. Useful when longer cycle times are
1398
+ used, but an instant feedback is needed (for example after changing a
1399
+ variable). Note that the <i>s7 in</i> nodes are still required to read
1400
+ the values of the variables.
1401
+ </dd>
1402
+ </dl>
1403
+ </script>
1404
+
1405
+ <script type="text/javascript">
1406
+ RED.nodes.registerType('s7 control', {
1407
+ category: 'plc',
1408
+ defaults: {
1409
+ endpoint: {
1410
+ value: "",
1411
+ type: "s7 endpoint",
1412
+ required: true
1413
+ },
1414
+ function: {
1415
+ value: "cycletime"
1416
+ },
1417
+ name: {
1418
+ value: ""
1419
+ }
1420
+ },
1421
+ color: "#3FADB5",
1422
+ inputs: 1,
1423
+ outputs: 1,
1424
+ icon: "serial.png",
1425
+ label: function () {
1426
+ var self = this;
1427
+
1428
+ if (this.name) return this.name;
1429
+
1430
+ var endpointNode = RED.nodes.node(this.endpoint);
1431
+ if (endpointNode) {
1432
+ if (this.function) {
1433
+ return endpointNode.label() + ": " + this._("s7.control.function." + this.function);
1434
+ } else {
1435
+ return endpointNode.label()
1436
+ }
1437
+ }
1438
+ return this._("s7.control.label.name");
1439
+ },
1440
+ labelStyle: function () {
1441
+ return this.name ? "node_label_italic" : "";
1442
+ }
1443
+ });
1444
+ </script>