Wiki source code of 08 Macro Script

Version 37.1 by Karen on 2023/06/02 14:59

Show last authors
1 This chapter provides information about scripts in PIStudio.
2
3 = **Script type** =
4
5 Script is applied to realize complex control functions. HMI compile software provide powerful function, simple operation, reliable script system, the features of script are list as follow:
6
7 Similar to BASIC grammatical structure;
8
9 * BASIC work as the first computer language for the general public, it is easy and efficient to use.
10
11 Support all of program logic control structures;
12
13 * Software script supports three logic control structures: order, condition, loops. It could realize complexity procedures.
14
15 Powerful function; Functions of script are divided into two types: system and custom function.
16
17 * System function: the functions that system has been predefined for users.
18 * Custom function: users could define a function and apply to all scripts.
19
20 Support variety of data format;
21
22 * Script supports integer, floating, BCD code, byte, string and etc.
23
24 **Scripts Running Method**
25
26 1. **Background Script:** Run independently during start project, screen updates have no influence and valid of all scripts.
27 1. **Screen Script:** Only run under the designated screen. Screen script start running until screen is closed or switched.
28
29 And both screen and background have four modes for script
30
31 (% class="table-bordered" %)
32 |=**Property**|=**Description**
33 |Initialize|The script would be executed once during loading project.
34 |Close|The script would be run once during closing HMI project.
35 |Timing|The script would run under certain conditions after the HMI is started, until the condition ends.
36 |Bit trigger|Script would be repeat executed when meet the condition of bit trigger.
37
38 == Initialize ==
39
40 Initialize script divided into screen initialize script and background initialize script. Screen initialize script runs once during the initialization of screen; background initialize script runs during the loading of project.
41
42 **Operating procedures**
43
44 Click "Background script" in project manager to enter script editor screen, or click "Screen script" in right click menu of screen to enter script editor screen;
45
46 (% style="text-align:center" %)
47 [[image:9.Scripts_html_96fb2991c0580f0f.gif||class="img-thumbnail"]]
48
49
50 (% style="text-align:center" %)
51 [[image:9.Scripts_html_3cebb8edeabbd760.gif||class="img-thumbnail"]]
52
53 Double click "initialize" to open script edit window, as below shows;
54
55 (% style="text-align:center" %)
56 [[image:9.Scripts_html_8d93c592be893fad.gif||class="img-thumbnail"]]
57
58 Enter scripts in edit window;
59
60 == Close ==
61
62 Close script divided into screen close script and background close script. Screen close script runs once During the destroying of screen because of closing or switching; background close script runs during the closing of project (such as restart HMI, into HMI setup).
63
64 **Operating procedures**
65
66 1. Click "Background script" in project manager to enter script editor screen, or click "Screen script" in right click menu of screen to enter script editor screen;
67 1. Double click "Close" to open script edit window;
68 1. Enter scripts in edit window;
69
70 == Timing ==
71
72 The script would run for a designated time interval.
73
74 **Operating procedures of creating one**
75
76 Click "Background script" in project manager to enter script editor screen, or click "Screen script" in right click menu of screen to enter script editor screen;
77
78 Double click "Timing", it would pop-up below setting window;
79
80 (% style="text-align:center" %)
81 [[image:9.Scripts_html_ca0d08792c31539e.gif||class="img-thumbnail"]]
82
83 (% class="table-bordered" %)
84 |=**Property**|=**Description**
85 |Cycle|Script runs at designated time interval, unit is 10 ms.
86 |Ok|Script created.
87 |Cancel|Cancel the current script setting.
88
89 Enter scripts in edit window;
90
91 **Operating procedures of editing**
92
93 1. Click "Background script" in project manager to enter script editor screen, or click "Screen script" in right click menu of screen to enter script editor screen;
94 1. Select "Timing", and click [[image:9.Scripts_html_d1db672f9b0fe31.gif]] to modify the script execution interval;
95 1. Double click selected "Timing" to open editing window;
96
97 **Operating procedures of deleting**
98
99 Click "Background script" in project manager to enter script editor screen, or click "Screen script" in right click menu of screen to enter script editor screen;
100
101 (% style="text-align:center" %)
102 [[image:9.Scripts_html_f7b5302abd3000e3.gif||class="img-thumbnail"]]
103
104 Select "Timing", and click  [[image:9.Scripts_html_75dc3ed25fdbc359.gif]] to change interval of script, it pops-up above window
105
106 Select "Yes" to execute operation or select "No" to cancel operation;
107
108 (% class="box infomessage" %)
109 (((
110 **✎Note:** The maximum number of timing script for each screen or background is 32.
111 )))
112
113 == Trigger bit ==
114
115 **Introduction**
116
117 Trigger control script is that software will check whether the designated bit meet trigger condition every 20ms. Script execute once condition is met until project closed.
118
119 **Operating procedures of creating one**
120
121 Click "Background script" in project manager to enter script editor screen, or click "Screen script" in right click menu of screen to enter script editor screen;
122
123 Double click "Trigger bit", it pops-up below setting window;
124
125 (% style="text-align:center" %)
126 [[image:9.Scripts_html_5aa68df50f16cfa2.gif||class="img-thumbnail"]]
127
128 * Bit address: It sets trigger address for script;
129 * Condition: detailed information as below shows;
130
131 (% class="table-bordered" %)
132 |=**Condition**|=**Description**
133 |TRUE|Script execute once the bit value is TRUE, detects the bit every per approximately 20 ms;
134 |FALSE|Script execute once the bit value is FALSE, detects the bit every per approximately 20 ms;
135 |Bit changed|Execute once the trigger bit switches state;
136 |Rising|Script execute once the bit value from FALSE to TRUE, detects the bit every per approximately 20 ms;
137 |Falling|Script execute once the bit value from TURE to FALSE, detects the bit every per approximately 20 ms;
138
139 Set trigger bit and condition, click "OK" to open editing window.
140
141 **Operating procedures of editing**
142
143 * Click "Background script" in project manager to enter script editor screen, or click "Screen script" in right click menu of screen to enter script editor screen;
144 * Select "Trigger script", and click [[image:9.Scripts_html_d1db672f9b0fe31.gif]] to change trigger bit and condition;
145 * Double click selected "Trigger script" to open editing window.
146
147 **Operating procedures of deleting**
148
149 * Click "Background script" in project manager to enter script editor screen, or click "Screen script" in right click menu of screen to enter script editor screen;
150 * Select "Trigger script", and click [[image:9.Scripts_html_75dc3ed25fdbc359.gif]] to change interval of script, it pops-up below window
151
152 (% style="text-align:center" %)
153 [[image:9.Scripts_html_f7b5302abd3000e3.gif||class="img-thumbnail"]]
154
155 * Select "Yes" to execute operation or select "No" to cancel operation;
156
157 (% class="box infomessage" %)
158 (((
159 **✎Note:** The maximum number of trigger script for each screen or background is 32.
160 )))
161
162 == Background function ==
163
164 Global function is a collection of codes;it can be called in any script.The method reference system function;
165
166 **Operating procedures**
167
168 Double click "Background function" in project manager;
169
170 (% style="text-align:center" %)
171 [[image:9.Scripts_html_6240f0610ba63eff.gif||class="img-thumbnail"]]
172
173 Set parameters;
174
175 (% style="text-align:center" %)
176 [[image:9.Scripts_html_d196f8a817949f3e.gif||class="img-thumbnail"]]
177
178 (% class="table-bordered" %)
179 |**Property**|**Description**
180 |Function name|Function name could not be the same as existing.
181 |Return type|None, string, integer, float.
182 |Parameter 1|The name of parameter 1.
183
184 **Operating procedures of editing**
185
186 * Click "Background function" in project manager to enter script editor screen;
187 * Select Function name, and click [[image:9.Scripts_html_c653b64bc266a016.gif]] to change parameters;
188 * Double click selected "Trigger script" to open editing window;
189
190 **Operating procedures of deleting**
191
192 * Click "Background function" in project manager to enter script editor screen;
193 * Select Function name, and click  [[image:9.Scripts_html_75dc3ed25fdbc359.gif]] to change interval of script, it pops-up below window
194
195 (% style="text-align:center" %)
196 [[image:9.Scripts_html_f7b5302abd3000e3.gif||class="img-thumbnail"]]
197
198 * Select "Yes" to execute operation or select "No" to cancel operation;
199
200 (% class="box infomessage" %)
201 (((
202 **✎Note:** The maximum parameters for each function are 4, and parameter name can't be unique;
203 )))
204
205 = Script usage =
206
207 Script can make project more convenient and flexible. Script is useful in realizing complex HMI function. If the script is used improperly, it may affect the efficiency of entire project. So pay attention to the follow issues:
208
209 * Do not use too much script loops, if the script loops that execute too many times; it might influence the efficiency of HMI.
210 * In the cycle scripts, avoid using external register, due to the relatively slow serial communication, frequent access to external registers may cause the execution of scripts severely reduced, even influence the screen respond efficiently. There is fine to use internal register.
211 * The maximum script length is 512 rows.
212
213 This section describes how to edit scripts and use some of the accompanying tools and features of the script editor.
214
215 == **Script access to d evice** ==
216
217 Software script supports an efficiency way to access the device address by using symbol @.
218
219 (% class="table-bordered" %)
220 |=**Writing**|=**Meaning**|=**Examples**
221 |@B_;@b_;|Access designated bit address|(((
222 @B_I0.0:access bit address I0.0
223
224 @b_HDX0.0:access bit address HDX0.0
225 )))
226 |@W_;@w_;|(% rowspan="2" %)(((
227 Access designated word address
228
229 HMI connect more than automatic control devices, "#"stands for choosing number before the symbol,":"stands for accessing the station number before symbol.
230
231 Access the first protocol without "#",access default station number1 without":".
232 )))|(((
233 @W_IW0:access word address IW0
234
235 @b_HDW0:access word address HDW0
236 )))
237 |@B_(the number of protocol connection)#(station number):address|(((
238 @B_2#2:I0.0:access the bit address I0.0, with the connection number 2 and station number 2;
239
240 @B_I0.0:access to bit address I0.0;
241 )))
242
243 The script can access with the device though: write and read.
244
245 **For example**
246
247 {{code language="basic"}}
248 If @B_HDX0.0 = 1 then 'read the value from address HDX0.0.
249
250 @B_HDX0.0 = 0 'write 0 to address HDX0.0
251
252 Else
253
254 @B_HDX0.0 = 1 'write 1 to address HDX0.0
255
256 Endif
257
258 @W_QW0 = @W_QW0 + 1 'read data from address QW0, add 1 to this value then write to address QW0
259 {{/code}}
260
261 == **Grammar checking** ==
262
263 **Operating procedures**
264
265 1. Select [[image:9.Scripts_html_2a530bda982b4281.gif]] from script tool bar;
266 1. System does not prompt grammar error if grammar is correct, or system will list all errors;
267 1. Check error information, and modify errors;
268
269 **Error information**
270
271 ~1. Identifier ~*~** contains invalid characters
272
273 2. Attempt to redeclare sub ~*~**
274
275 3. Attempt to redeclare function ~*~**
276
277 4. Attempt to use reserved word ~*~** as identifier
278
279 5. Attempt to use type ~*~** as identifier
280
281 6. Unexpected ')' while parsing arguments for function ~*~**
282
283 7. Could not parse expression (one of the arguments of function ~*~**)
284
285 8. Could not parse arguments of ~*~**
286
287 9. Too many arguments for function ~*~**
288
289 10. Not enough arguments for function ~*~**
290
291 ~11. '(' expected after sub name ~*~**
292
293 12. Unexpected '(' while parsing arguments for sub ~*~**
294
295 13. Could not parse expression (one of the arguments of sub ~*~**)
296
297 14. Could not parse arguments of ~*~**
298
299 15. Too many arguments for sub/function ~*~**
300
301 16. Not enough arguments for sub/function ~*~**
302
303 17. Could not parse expression
304
305 18. '(' expected after function name ~*~**
306
307 19. Unexpected use of sub ~*~** as a part of expression
308
309 20. Illegal statements preceding subs/functions declaration
310
311 21. Unexpected end of file while looking for 'endsub'
312
313 22. End of line expected after 'else'.
314
315 23. End of line expected after 'endif'.
316
317 24. End of line expected after 'next'.
318
319 25. End of line expected after 'wend'.
320
321 26. 'while', 'until' or end of line expected afte r'do'.
322
323 27. Could not parse expression after 'while'
324
325 28. Could not parse expression after 'until'
326
327 29. 'do' without 'loop'
328
329 30. Sub ~*~** contains invalid character'@'
330
331 31. Sub ~*~** already declared
332
333 32. Function ~*~** already declared
334
335 33. Sub name expected after 'sub'
336
337 34. Function name expected after 'function'
338
339 35. Variable name expected
340
341 36. Argument ~*~** contains invalid character '@'
342
343 37. 'integer', 'floating' or 'string' expected
344
345 38. ''',' or ')' expected
346
347 39. 'endsub' without 'sub'
348
349 40. 'end function' without 'function'
350
351 41. End of line expected after 'beep'
352
353 42. 'dim' unexpected here
354
355 43. Variable name expected after 'dim'
356
357 44. 'as' expected after variable name
358
359 45. 'integer' 'floating' or 'string' expected after 'as'
360
361 46. ',' or end of line expected after type in dim statement
362
363 47. Could not parse expression after 'while'
364
365 48. End of line expected after' while' condition
366
367 49. 'while' without 'wend'
368
369 50. End of line expected after 'wend'
370
371 51. 'wend' without 'while'
372
373 52. Variable name expected after' for'
374
375 53. '=' expected after variable name
376
377 54. Could not parse expression after 'for'
378
379 55. 'to' expected
380
381 56. Could not parse expression after 'to'
382
383 57. Could not parse expression after 'step'
384
385 58. End of line expected
386
387 59. 'for' without 'next'
388
389 60. End of line expected after 'next'
390
391 61. 'Next' without 'for'
392
393 62. Could not parse expression after'if'
394
395 63. 'then' expected
396
397 64. Unexpected end of file while looking for 'endif'
398
399 65. Unexpected end of file while looking for 'else' or 'endif'
400
401 66. 'else' without ‘if'
402
403 67. 'end if' without 'if'
404
405 68. Label name expected after 'goto'
406
407 69. Unexpected end of line while looking for ')' in function call
408
409 70. ',' expected
410
411 71. Missing ')'
412
413 72. Unexpected end of line in expression
414
415 73. Unexpected end of file in expression
416
417 = **Script function list** =
418
419 == Mathematical ==
420
421 (% class="table-bordered" %)
422 |=(% style="width: 181px;" %)**Function**|=(% style="width: 1308px;" %)**Introduction**
423 |[[Abs>>||anchor="HAbs"]]|Get absolute value
424 |[[ACos>>||anchor="HACos"]]|Compute the inverse cosine value
425 |[[Asc>>||anchor="HAsc"]]|Return the first character of the string in ASCII value
426 |[[ASin>>||anchor="HASin"]]|Calculate the arcsine value
427 |[[ATan>>||anchor="HATan"]]|Return an arctangent value,the radian ranges -pi/2 to pi/2
428 |[[ATan2>>||anchor="HATan2"]]|Return the arctangent value
429 |[[Cos>>||anchor="HCos"]]|Return a cosine value of an angle
430 |[[Exp>>||anchor="HExp"]]|
431 |[[Hypot>>||anchor="HHypot"]]|Calculate the value of the hypotenuse of a right triangle
432 |[[Tan>>||anchor="HTan"]]|Implement tan calculation to computing the value
433 |[[Sin>>||anchor="HSin"]]|Implement sin calculation to computing the value
434 |[[Sqr>>||anchor="HSqr"]]|Assign a square root value
435 |[[SignedInt16>>||anchor="HSignedInt16"]]|Assign the value to [val] from address A1 which is signed integer
436 |[[SignedInt32>>||anchor="HSignedInt32"]]|Assign the value to [val] from address A1 which is signed even integer
437
438 == Data migration ==
439
440 (% class="table-bordered" %)
441 |=(% style="width: 178px;" %)**Function**|=(% style="width: 1311px;" %)**Introduction**
442 |[[BMOV>>||anchor="HBMOV"]]|Copy data with a designated length from source address
443 |[[FILL>>||anchor="HFILL"]]|Write the same value to designated address constantly
444 |[[SetKeyMap>>||anchor="HSetKeyMap"]]|The key values of the keyboard are mapped so that multiple keyboard buttons perform the same function
445
446 == Process control ==
447
448 (% class="table-bordered" %)
449 |=(% style="width: 181px;" %)**Function**|=(% style="width: 1308px;" %)**Introduction**
450 |[[Goto>>||anchor="HGoto"]]|Go to the designated row unconditionally in a function body
451 |FOR|Execute a command repeatedly for designated times
452 |[[End>>||anchor="HEnd"]]|End the execution of script
453 |while|If the condition is true, then all the commands before Wend in the statement will be executed and then recheck the condition, if the condition is false, the command after Wend will be executed
454
455 == Data conversion ==
456
457 (% class="table-bordered" %)
458 |=(% style="width: 182px;" %)**Function**|=(% style="width: 1307px;" %)**Introduction**
459 |[[A2H>>||anchor="HA2H"]]|Convert string A1 to hexadecimal number
460 |[[AsFloating>>||anchor="HAsFloating"]]|Convert parameter to a float
461 |[[AsInteger>>||anchor="HAsInteger"]]|Convert parameter to a integer
462 |[[AsString>>||anchor="HAsString"]]|Convert parameter to a string
463 |[[B2W>>||anchor="HB2W"]]|Convert an array
464 |[[BCD>>||anchor="HBCD"]]|Convert binary to BCD, save the result as return value
465 |[[BIN>>||anchor="HBIN"]]|Convert BCDto binary, save the result in return value
466 |[[Chr>>||anchor="HChr"]]|Convert integer parameter into correspond ASCII character,return the character string
467 |[[D2F>>||anchor="HD2F"]]|Convert the 32 bit integer format data to float then output the result
468 |[[D2Float>>||anchor="HD2Float"]]|Convert the designated value to floating then assign to variable
469 |[[D2Int>>||anchor="HD2Int"]]|Output the 32-bit integer in the form of integer
470 |[[DegToRad>>||anchor="HDegToRad"]]|Convert the angle into correspond radian, and display
471 |[[F2D>>||anchor="HF2D"]]|Convert a 32 bit floating to integer format, and then output the result
472 |[[F2S>>||anchor="HF2S"]]|Output a format of floating that in the type of string
473 |[[Float2D>>||anchor="HFloat2D"]]|Copy floating value to the address
474 |[[H2A>>||anchor="HH2A"]]| of ASCII
475 |[[Int2D>>||anchor="HInt2D"]]|Write the 32-bit integer into the specified address
476 |[[Lcase>>||anchor="HLcase"]]|Convert all parameters to lowercase strings
477 |[[MAX>>||anchor="HMAX"]]|Compare the value of A2 and A3, assign the greater number to A1
478 |[[MIN>>||anchor="HMIN"]]|Compare the value of A2 and A3, assign the smaller number to A1
479 |[[RadToDeg>>||anchor="HRadToDeg"]]|Convert radiant value to degree
480 |[[S2F>>||anchor="HS2F"]]|Convert string to floating in the specified format
481 |[[SWAP>>||anchor="HSWAP"]]|Exchange the high and low bytes of the parameter
482 |[[W2B>>||anchor="HW2B"]]|Combine the high byte of the value of two consecutive addresses into a new value
483 |[[W2D>>||anchor="HW2D"]]|Convert the unsigned Word to unsigned Dword and save the result
484 |[[W2F>>||anchor="HW2F"]]|Convert a 16bit integer to a 32bit floating, and then save to the next word address
485 |[[W2S>>||anchor="HW2S"]]|Convert integer word text as S1 format, and then save
486
487 == String processing ==
488
489 (% class="table-bordered" %)
490 |=(% style="width: 180px;" %)**Function**|=(% style="width: 1309px;" %)**Introduction**
491 |[[A2I>>||anchor="HA2I"]]|A string of length is intercepted from A1 and converted to a single/double word integer, and then this integer is assigned to A2
492 |[[InStr>>||anchor="HInStr"]]|Return the position of str1 in str2
493 |[[Left>>||anchor="HLeft"]]|Return a string of the specified length from the left side of parameter
494 |[[Len>>||anchor="HLen"]]|Return the string length
495 |[[LTrim>>||anchor="HLTrim"]]|Remove the left empty part of the string and return
496 |[[Mid>>||anchor="HMid"]]|Returns a string contain a specified characters length from a string
497 |[[Right>>||anchor="HRight"]]|Return a string of the specified length from the right side of parameter
498 |[[RTrim>>||anchor="HRTrim"]]|Clear the empty part on the right side of string [str], then assign the empty part to val
499 |[[Trim>>||anchor="HTrim"]]|Return a value of an address without empty string next to it
500 |[[UCase>>||anchor="HUCase"]]|Capitalize the string data, and then assign the value to val
501
502 == Fixed constant ==
503
504 (% class="table-bordered" %)
505 |=**Function**|=**Introduction**
506 |Pi|pi = 3.14159265358979321
507 |True|TRUE = 1
508 |False|FALSE = 0
509 |Operator|Operator in scripts edit window
510 |Variable|A variable is any factor, trait, or condition that can exist in differing amounts or types
511
512 == Bit control ==
513
514 (% class="table-bordered" %)
515 |=(% style="width: 178px;" %)**Function**|=(% style="width: 1311px;" %)**Introduction**
516 |[[Clrb>>||anchor="HClrb"]]|Set the bit of A1 as FALSE
517 |[[InvB>>||anchor="HInvB"]]|The state of inverse bit
518 |[[SetB>>||anchor="HSetB"]]|Set the bit A1 ON
519
520 == File operation ==
521
522 |=(% style="width: 178px;" %)**Function**|=(% style="width: 1311px;" %)**Introduction**
523 |(% style="width:178px" %)[[HmiRegoperator>>path:#HHmiRegoperator]]|(% style="width:1311px" %)Data of Upload/ Download address
524 |(% style="width:178px" %)[[CopyFile>>path:#HCopyFile]]|(% style="width:1311px" %)Copy the A3 file from the A1 directory to the A2 directory according to the format of A4 and A5
525 |(% style="width:178px" %)[[DbToCSVFile>>path:#HDbToCSVFile]]|(% style="width:1311px" %) file to csv format and export it
526 |(% style="width:178px" %)[[FileCmpDir>>path:#HFileCmpDir]]|(% style="width:1311px" %)The filename input and the filename in the folder whether is duplicate or not
527 |(% style="width:178px" %)[[MyDeleteFile>>path:#HMyDeleteFile]]|(% style="width:1311px" %)Delete the designated file
528 |(% style="width:178px" %)[[WriteWordToFile>>path:#HWriteWordToFile]]|(% style="width:1311px" %)Write data with designated length to designated file
529 |(% style="width:178px" %)[[ReadWordFormFile>>path:#HReadWordFormFile]]|(% style="width:1311px" %)Read data with designated length from designated file
530
531
532
533 == Comparison ==
534
535 (% class="table-bordered" %)
536 |=(% colspan="2" style="width: 389.5px;" %)Function|=Introduction
537 |(% rowspan="8" %)IF... THEN GOTO...|(% style="width:148.719px" %)IF=|(% rowspan="18" style="width:691.5px" %)Execute correspond instruction when fulfill condition. Condition will be tested during executing if. it will execute the next instruction block of then, if condition is true. Otherwise, execute the later of else. Complete the two instructions, next execute the later of End if.
538 |(% style="width:148.719px" %)IF<>
539 |(% style="width:148.719px" %)IF>
540 |(% style="width:148.719px" %)IF>=
541 |(% style="width:148.719px" %)IF<
542 |(% style="width:148.719px" %)IF<=
543 |(% style="width:148.719px" %)IF AND=0
544 |(% style="width:148.719px" %)IF AND<>0
545 |(% rowspan="8" style="width:255.281px" %)IF|(% style="width:148.719px" %)IF=
546 |(% style="width:148.719px" %)IF<>
547 |(% style="width:148.719px" %)IF>
548 |(% style="width:148.719px" %)IF>=
549 |(% style="width:148.719px" %)IF<
550 |(% style="width:148.719px" %)IF<=
551 |(% style="width:148.719px" %)IF AND=0
552 |(% style="width:148.719px" %)IF AND<>0
553 |(% colspan="2" style="width:389.5px" %)ELSE
554 |(% colspan="2" style="width:389.5px" %)ENDIF
555
556 == **Applicatio**n** type** ==
557
558 (% class="table-bordered" %)
559 |=(% style="width: 181px;" %)**Function**|=(% style="width: 1308px;" %)**Introduction**
560 |[[AddrStringCompare>>||anchor="HAddrStringCompare"]]|Compare the designated length of two character strings
561 |[[Beep>>||anchor="HBeep"]]|Enable buzzer
562 |[[IsFloating>>||anchor="HIsFloating"]]|whether a parameter is floating, return TRUE if it is floating, otherwise return FALSE
563 |[[IsInteger>>||anchor="HIsInteger"]]|whether a parameter(A1) is integer, return TRUE if the parameter is integer, otherwise return FALSE
564 |[[Log>>||anchor="HLog"]]|Log function: return the natural logarithm of the value
565 |[[Log10>>||anchor="HLog10"]]|Log function: return the natural logarithm of the value
566 |[[MSeconds>>||anchor="HMSeconds"]]|Display the current microseconds of system
567 |[[NewNoAddr>>||anchor="HNewNoAddr"]]|At the basic of source address A2,offset designated length,obtain a new address A1
568 |[[NewStatAddr>>||anchor="HNewStatAddr"]]|At the basic of source address A2,offset the designated length,to obtain a new station A1.
569 |[[NStringCompare>>||anchor="HNStringCompare"]]|Compare whether the designated length of two strings is the same,return 1 to A1 if yes,otherwise return 0
570 |[[Power>>||anchor="HPower"]]|The value of [expr2] to the power of [expr1] will be assigned to Var
571 |[[RAND>>||anchor="HRAND"]]|Generate a random number
572 |[[ReadAddr>>||anchor="HReadAddr"]]|Assign the value in the specified address to [word]
573 |[[SleepA>>||anchor="HSleepA"]]|Wait time T(ms)
574 |[[WriteAddr>>||anchor="HWriteAddr"]]|Assign the value from A2 to address A1
575
576 == Others ==
577
578 (% class="table-bordered" %)
579 |=(% style="width: 182px;" %)**Function**|=(% style="width: 1307px;" %)**Introduction**
580 |[[DIM...AS...>>||anchor="HDIM...AS..."]]|Declare a variable
581 |do|Condition determent instruction
582 |[[Function>>||anchor="HFunction"]]|Differ from internal function, need to declare the name, parameter, code of the function
583 |[[Sub>>||anchor="HSub"]]|Declare the name, parameters and codes of the Sub (sub function)
584 |[[PrintText>>||anchor="HPrintText"]]|Output the contents to the printer for printing
585 |[[PI_GetTickCount>>||anchor="HPI_GetTickCount"]]|Write the starting time in the set address as a 32-bit integer
586 |[[StAndFtChange>>||anchor="HStAndFtChange"]]|Calculate the number of seconds from January 1, 1970 to the current time
587 |[[GetServerDelayInfo>>||anchor="HGetServerDelayInfo"]]|Convert string to hexadecimal number
588
589 = **Function description** =
590
591 == A2H ==
592
593 **Function**
594
595 Val = A2H(A1)
596
597 **Description**
598
599 Convert string in the specified address to a hexadecimal number;
600
601 **Parameters**
602
603 * **A1:** Source data, only convert the first four digits of string
604 * **Val:** The value is hexadecimal number.
605
606 **Example**
607
608 {{code language="basic"}}
609 @W_HDW20=A2H(@W_HDW10) ' convert the string of HDW10 to hex then save in HDW20.
610 {{/code}}
611
612 **Input:** @W_HDW10=255
613
614 **Result:** @W_HDW20=255
615
616 (% class="box infomessage" %)
617 (((
618 **✎Note:**
619
620 * A1 needs to be address (such as:@W_HDW000002).
621 * Only [0~~1], [a~~f] can be converted, others will be converted to 0
622 )))
623
624 == A2I ==
625
626 **Function**
627
628 A2I (A1, A2, length, S)
629
630 **Description**
631
632 Intercept a string of the specified length from A1,convert it to a single/double word integer and assign this integer to A2.
633
634 **Parameters**
635
636 * **A1:** String to be intercepted
637 * **A2:** The final integer value
638 * **Length:** intercepts the length of the string
639 * **S:** Control single or double words.
640 ** S=0, indicating an integer single word; S=1, indicating an integer double word.
641
642 **Return value:** none
643
644 **Example**
645
646 {{code language="basic"}}
647 A2I("@W_HDW200","@W_HDW100",4,0) 'converts a string into a 16-bit (single word) decimal integer
648
649 A2I("@W_HDW600","@W_HDW500",4,1)' converts a string to a 32-bit (double word) decimal integer
650 {{/code}}
651
652 **Input: **@W_HDW200="12345", **Result:** @W_HDW100=1234
653
654 **Input: **@W_HDW600="12345", **Result:** @W_HDW500=1234
655
656 (% class="box infomessage" %)
657 (((
658 **✎Note:** A1 and A2 need to be address (such as:@W_HDW000002).
659 )))
660
661 == **Abs** ==
662
663 **Function**
664
665 val = Abs(A1)
666
667 **Description**
668
669 The absolute value of A1.
670
671 **Parameters**
672
673 * **A1: **the data of absolute value, need to be variable.
674 * **Val: **it is absolute value that is address or variable.
675
676 **Example**
677
678 {{code language="lua"}}
679 Dim a as integer 'a is defined as integer
680
681 a = SignedInt16("@W_HDW0")'convert the data of @W_HDW0 into signed data.
682
683 @W_HDW1 = Abs(a) 'assign the returned absolute value to @W_HDW1
684 {{/code}}
685
686 **Input: **@W_HDW0=-6
687
688 **Result: **@W_HDW1=6
689
690 (% class="box infomessage" %)
691 (((
692 **✎Note: SignedInt16** function is designed to convert unsigned to signed.
693 )))
694
695 == **ACos** ==
696
697 **Function**
698
699 val = ACos(A1)
700
701 **Description**
702
703 To compute the inverse cosine value of A1.
704
705 **Parameters**
706
707 * **A1: **floating value, can be an address or variable.
708 * **Val: **return value is floating, can be an address or variable.
709
710 **Example**
711
712 {{code language="lua"}}
713 Dim a ,b as floating'define two float variable a,b
714
715 a = 0.5 'assign the designated value to a
716
717 b = ACos(a) 'the inverse cosine value of "a" is a radian which assign to variable b.
718
719 'to add the following sentence if needed to view the return value:
720
721 float2d("@W_HDW200", b)'float b written into HDW200.
722 {{/code}}
723
724 **Result:** @W_HDW200=1.047
725
726 (% class="box infomessage" %)
727 (((
728 **✎Note:** Please call **RadToDeg** function to convert radian into angle.
729 )))
730
731 == **AddrStringCompare** ==
732
733 **Function**
734
735 val = AddrStringCompare(A1, A2, length)
736
737 **Description**
738
739 It is designed to compare the designated length of two character strings. The string value is 1 when the two strings are the same.
740
741 **Parameters**
742
743 * **A1, A2: **character string, need to be an address (such as:"@W_HDW000002")
744 * **Length: **The length of character string.
745 * **Val: **Return value, 0 or 1.
746
747 **Example**
748
749 {{code language="lua"}}
750 if AddrStringCompare("@W_HDW10","@W_HDW0",2)=1 then
751
752 'compare the character string of HDW10 and @W_HDW0 whether value are 1.
753
754 @W_HDW20=1 '@W_HDW20 display 1
755
756 else
757
758 @W_HDW20=0'@W_HDW20 display 0
759
760 Endif
761 {{/code}}
762
763 **Input: **@W_HDW10="1a2 ", @W_HDW0="1a2 ",
764
765 **Result:** @W_HDW20=1
766
767 **Input: **@W_HDW10="ab2 ", @W_HDW0="12a ",
768
769 **Result: **@W_HDW20=0
770
771 == **Asc** ==
772
773 **Function**
774
775 val = Asc(A1)
776
777 **Description**
778
779 Return the first character of the string in ASCII value.
780
781 **Parameters**
782
783 * **A1:**character string, it can be an address (such as: @W_HDW000002)
784 * **val:**return value,ASCII value,it could be an address or variable.
785
786 **Example**
787
788 {{code language="lua"}}
789 @W_HDW10 = Asc("A") 'return the ASCII value of A to HDW10
790
791 @W_HDW11 = Asc("a")'return the ASCII value of a to HDW11
792
793 @W_HDW12 = Asc("Apple") 'return the first character A of string Apple to HDW12
794
795 @W_HDW13 = Asc("123") 'return the first character ASCII value 1 of string 123 to HDW13.
796 {{/code}}
797
798 **Result:**
799
800 * @W_HDW10 = 65
801 * @W_HDW11 = 97
802 * @W_HDW12 = 65
803 * @W_HDW13 = 49
804
805 == **AsFloating** ==
806
807 **Function**
808
809 val = AsFloating(A1)
810
811 **Description**
812
813 Convert parameter A1 to a float.
814
815 **Parameters**
816
817 * A1: integer variable.
818 * **val: **return float value, can be a variable or address.
819
820 **Example**
821
822 {{code language="lua"}}
823 Dim a as integer 'define a integer variable {a}.
824
825 a = @W_HDW10 'assign @W_HDW10 to a
826
827 b = AsFloating(a) 'convert integer a to float then assign to b.
828
829 b = b/1.2 'add as following sentence when need to view the return value:
830
831 Float 2D("@W_HDW11",b) 'float variable b written into HDW11.
832 {{/code}}
833
834 **Input: **@W_HDW10=24,
835
836 **Result: **@W_HDW11=20.00(set two decimals)
837
838 == **ASin** ==
839
840 **Function**
841
842 val = ASin(A1)
843
844 **Description**
845
846 Calculate the arcsine value of A1.
847
848 **Parameters**
849
850 * **A1: **Float can be an address or variable.
851 * **Val: **Return float value, can be an address or variable.
852
853 **Example**
854
855 {{code language="lua"}}
856 Dim a, b as floating'define two float variable a,b
857
858 a = 0.5'assign the designated value to a
859
860 b=ASin(a) 'calculate the arcsine value of a ,assign the radian to b.
861
862 'Add the following command if need to view the return value:
863
864 float2d ("@W_HDW200", b) 'float variable b written into HDW200
865 {{/code}}
866
867 **Result: **@W_HDW200=0.524
868
869 (% class="box infomessage" %)
870 (((
871 **✎Note:** Pleasecall **RadToDeg** function to convert radian into angle.
872 )))
873
874 == **AsInteger** ==
875
876 **Function**
877
878 val = AsInteger(A1)
879
880 **Description**
881
882 Convert parameter A1 to integer value.
883
884 **Parameters**
885
886 * **A1: **floating need to be a variable.
887 * **Val: **the value returned could can be a variable or address.
888
889 **Example**
890
891 {{code language="lua"}}
892 Dim a as floating 'define floating variable a
893
894 a = D2Float("@W_HDW0",a) 'use D2Float function to save the float date of HDW0 in a
895
896 b= AsInteger(a) 'convert the float a into integer, the return value assigned to b
897
898 @W_HDW10=b 'save b to HDW10
899 {{/code}}
900
901 **Input:** @W_HDW0=20.12,
902
903 **Result:** @W_HDW10=20
904
905 == **AsString** ==
906
907 **Function**
908
909 val = AsString(A1)
910
911 **Description**
912
913 Convert parameter A1 to a character string.
914
915 **Parameters**
916
917 * A1: not string parameter, it can be a variable.
918 * Val: return string value, variable or address.
919
920 **Example**
921
922 Script 1:
923
924 {{code}}
925 a=123 'assign a value to a
926
927 b=234 'assign a value to b
928
929 c=AsString(a)+AsString(b) 'convert a and b to string then add up the two strings ,assign the result to c.
930
931 @W_HDW0=c 'assign c to HDW0
932
933 d=a+b 'plus a with b
934
935 @W_HDW100=d 'assign d to (HDW100)
936 {{/code}}
937
938 **Result: **
939
940 * @W_HDW0=123234
941 * @W_HDW100=357
942
943 Script 2:
944
945 {{code language="lua"}}
946 W2S("@W_HDW200","@W_HDW300","02d")
947
948 W2S("@W_HDW210","@W_HDW400","02d")
949
950 W2S("@W_HDW220","@W_HDW500","02d")
951
952 @W_HDW0=AsString(@W_HDW300)+AsString(@W_HDW400)+AsString(@W_HDW500)
953 {{/code}}
954
955 **Input: **@W_HDW200=12,@W_HDW210=34,@W_HDW220=56
956
957 **Result :**@W_HDW300=12,@W_HDW400=34,@W_HDW500=56,@W_HDW0=123456
958
959 (% class="box infomessage" %)
960 (((
961 **✎Note:** Ensure the data always is two words; otherwise occur error. reference the other chapter of W2S function
962 )))
963
964 == **ATan** ==
965
966 **Function**
967
968 var = ATan(A1)
969
970 **Description**
971
972 Return an arctangent value,the radian ranges -pi/2 to pi/2.
973
974 **Parameters**
975
976 * **A1: **Can be float, address or variable.
977 * **Val: **radian of return value.
978
979 **Example**
980
981 {{code language="basic"}}
982 @W_HDW20= Atan(@W_HDW10)'save the arctangent value of (HDW10) to (HDW20)
983 {{/code}}
984
985 **Input: **@W_HDW10=1.000,@W_HDW20=0.785
986
987 (% class="box infomessage" %)
988 (((
989 **✎Note:** Please call RadToDeg function convert radian to angle.
990 )))
991
992 == **ATan2** ==
993
994 **Function**
995
996 val = ATan2(A1,A2)
997
998 **Description**
999
1000 Return the arctangent value of A1/A2,radian range
1001
1002 **Parameters**
1003
1004 * **A1, A2:** Address or variable.
1005 * **Val: **returned value is a radian, range -pi to pi.
1006 * **Notice: **ATan2 use sign of two parameters to define the quadrant of return value.
1007
1008 **Example**
1009
1010 //{{code language="lua"}}@W_HDW20= ATan2 (@W_HDW10,@W_HDW12)'save the arctangent value of (HDW10/HDW12) to (HDW20).{{/code}}//
1011
1012 **Input:**@W_HDW10=1.0,@W_HDW12=1.0,
1013
1014 **Result: **@W_HDW20=0.785
1015
1016 (% class="box infomessage" %)
1017 (((
1018 **✎Note:** Please call **RadToDeg** function convert radian to angle.
1019 )))
1020
1021 == **B2W** ==
1022
1023 **Function**
1024
1025 B2W(A1, A2, length)
1026
1027 **Description**
1028
1029 Convert an array (begins with A2, unit: byte, to another array (begins with A1, unit: word).
1030
1031 **Parameters**
1032
1033 * **A1: **Saving address after converting
1034 * **A2: **Address of the value be converted 
1035 * **Length:** The length of conversion
1036
1037 **Return value: **None
1038
1039 **Example**
1040
1041 //{{code language="lua"}}B2W(@W_HDW100,@W_HDW10,2) 'convert (@W_HDW10) to the length of 2,save as the result that begins with @W_HDW100.{{/code}}//
1042
1043 **Input: **@W_HDW10=1A2B
1044
1045 **Result: **
1046
1047 * @W_HDW100=2B
1048 * @W_HDW101=1A
1049
1050 (% class="box infomessage" %)
1051 (((
1052 **✎Note:**
1053
1054 * A1 and A2 need to be address(e.g.: @W_HDW000002);
1055 * Length could be address or variable;
1056 * This is a subprogram; it has no returned value.
1057 )))
1058
1059 == **BCD** ==
1060
1061 **Function**
1062
1063 val = BCD(A1)
1064
1065 **Description**
1066
1067 Convert A1(binary) to BCD, save the result as return value.
1068
1069 **Parameters**
1070
1071 * **A1: **The binary be converted; it can be an address or variable.
1072 * **Val: **Return value, BCD code; it can be an address or variable.
1073
1074 **Example**
1075
1076 //{{code language="lua"}}@W_HDW20=BCD(@W_HDW10) 'convert HDW10 (binary) to BCD code, then save in (HDW20){{/code}}//
1077
1078 **Input:** @W_HDW10=11111111(binary)
1079
1080 **Result:** @W_HDW20=255
1081
1082 (% class="box infomessage" %)
1083 (((
1084 **✎Note:** Return value is a word; it hexadecimal corresponds to BCD code.
1085 )))
1086
1087 == **Beep** ==
1088
1089 **Function**
1090
1091 Beep()
1092
1093 **Description**
1094
1095 Enable buzzer
1096
1097 **Parameters**
1098
1099 None
1100
1101 **Example**
1102
1103 {{code language="lua"}}
1104 if @B_HDX100.0=1 then 'beep when the bit switch HDX100.0 set ON
1105
1106 beep()
1107
1108 endif
1109 {{/code}}
1110
1111 **Result: **HMI beep when bit switch HDX100.0 set ON.
1112
1113 == **BIN** ==
1114
1115 **Function**
1116
1117 Val = BIN(A1)
1118
1119 **Description**
1120
1121 Convert A1 (BCD) into binary, save the result in return value.
1122
1123 **Parameters**
1124
1125 * **A1:** The BCD code is converted; it can be address or variable.
1126 * **Val:** Return binary value,it can be address or variable.
1127
1128 **Example**
1129
1130 //{{code language="lua"}}@W_HDW20=BIN(@W_HDW10) 'convert HDW10(BCD) to binary, save the result in (HDW20){{/code}}//
1131
1132 **Input:** @W_HDW10=255
1133
1134 **Result:** @W_HDW20=11111111 (binary)
1135
1136 == **BMOV** ==
1137
1138 **Function**
1139
1140 BMOV(A1, A2,length)
1141
1142 **Description**
1143
1144 Copy data with a designated length from source address A2 to A1.
1145
1146 **Parameter**
1147
1148 * **A1:** saving address;
1149 * **A2:** source address;
1150
1151 **length:** operating length;
1152
1153 **Example**
1154
1155 {{code language="lua"}}
1156 @W_HDW20 = 20 'assign value to HDW20
1157
1158 @W_HDW21 = 21 'assign value to HDW21
1159
1160 @W_HDW22 = 22 'assign value to HDW22
1161
1162 BMOV(@W_HDW10,@W_HDW20,3) 'assign the word address of HDW20, HDW21, HDW22 to HDW10, HDW11, HDW12
1163 {{/code}}
1164
1165 **Result:**
1166
1167 * @W_HDW10 = 20
1168 * @W_HDW11 = 21
1169 * @W_HDW12 = 22
1170
1171 **✎Note:**
1172
1173 * A1 and A2 need to be address
1174 * Length can be an integer variable or an address. When destAddr and srcAddr are PLC (external device) addresses, the length range is 1-2048, and the 2049th address would not be operated when the range is exceeded.
1175 * When destAddr and srcAddr are HMI addresses, the length range is 1-4096, and This function is invalid when out of range.
1176
1177 == **Chr** ==
1178
1179 **Function**
1180
1181 val = Chr(A1, A2, ...)
1182
1183 **Description**
1184
1185 Convert integer parameter into correspond ASCII character, return the character string.
1186
1187 **Parameters**
1188
1189 * **A1, A2....:** converted integer; it can be an address or variable.
1190 * **Val: **returned value, can be an address or variable.
1191
1192 **Example**
1193
1194 {{code language="lua"}}
1195 @W_HDW100=Chr(@W_HDW20, @W_HDW21, @W_HDW22, @W_HDW23, @W_HDW24)
1196
1197 'convert the value of(HDW20, HDW21 ,HDW22, HDW23, HDW24) to ASCII character, assign the value to (HDW100)
1198 {{/code}}
1199
1200 **Input** 72,69,76,76,79 step by step according to HDW20, HDW21, HDW22, HDW23, HDW24,
1201
1202 **Result: **returns HELLO to (@W_HDW100).
1203
1204 == **Clrb** ==
1205
1206 **Function**
1207
1208 ClrB(A1)
1209
1210 **Description**
1211
1212 Set the bit of A1 as FALSE (0).
1213
1214 **Parameters**
1215
1216 **A1:** System address(bit)
1217
1218 **✎Note:** subprogram has no return value.
1219
1220 **Example**
1221
1222 //{{code language="lua"}}ClrB(@B_HDX100.0) 'assign 0 to (@B_HDX100.0){{/code}}//
1223
1224 == **Constant** ==
1225
1226 **Description**
1227
1228 Script supported constant, users can use on script:
1229
1230 pi = 3.14159265358979321
1231
1232 TRUE = 1
1233
1234 FALSE = 0
1235
1236 **Example**
1237
1238 {{code language="lua"}}
1239 Dim a as integer 'define integer a
1240
1241 a = RadToDeg(pi) 'convert radian pi to angle then assign to a,RadToDeg function is used to convert radian to angle.
1242
1243 @W_HDW11 = a 'assign a to (HDW11)
1244 {{/code}}
1245
1246 **Result: **@W_HDW11=180
1247
1248 == **CopyFile** ==
1249
1250 **Function**
1251
1252 A6=CopyFile(A1,A2,A3,A4,A5)
1253
1254 **Description**
1255
1256 Copy the A3 file from the A1 directory to the A2 directory according to the format of A4 and A5, and write returned value status to A6.
1257
1258 **Parameters**
1259
1260 * **A1: **the source path of the file to be copied.
1261 * **A2: **target path.
1262 * **A3:** the name of the file to be copied.
1263 * **A4: **copy type (0: copy file, 1: copy directory).
1264 * **A5: **Whether to overwrite the file with the same name when copying (0: Yes, 1: No).
1265 * **A6: **returned value.
1266 ** 0: copy failed
1267 ** 1: copy succeeded
1268 ** 2: Parameter error
1269 ** 3: U disk does not exist
1270 ** 4: SD card does not exist
1271 ** 5: Path error
1272
1273 **Example**
1274
1275 Copy a single file:
1276
1277 {{code language="lua"}}
1278 @W_HDW100 = " test.csv"
1279
1280 CopyFile("UDisk/Test","Flash/Test","test.csv",0,0) 'Copy the Test.csv file in the UDisk/Test directory to the Flash/Test directory.
1281
1282 Can also be written as CopyFile("UDisk/Test","Flash/Test",@W_HDW100,0,0)
1283
1284 (2) Copy the entire directory file:
1285
1286 CopyFile("UDisk/Test","Flash/Test","",1,0) ' Copy the files in the UDisk/Test
1287
1288 directory to the Flash/Test directory.
1289 {{/code}}
1290
1291 (% class="box infomessage" %)
1292 (((
1293 **✎Note:**
1294
1295 * Both source and destination paths need to begin with UDisk or Flash or SDCard;
1296 * A1 and A2 could be string (requires double quotes) or variable, maximum character length 127 allowed in path;
1297 * A3 could be a string, such as: [FileName] (requires double quotes); or address, such as: @W_HDW100 (no need to add double quotes);
1298 * A4 and A5 could be values, addressesor variable;
1299 * A6 could be address or variable.
1300 )))
1301
1302 == **Cos** ==
1303
1304 **Function**
1305
1306 Val = Cos(A1)
1307
1308 **Description**
1309
1310 Return a cosine value of an angle.
1311
1312 **Parameters**
1313
1314 * **A1: **a float radian of angle, it can be an address or variable.
1315 * **Val: **return float value, it can be an address or variable.
1316
1317 **Example**
1318
1319 {{code language="lua"}}
1320 Dim a, b as floating 'define float a, b
1321
1322 b = pi/3 'convert the value of HDW11 to float and assign to 'b'.
1323
1324 a=Cos(b) 'return the cosine value of'b' and assign the result to 'a'.
1325
1326 'to add the following sentence if need to view the return value:
1327
1328 Float2D("@W_HDW20",a) 'the float value of a written into HDW13.
1329 {{/code}}
1330
1331 **Result: **@W_HDW20=0.5
1332
1333 (% class="box infomessage" %)
1334 (((
1335 **✎Note:** Please call **RadToDeg** function convert radian to angle.
1336 )))
1337
1338 == **D2F** ==
1339
1340 **Function**
1341
1342 D2F (A1, A2) or A1= D2F (A1, A2)
1343
1344 **Description**
1345
1346 Convert the 32-bit integer format data to float then output the result.
1347
1348 **Parameters**
1349
1350 * **A1: **required data, begin with"@";
1351 * **A2: **source data, begin with"@";
1352
1353 **Example**
1354
1355 {{code language="lua"}}
1356 D2F(@W_HDW2,@W_HDW0) 'convert the double word (HDW0) to float, save the result to (HDW2).
1357
1358 @W_HDW2=D2F(@W_HDW2,@W_HDW0) 'convert the double word (HDW0) to float, save the result to (HDW2).
1359 {{/code}}
1360
1361 **Result: **HDW0=100, HDW2=100
1362
1363 == **D2Float** ==
1364
1365 **Function**
1366
1367 F= D2Float("A1",F)
1368
1369 **Description**
1370
1371 Convert the designated value to floating then assign to variable.
1372
1373 **Parameters**
1374
1375 * **A1:** Source data;
1376 * **F:** User-defined floating variable
1377
1378 **Example**
1379
1380 {{code language="lua"}}
1381 dim F as floating 'define F as floating
1382
1383 F=D2Float("@W_HDW10",F) 'assign the value of (HDW10) to F in floating
1384
1385 Float2D("@W_HDW12",F) 'copy the floating value of F to HDW12 register,use to display result.
1386 {{/code}}
1387
1388 **Result: **
1389
1390 * HDW10=200,
1391 * HDW12=200.
1392
1393 (% class="box infomessage" %)
1394 (((
1395 **✎Note:** A1 needs to be address;
1396 )))
1397
1398 == **D2Int** ==
1399
1400 **Function**
1401
1402 A2= D2Float("A1",A2)
1403
1404 **Description**
1405
1406 Output the 32-bit integer in the form of integer.
1407
1408 **Parameters**
1409
1410 * **A1:** Source data can only be the HMI internal or external register starting with "@".
1411 * **A2: **Target data can only use theinteger variable defined by script.
1412
1413 **Example**
1414
1415 {{code language="basic"}}
1416 dim var1 as integer 'define var1 as integer
1417
1418 var1=D2Int("@W_HDW0",var1) 'Read out the 32-bit integer in HDW0 and save the result in var1.
1419
1420 HDW0=9999999
1421 {{/code}}
1422
1423 **Result:** Var1=9999999
1424
1425 == **DataLogToUorSD** ==
1426
1427 **Function**
1428
1429 DataLogToUorSD (A1, A2, A3, A4, A5, A6, A7, A8)
1430
1431 **Description**
1432
1433 Exported Data record (database file) as db or csv format file, and register HSW1853 can change the exported file type.
1434
1435 (HSW1853 = 0: exported as db format, filename format: Start time-end time-group name.db)
1436
1437 (HSW1853 = 1: exported as csv format, filename format: Start time-end time-group name.csv)
1438
1439 **Parameters**
1440
1441 * A1: Data record group name address (string, must be address). For example: " @W_HDW30 "
1442 * A2: Start time address (string, must be address). For example: " @W_HDW40 "
1443 * A3: End time address (string, must be address). For example: " @W_HDW50 "
1444 * A4: db file save location (integer value)
1445 ** = 1: Saved on SD card
1446 ** = 2: Save in USB flash drive
1447 * A5: Return value(string, must be address). For example: " @W_HDW60 ", return result of the script will be written to HDW60; Meaning of value in address:
1448 ** = 1: Script executed successfully
1449 ** = 100: U disk or SD card unplugged
1450 ** = 101: U disk or SD card does not exist
1451 ** = 102: Script executed failed
1452 ** = 201: db export failed
1453 ** = 203: Script is being executed (previous executed script doesn't exit)
1454 * A6: Script running mode (integer value)
1455 ** = 1: Wait for script execution before exit
1456 ** = Others: Exit without waiting for the result of script execution (when the data record volume is large, it takes some time to execute the script, and when wait for the result of script execution, it may affect the execution of other scripts)
1457 * A7: Path name address (string, must be address). For example: " @W_HDW70 ", script will automatically prefix the folder name HMI_, for example: @W_HDW70 = "Log", the db file will be saved under the directory of HMI_Log in U disk or SD.
1458 * A8: Reserved address (string, must be address). For example:" @W_HDW80 ". This address is temporarily useless but needs to be set.
1459
1460 **Example**
1461
1462 {{code language="basic"}}
1463 @W_HDW30 = "Record test" 'Data record group name
1464 @W_HDW40 = 2021
1465 @W_HDW41 = 04
1466 @W_HDW42 = 30
1467 @W_HDW43 = 09
1468 @W_HDW44 = 0
1469 @W_HDW45 = 0
1470 'Start time 2021-04-30 09:00:00
1471 @W_HDW50 = 2021
1472 @W_HDW51 = 04
1473 @W_HDW52 = 30
1474 @W_HDW53 = 20
1475 @W_HDW54 = 0
1476 @W_HDW55 = 0
1477 'End time 2021-04-30 20:00:00
1478 @W_HDW70 = "Log" 'Directory name
1479
1480 DataLogToUorSD ("@ W_HDW30", "@ W_HDW40", "@ W_HDW50", 2, "@ W_HDW60", 1, "@ W_HDW70", "@ W_HDW80")
1481
1482 'Export the data records collected from 2021-04-30 09:00:00 to 2021-04-30 20:00:00 under the group name of the record test to the HMI_Log directory of the U disk with the file name being 20210430090000-20210430200000-record tests. db. (HSW1853 is 0).
1483 {{/code}}
1484
1485 == **DbToCSVFile** ==
1486
1487 **Function**
1488
1489 A8=DbToCSVFile(A1,A2,A3,A4,A5,A6,A7)
1490
1491 **Description**
1492
1493 Convert db (database file) file to csv format and export it.
1494
1495 **Parameters**
1496
1497 * **A1: **db file save path (value is integer);
1498 ** =0: Alarm record file in HMI flash;
1499 ** =1: Alarm record file in UDisk (USB flash disk);
1500 ** =2: Alarm record file in SD card;
1501 ** =3: Data record file in HMI flash;
1502 ** =4: Data record file in UDisk (USB flash disk);
1503 ** =5: Data record file in SD card;
1504 * **A2: **group numer of db file (value is integer);
1505 ** Used during exporting data record file, the group number could be seen in the data record setting interface;
1506 * **A3:** csv file save path (value is integer);
1507 ** =0: Save in UDisk (USB flash disk);
1508 ** =1: Save in SD card;
1509 * **A4: **csv name;
1510 * **A5: **start time of data recordin db file(string), consecutive 6 word addresses (the values in the address are year, month, day, hour, minute, second);
1511 * **A6:** end time of data recordin db file(string), consecutive 6 word addresses (the values in the address are year, month, day, hour, minute, second);
1512 * **A7:** csv encoding format;
1513 ** =0 UTF8 format;
1514 ** =1 GBK format;
1515 * **A8:** returned value;
1516 ** =0: Failed to export;
1517 ** =1: Exported;
1518 ** =2: db file path error;
1519 ** =3: U disk or SD card does not exist;
1520 ** =4: csv name error;
1521 ** =5: db file does not exist;
1522 ** =6: csv file already exists;
1523
1524 **Example**
1525
1526 * @W_HDW100 = 2018
1527 * @W_HDW101 = 12
1528 * @W_HDW102 = 25
1529 * @W_HDW103 = 19
1530 * @W_HDW104 = 10
1531 * @W_HDW105 = 30
1532 * @W_HDW200 = 2018
1533 * @W_HDW201 = 12
1534 * @W_HDW202 = 25
1535 * @W_HDW203 = 20
1536 * @W_HDW204 = 10
1537 * @W_HDW205 = 30
1538
1539 **Export data record file**
1540
1541 {{code language="basic"}}
1542 DbToCsvFile(3,2,0,"123.csv","@W_HDW100","@W_HDW200",0)
1543 'In the HMI flash, the group number is 2, and the data records collected in the time of 2010.12.25 19:10:30-2018.12.25 20:10:30
1544 'are exported to the 123.csv file in the Udisk in UTF8 format.
1545 {{/code}}
1546
1547 **Export alarm record file**
1548
1549 {{code language="basic"}}
1550 DbToCsvFile(0,0,0,"456.csv","@W_HDW100","@W_HDW200",1)
1551 'The alarm records generated in HMI Flash at 2018.12.25 19:10:30-2018.12.25 20:10:30
1552 'are exported to the 456.csv file in the Udisk in GBK format
1553 {{/code}}
1554
1555 (% class="box infomessage" %)
1556 (((
1557 **✎Note:**
1558
1559 * A1 can be an address or a variable or a value, and the path need to start with UDisk or Flash or SDCard;
1560 * A2 can be an address or a variable or a value;
1561 * A3 can be an address or a variable or a value, and the path need to start with UDisk or Flash or SDCard;
1562 * A4 can be an address or variables or string, and the length of the file name (sum of values, English, Chinese) could not exceed 127;
1563 * A5 need to be an address;
1564 * A6 need to be an address;
1565 * A7 can be an address or a variable or a value;
1566 )))
1567
1568 == **DegToRad** ==
1569
1570 **Function**
1571
1572 A2 = DegToRad(A1)
1573
1574 **Description**
1575
1576 Convert the angle into correspond radian, and display.
1577
1578 **Parameters**
1579
1580 * **A1:** inputting angle supports address, other variable or floating.
1581 * **A2: **outputting radian supports address, other variable or floating.
1582
1583 **Example**
1584
1585 Script 1
1586
1587 //{{code language="lua"}}@W_HDW12=DegToRad(@W_HDW10) 'input angle on (HDW10),convert to correspond redian and copy to (HDW12){{/code}}//
1588
1589 **Result: **HDW10=180; HDW12=3.14159
1590
1591 Script 2
1592
1593 {{code language="lua"}}
1594 dim a as floating 'set variable
1595
1596 dim b as floating 'set variable
1597
1598 b=30 'input angle
1599
1600 a=DegToRad(b) 'convert the length of radian and copy to variable {a}
1601
1602 float2d("@W_HDW0", a) 'display the value of floating on(HDW0)
1603 {{/code}}
1604
1605 **Result:** HDW0=0.52360
1606
1607 == **DIM ... AS ...** ==
1608
1609 **Function**
1610
1611 Dim "variable" as "date type"
1612
1613 **Description**
1614
1615 Declare a variable, stable the type of data.
1616
1617 **Parameters**
1618
1619 * **Variable: **begin with letter, other character can be letter, numbers, underscores ('_'), need to begin with '@' if it is address;
1620 * **Data type: **string,floating,integer;
1621
1622 **Example**
1623
1624 {{code language="lua"}}
1625 dim a as integer 'define a as integer
1626
1627 dim @W_HDW0 as floating 'define @W_HDW0 as floating
1628
1629 dim hi as string 'define "hi" as string
1630 {{/code}}
1631
1632 **Result:**
1633
1634 a is integer
1635
1636 @W_HDW0 is floating
1637
1638 hi is string
1639
1640 (% class="box infomessage" %)
1641 (((
1642 **✎Note:** Use the variable of Dim during running, could not change the type, Dim will be missed if the type of variable is no difined. Variable could be declared in once.
1643 )))
1644
1645 == **DO ... LOOP** ==
1646
1647 **Function**
1648
1649 Do [While | Until condition]
1650
1651 [statements]
1652
1653 Loop
1654
1655 or
1656
1657 Do
1658
1659 [statements]
1660
1661 Loop [While | Until condition]
1662
1663 **Description**
1664
1665 Condition determent instruction.
1666
1667 * Do while.loop executes an instruction of block repeatedly when condition is true.
1668 * Do until.loop executes an instruction of block repeatedly until condition is false.
1669
1670 **Parameters**
1671
1672 **Condition: **determine condition; obtain the expression of True or False.
1673
1674 **Statements: **execute one or more instructions repeatedly when condition is True or until condition is True.
1675
1676 If condition is true, all statements are executed until the Wend statement is encountered. Control then returns to the While statement and condition is again checked. If condition is still True, the process is repeated. If it is not true, execution resumes with the statement following the Wend statement.
1677
1678 **Example**
1679
1680 {{code language="lua"}}
1681 dim i as integer 'end DO loop when i=100
1682
1683 do while i<100
1684
1685 i=i+1
1686
1687 @W_HDW0=i
1688
1689 loop
1690 {{/code}}
1691
1692 **Result: **HDW0=100
1693
1694 == **End** ==
1695
1696 **Function**
1697
1698 Terminates the script immediately.
1699
1700 **Description**
1701
1702 End the execution of script.
1703
1704 **Parameters**
1705
1706 **Statement:** Judging condition, use with IF together. end script when meet condition.
1707
1708 **Example**
1709
1710 //{{code language="lua"}}If a = 10 Then End 'end script when a=10.{{/code}}//
1711
1712 **Result:** End the script program.
1713
1714 == **Exp** ==
1715
1716 **Function**
1717
1718 A1=Exp(A2)
1719
1720 **Description**
1721
1722 Returns the power value of e (natural logarithm), save the outputting result to A1, e=2.71828182846.
1723
1724 **Parameters**
1725
1726 * **A1: **the goal date: the power floating value of returning, need to begin with '@'([[(% class="wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink" %)__e.g.@W_HDW10__>>path:mailto:'@'(e.g.@W_HDW10]](%%));
1727 * **A2: **Source data, natural exponential function, need to be integer or variable. Could not not begin with the address of "@"(e.g.@W_HDW10)
1728
1729 **Example**
1730
1731 {{code language="lua"}}
1732 dim a as integer'define a as integer
1733
1734 a = @W_HDW2 ' assign the value of (HDW2) to variable a
1735
1736 @W_HDW0= Exp(a)'exponential is the value of (HDW2),save result to(HDW0)
1737 {{/code}}
1738
1739 **Result:**
1740
1741 * HDW2=2,
1742 * HDW0=7.38905600
1743
1744 == **F2D** ==
1745
1746 **Function**
1747
1748 F2D (A1, A2)
1749
1750 **Description**
1751
1752 Convert a 32 bit floating to integer format, then output the result.
1753
1754 **Parameters**
1755
1756 * **A1: **Destination, the value can be an address(e.g.@W_HDW12).
1757 * **A2: **source date, it can be an address or other variable.
1758
1759 **Example**
1760
1761 //{{code language="lua"}}F2D(@W_HDW12,@W_HDW10) 'convert the floating of (HDW10) to integer, save in (HDW12).{{/code}}//
1762
1763 **Result:**
1764
1765 * HDW10=200,
1766 * HDW12=200
1767
1768 == **F2S** ==
1769
1770 **Function**
1771
1772 F2S (A1,A2,s1)
1773
1774 **Description**
1775
1776 Output a format of floating that in the type of string.
1777
1778 **Parameters**
1779
1780 * **A1:** Source address, used to store floating, the value is an address(e.g.@W_HDW200);
1781 * **A2:** Destination address, used to store string after converted, value is an address(e.g.@W_HDW100).
1782 * **S1:** the format of displaying goal data. such as the format of 03.03f,f, used for outputting a single-precision in the form of decimal.m.nf:means m column and n decimals when outputting.
1783
1784 **Example**
1785
1786 //{{code language="lua"}}F2S("@W_HDW200", "@W_HDW100", "03.03f") '(HDW200) is floating input,(HDW100) is text output;{{/code}}//
1787
1788 **Result: **
1789
1790 * HDW200=1.22365,
1791 * HDW100=1.224
1792
1793 == **FileCmpDir** ==
1794
1795 **Function**
1796
1797 FileCmpDir(A1, A2, A3, A4, A5, A6, A7, A8, A9)
1798
1799 **Description**
1800
1801 The filename input and the filename in the folder whether is duplicate or not.
1802
1803 **Parameters**
1804
1805 A1: file path (value is integer);
1806
1807 In HMI:
1808
1809 * =0: Recipe folder in HMI flash;
1810 * =1: Custom folder in UDisk (USB flash disk);
1811 * =2: Custom folder in SD card.
1812 * =3: Custom folder in HMI flash;
1813
1814 In simulator:
1815
1816 * = 0: D:/Recipe/
1817 * = 1: C:/WECON/CustomFileDir/
1818 * = 2: C:/WECON/CustomFileDir/
1819 * = 3: C:/WECON/CustomFileDir/
1820
1821 **✎Note:**
1822
1823 A1 can be an address,variable or fixed value.
1824
1825 A2: file name (value is string);
1826
1827 The file name would be compared;
1828
1829 **✎Note: **
1830
1831 A2 can be an address, variable or string. The length of file name cannot exceed 32 characters.
1832
1833 A3: folder name (value is integer);
1834
1835 The folder name would be compared;
1836
1837 **✎Note: **
1838
1839 A3 can be an address, variable or string. The length of file name cannot exceed 32 characters.
1840
1841 A4:file name display address (value is a string);
1842
1843 Display the specified number of file names in the specified folder.
1844
1845 **✎Note:**
1846
1847 A4 Can only use address here. And the length of the file name cannot exceed 32 characters.
1848
1849 A5: Function type (value is an integer)
1850
1851 ~= 0: compare whether the file name in the folder and the file name input are duplicated or not.
1852
1853 ~= 1: return list of file names.
1854
1855 ~= 100: compare file names, without input suffix .csv
1856
1857 **✎Note: **
1858
1859 A5 can be an address, variable or value.
1860
1861 A6: Return value (value is an integer)
1862
1863 ~= 1: Successfully opened the folder.
1864
1865 ~= 2: Failed to open the folder.
1866
1867 ~= 3: The file has duplicate names
1868
1869 **✎Note:**
1870
1871 A6 must be an address.
1872
1873 A7: File number (value is an integer)
1874
1875 Display the number of files in the folder (up to 100)
1876
1877 **✎Note: **
1878
1879 A7 must be an address.
1880
1881 A8: File creation time (value is a string);
1882
1883 Display the time of file creation, time occupies 32 characters
1884
1885 A9: The maximum number of files to read (value is an integer)
1886
1887 Set the maximum number of files to read (up to 100 files)
1888
1889 **✎Note:** A9 can be an address, variable or value.
1890
1891 **Example**
1892
1893 Read the specified number of files in the folder.
1894
1895 (% class="box" %)
1896 (((
1897 FileCmpDir(@W_HDW1254, @W_HDW50, "File", "", 0, "@W_HDW0", "", "", 10)'Determine whether there is a file with the same name as @W_HDW50 in the file directory of HDW1254.@W_HDW0=3 is Yes.@W_HDW0 = 1 is No.@W_HDW0=2 is comparison failed.
1898 )))
1899
1900 Compare filename input and the filename in the folder whether is duplicate or not.
1901
1902 (% class="box" %)
1903 (((
1904 FileCmpDir(@W_HDW1254, "", "File", "@W_HDW200", 1, "@W_HDW0", "@W_HDW300", "@W_HDW400", 10)’The file name under the directory File in the flash is written to the continuous address begin from @W_HDW200, the file creation time is written to the continuous address begin from @W_HDW400, the number of files is written to the address @W_HDW300, the maximum number of files is 10
1905 )))
1906
1907 Compare the csv file name in the folder and the csv file name input whether is duplicated or not.
1908
1909 (% class="box" %)
1910 (((
1911 FileCmpDir(@W_HDW1254, @W_HDW50, "File", "", 100, "@W_HDW0", "", "", 10)' Judge whether there is a file in the directory File in the flash is same with following: @W_HDW50, @W_HDW50.csv, @ W_HDW50.CSV , @W_HDW0=3 is Yes, @W_HDW0 = 1 is No ,@W_HDW0=2 is comparison failed
1912 )))
1913
1914 == **FILL** ==
1915
1916 **Function**
1917
1918 FILL (A1, A2, A3)
1919
1920 **Description**
1921
1922 Write the same value to designated address constantly.
1923
1924 **Parameters**
1925
1926 **A1:** The beginning address, it can be an address (e.g.@ W_ HDW25);
1927
1928 **A2:** Source data, it needs to be written in continuous value, the value can be an address, variable or constant;
1929
1930 **A3:** The number of operation, writing address number, it can be an address, variable or constant;
1931
1932 When the PLC (external device) address is used in this function, the length range is 1-2048, and only the 2048th address can be operated when the range is exceeded.
1933
1934 When the HMI internal address is used in this function, the length range is 1-4096. If the function is out of range, then the function is invalid.
1935
1936 **Example**
1937
1938 //FILL (@W_HDW25, 10, 3) 'At the beginning three address of @W_ HDW25 is 10.//
1939
1940 **Result: **At the beginning three address of @W_ HDW25 is 10, @W_ HDW25=10, @W_ HDW26=10, @W_ HDW27=10.
1941
1942 == **Float2D** ==
1943
1944 **Function**
1945
1946 Float2D (A1,A2);
1947
1948 **Description**
1949
1950 Copy floating value to the address.
1951
1952 **Parameters**
1953
1954 * **A1: **Goal address, the value need to be address (e.g.@W_HDW102);
1955 * **A2:** Source data, it can be floating;
1956
1957 **Example**
1958
1959 {{code language="lua"}}
1960 dim f as floating 'define f as floating
1961
1962 f=1.1 'assign a designated value to f
1963
1964 Float2D ("@W_HDW102",f) 'assign the value f to HDW102
1965 {{/code}}
1966
1967 **Result:** HDW102=1.1
1968
1969 == **For. to. step. next** ==
1970
1971 **Function**
1972
1973 For counter = start to end Step
1974
1975 [Statements]
1976
1977 Next
1978
1979 **Description**
1980
1981 Execute a command repeatedly for designated times.
1982
1983 **Parameters**
1984
1985 * **counter: **Work as a variable for loop counter;
1986 * **start: **The start value of counter, it could be any variable type or expression;
1987 * **end: **The end value of counter, it could be any variable type or expression;
1988 * **step: **Every loop, the changed value of counter is step value, step default if it is not designation. Step default as below:
1989 ** if start>end, step default is 1;
1990 ** if start< end. It could be any variable type or expression;
1991 * **statements: **Between For with Next, execute instruction set of designated times;
1992 ** Set a loop of for...Next in another loop, it can nest call the loop of for...Next. Different from a while, for only search once value from end. Empty for loop will be ignored, and could not delay time.
1993
1994 **Example**
1995
1996 {{code language="lua"}}
1997 'Use HDX2.0 to trigger the loop
1998
1999 for i=100 to 0 step -5 ' set the start is 100,end is 0,subtract 5 every time, execute 20 times totally.
2000
2001 @W_HDW100=@W_HDW100+1 ' execute (HDW100+1) 21 times totally, the final result is 21.
2002
2003 Next
2004
2005 @B_HDX2.0=0
2006 {{/code}}
2007
2008 **Result: **HDW100=21
2009
2010 == **Function** ==
2011
2012 **Function**
2013
2014 * Function name (arglist)
2015 * statements
2016 * name = expression
2017 * statements
2018 * End Function
2019
2020 **Description**
2021
2022 Unlike internal function, it needs to declare the name, parameter, code of the function.
2023
2024 **Parameters**
2025
2026 * **Name: **function name.
2027 * **arglist: **stands for the variable list of parameter, this parameter will be entered during calling function. use comma to separate.
2028 * **statements: **a set of code in running function body.
2029
2030 **Notice: **it could not define a function program at any other program body. Write name first and then follow with parameter list, when calling function. Declare function need to before be calling. in the internal function body, it could be assigned to a function name from returned value at any place. Return value is 0 if not assign function name. Functions can recursive, but it may lead to stack overflow.
2031
2032 **Example**
2033
2034 {{code language="lua"}}
2035 Function sincos (angle as floating)
2036
2037 sincos = sin(angle) + cos(angle)
2038
2039 End Function<
2040
2041 ........
2042
2043 @W_0002 = sincos(pi/2)
2044
2045 ........
2046 {{/code}}
2047
2048 == **GetServerDelayInfo** ==
2049
2050 **Function**
2051
2052 A3=GetSerVerDelayInfo(A1,A2)
2053
2054 **Description**
2055
2056 Convert string A1 to hexadecimal number.
2057
2058 **Parameters**
2059
2060 **A1:** The starting address, save the delay data of each server (10 consecutive addresses, the last 7 addresses are reserved), when the server testing fails, the value in the corresponding address is -1. The unit is ms (signed decimal number).
2061
2062 (% class="table-bordered" %)
2063 |=**Address**|=**Description**
2064 |A1|Delay data of the server configured in [Project Settings]
2065 |A1+1|Delay data of Server 1
2066 |A1+2|Delay data of Server 2
2067
2068 **A2: **Server test result address
2069
2070 (% class="table-bordered" %)
2071 |=(% style="width: 239px;" %)**Address**|=(% style="width: 1250px;" %)**Description**
2072 |(% style="width:239px" %)0 bit|(% style="width:1250px" %)Set ON, Server configured in [Project Settings] fails
2073 |(% style="width:239px" %)1^^st^^bit|(% style="width:1250px" %)Set ON, Server 1 fails
2074 |(% style="width:239px" %)2^^nd^^bit|(% style="width:1250px" %)Set ON, Server 2 fails
2075 |(% style="width:239px" %)3^^rd^^~~ 10^^th^^bits|(% style="width:1250px" %)Reserved
2076 |(% style="width:239px" %)11^^th^^bit|(% style="width:1250px" %)Set ON, network error, network port interface failure
2077
2078 **A3:**Returns the preferred server number or network status (automatically selects the server with the best connection network status).
2079
2080 * =0: Server configured in [Project Settings];
2081 * =1: Server 1;
2082 * =2: Server 2;
2083 * =3~~10: Reserved;
2084 * =100: Try again later (two test intervals need to wait 30 seconds);
2085 * =101: Failed to test Server;
2086
2087 **Example**
2088
2089 //{{code language="lua"}}@W_HDW200 = GetServerDelayInfo("@W_HDW100", "@W_HDW50"){{/code}}//
2090
2091 Result:
2092
2093 * HDW100: Delay data of the server configured in [Project Settings]
2094 * HDW101: Delay data of Server 1
2095 * HDW102: Delay data of Server 2
2096 * HDX50.0=1:Server configured in [Project Settings] fails
2097 * HDX50.1=1: Server 1 fails
2098 * HDX50.2=1:Server 2 fails;
2099 * HDX50.11= 1: network error, network port interface failure;
2100
2101 When the server signal is stable, the optimal server is automatically connected according to the network status @W_HDW200. When the server connection is abnormal, @W_HDW200=101, the server test fails or the test is abnormal.
2102
2103 (% class="box infomessage" %)
2104 (((
2105 **✎Note:** The time interval between executions of this function could not be less than 30 seconds, otherwise an error will occur.
2106 )))
2107
2108 == **Goto** ==
2109
2110 **Function**
2111
2112 Goto label
2113
2114 **Description**
2115
2116 Go to the designated row without any condition in a function body.
2117
2118 **Parameters**
2119
2120 * **Label:** target character, start with letter in row label, end with(:)of any string.row label has no sensitive to the format of letter.
2121
2122 **Example**
2123
2124 //Goto sd 'go to the row which start with "sd";//
2125
2126 **Result:** Go to sd row.
2127
2128 (% class="box infomessage" %)
2129 (((
2130 **✎Note:** Goto only can jump into the internal function that visible row.
2131 )))
2132
2133 == **H2A** ==
2134
2135 **Function**
2136
2137 A1 = H2A (A2)
2138
2139 **Description**
2140
2141 Convert a binary (16-bit) to hexadecimals (4-bit) of ASCII.
2142
2143 **Parameters**
2144
2145 * **A1: **Returned value, string, it could be an address or variable.
2146 * **A2: **Binary is needed to be converted, the value could be a address or variable.
2147
2148 **Example**
2149
2150 //{{code language="lua"}}@W_HDW100= H2A (@W_HDW0) ' convert the binary of (HDW0) to character and save in (HDW100).{{/code}}//
2151
2152 **Result:**
2153
2154 * HDW0=200,
2155 * HDW=100
2156
2157 == **HmiRegoperator** ==
2158
2159 **Function**
2160
2161 HmiRegoperator (A1,A2,A3,A4,A5,A6)
2162
2163 **Description**
2164
2165 Data of Upload/ Download address
2166
2167 **Parameters**
2168
2169 * **A1: **The start address of target
2170 * **A2: **Length, address length, unit: word, range: 1~~1000
2171 * **A3: s**torage
2172 ** A3=0, select USB flash disk as storage, and save files in Root directory;
2173 ** A3=1, select SD card as storage, and save files in Root directory;
2174 * **A4: **File name address, itneed to be address such as"@ W_HDW2"
2175 * **A5**: Upload / download data
2176 ** A5=0, save the data in the specified address as a file and store the file in the root directory;
2177 ** A5=1, Read data from file and it woule be written into specified address;
2178 * **A6:** State display, it needs to be address, such as "@ W_HDW2";
2179 ** A6=1, Normal
2180 ** A6=2, USB flash disk/ SD card does not exist
2181 ** A6=3, File doesn’t exist;
2182 ** A6=4, File name error;
2183 ** A6=5, Check error
2184 ** A6=6, Abnormal communication;
2185 ** A6=7, HUW register is not allowed;
2186 ** A6=8, Address length range error (address length range: 1-1000);
2187
2188 **Example**
2189
2190 Script 1
2191
2192 (% class="box" %)
2193 (((
2194 //HmiRegoperator("@W_HDW0",10,0,"@W_HDW2000",0,"@W_HDW3000")’The data in HDW0-HDW10 is saved as a file, the file name is set by HDW2000 and stored in a USB flash disk.//
2195 )))
2196
2197 Script 2
2198
2199 (% class="box" %)
2200 (((
2201 //HmiRegoperator("@W_HDW0",10,1,"@W_HDW2000",1,"@W_HDW3000")//
2202
2203 //Read the values from files which stored in the SD card (files named by the HDW2000), and write these values to the HDW0-HDW10.//
2204 )))
2205
2206 **✎Note:**
2207
2208 * The length of the file name is less than 32 characters, and the file name consists of numbers and letters (the file name does not meet this standard; WECON does not guarantee the accuracy of the data).
2209 * The interval of download function operation should be 5s or more.
2210 * A1 need to be address such as “@W_HDW2”.
2211 * Please use “Character Input/Display” object for it, and the file name consists of numbers and letters, could not be punctuated characters, maximum character length 32 allowed.
2212
2213 == **Hypot** ==
2214
2215 **Function**
2216
2217 Var = Hypot (expr1, expr2)
2218
2219 **Description**
2220
2221 Calculate the value of the hypotenuse of a right triangle.
2222
2223 **Parameters**
2224
2225 * **expr1, expr2: **Source data, the two sides of right triangle. it need to be address;
2226 * **Var:** Destination data,it need to be address;
2227
2228 **Example**
2229
2230 (% class="box" %)
2231 (((
2232 //@W_HDW200=Hypot (@W_HDW105,@W_HDW108) ' input the value of right-angle side at (HDW105) and (HDW108),and assign the result of the hypotenuse to (HDW200).//
2233 )))
2234
2235 **Result: **
2236
2237 * HDW105=3,
2238 * HDW108=4,
2239 * HDW200=5
2240
2241 (% class="box infomessage" %)
2242 (((
2243 **✎Note:** hypot function could support integer and floating when the format of source data and target data are the same.
2244 )))
2245
2246 == **IF ... THEN ... ELSE ... END IF** ==
2247
2248 **Function**
2249
2250 If condition Then
2251
2252 Statements
2253
2254 [Else
2255
2256 else statements]
2257
2258 End If
2259
2260 **Description**
2261
2262 Conditional judgments instruction. When the [Condition] defined by [IF] is TURN, the operation following [THEN] is performed. When [Condition] is FALSE, the operation after [ELSE] is executed.
2263
2264 **Parameters**
2265
2266 * **condition: **any expression, the value could be true or false.
2267 * **statement: **execute the instruction block when condition is true.
2268 * **else statement: **execute the instruction block when condition is false.
2269
2270 **Example**
2271
2272 {{code language="lua"}}
2273 if @W_HDW105=200 then ' judging condition: whether the value of (HDW105) is 200
2274
2275 @W_HDW108=1 'the value of (HDW108) is 1 if fulfil condition
2276
2277 else
2278
2279 @W_HDW200=1 ' the value of (HDW200) is 1 if not fulfil condition.
2280
2281 Endif
2282 {{/code}}
2283
2284 **Result:**
2285
2286 * HDW105=199;
2287 * HDW108=0;
2288 * HDW200=1
2289
2290 == **InStr** ==
2291
2292 **Function**
2293
2294 var = InStr ("str1", "str2")
2295
2296 **Description**
2297
2298 Returned the position of str1 in str2(start with 0), set -1 if no result.
2299
2300 **Parameters**
2301
2302 * **str1:** source string, it could only be string, not address;
2303 * **str2:** target string, it could only be string, not address;
2304 * **var:** Returned value, the format of data needs to be string;
2305
2306 **Example**
2307
2308 {{code language="lua"}}
2309 dim a as floating
2310
2311 a = InStr ("Hello", "o") ' calculate the position of"o"in"hello".
2312
2313 float2d ("@W_HDW0",a) ' Returned value is 4.(start with 0)
2314 {{/code}}
2315
2316 **Result:** HDW0=4
2317
2318 == **Int2D** ==
2319
2320 **Function**
2321
2322 Int2D("A1",A2)
2323
2324 **Description**
2325
2326 Write the 32-bit integer into the target address
2327
2328 **Parameters**
2329
2330 * **A1: **Source data could only be the HMI internal or external register starting with "@".
2331 * **A2:** Target data could only use the integer variable defined by script.
2332
2333 **Example**
2334
2335 {{code language="lua"}}
2336 dim var1 as integer 'define var1 as integer
2337
2338 Int2D("@W_HDW0", var1)    'Read out the 32-bit integer in var1 and save the result in HDW0 .
2339
2340  var1=9999999,
2341 {{/code}}
2342
2343 **Result:** HDW0=9999999.
2344
2345 == **InvB** ==
2346
2347 **Function**
2348
2349 InvB (A1)
2350
2351 **Description**
2352
2353 The state of inverse bit, it is a sub function, no returned value. Achieve the state of switching address constantly.
2354
2355 **Parameters**
2356
2357 * **A1:** it is an address.
2358
2359 **Example**
2360
2361 //{{code language="lua"}}InvB (@B_HDX0.1) 'switch the state if (HDX0.1).{{/code}}//
2362
2363 **Result: **Switch the state of (HDX0.1) constantly.
2364
2365 == **IsFloating** ==
2366
2367 **Function**
2368
2369 A2=IsFloating (A1)
2370
2371 **Description**
2372
2373 Decide whether a parameter is floating, return true if it is floating, otherwise return FALSE.
2374
2375 **Parameter**
2376
2377 * **A1:** source data, variable;
2378 * **A2:** target data, variable;
2379
2380 **Example**
2381
2382 {{code language="lua"}}
2383 dim a as integer
2384
2385 dim b as floating
2386
2387 b= D2float ("@W_HDW200",b) 'assign the value of (HDW200) to b
2388
2389 a = IsFloating (b) 'judge whether b is floating or not
2390
2391 @W_HDW300=a 'save the result to (HDW300)
2392 {{/code}}
2393
2394 **Result: **HDW300=1
2395
2396 == **IsInteger** ==
2397
2398 **Function**
2399
2400 A2= IsInteger (A1)
2401
2402 **Description**
2403
2404 Determine whether a parameter(A1) is integer, return TRUE if the parameter is integer, otherwise return FALSE.
2405
2406 **Parameter**
2407
2408 * **A1:** Source date, it is variable or number;
2409 * **A2:** Target date, need to be variable, it could not be system address ;
2410
2411 **Example**
2412
2413 {{code language="lua"}}
2414 dim a as integer
2415
2416 a = IsInteger (20) 'determine whether 20 is integer
2417
2418 @W_HDW300=a ' display the result on (HDW300)
2419 {{/code}}
2420
2421 **Result:** HDW300=1
2422
2423 == **IsString** ==
2424
2425 **Function**
2426
2427 val = IsString(expr)
2428
2429 **Description**
2430
2431 Determine whether a parameter is string, return TRUE if it is string, otherwise return FALSE.
2432
2433 **Parameters**
2434
2435 * **Expr:** source string, it could be a variable or string, not address;
2436 * **Val:** target date, the result need to be variable, could not be address;
2437
2438 **Example**
2439
2440 {{code language="lua"}}
2441 dim a as integer 'define variable, display the result;
2442
2443 a= isstring ("hello") 'determine whether"hello"is string;
2444
2445 @W_HDW0=a 'assign the result to (HDW0)
2446 {{/code}}
2447
2448 **Result: **HDW=1
2449
2450 == **Lcase** ==
2451
2452 **Function**
2453
2454 A2 = LCase(A1)
2455
2456 **Description**
2457
2458 Convert all parameters to lowercase strings.
2459
2460 **Parameters**
2461
2462 * **A1: **source string, it could be an address or variable;
2463 * **A2: **outputting string, it could be an address or variable;
2464
2465 **Example**
2466
2467 (% class="box" %)
2468 (((
2469 //@W_HDW33 = LCase (@W_HDW25) 'input source sting on (HDW25), convert it to destination string and display the result on (HDW33);//
2470 )))
2471
2472 **Result:** HDW25=HELLO
2473
2474 HDW33=hello
2475
2476 == **Left** ==
2477
2478 **Function**
2479
2480 Val =Left (String, Length)
2481
2482 **Description**
2483
2484 Return a string of the specified length from the left side of parameter.
2485
2486 **Parameters**
2487
2488 * **String:** source string; it could be an address or string.
2489 * **Length: **return the number of character. It could be an address, integer or variable. Return empty string if length<1. return the whole string if length not less than the character number of string.
2490 * **Val: **destination string, outputting string, it could be an address or variable.
2491
2492 **Example**
2493
2494 (% class="box" %)
2495 (((
2496 //@W_HDW30=Left (@W_HDW36, @W_HDW40) '(HDW36) used to input source string,(HDW30) used to display the string result;//
2497 )))
2498
2499 Result:
2500
2501 * HDW36=hello,
2502 * HDW40=2,
2503 * HDW30=he
2504
2505 == **Len** ==
2506
2507 **Function**
2508
2509 Length=Len(String)
2510
2511 **Description**
2512
2513 Return the string length.
2514
2515 **Parameters**
2516
2517 * **String:** source string, it could be a address or string;
2518 * **Length:** target data, return value, it could be a address, variable, integer or floating;
2519
2520 **Example**
2521
2522 //{{code language="lua"}}@W_HDW30=Len (@W_HDW36) 'count the character number of (HDW36), save the result to (HDW30);{{/code}}//
2523
2524 **Result:**
2525
2526 * HDW36=hello
2527 * HDW30=5
2528
2529 == **Log** ==
2530
2531 **Function**
2532
2533 a= Logn (x)=Log(x)/Log(n)
2534
2535 **Description**
2536
2537 Log function:return the natural logarithm of the value.
2538
2539 **Parameters**
2540
2541 * **a: **source date,it could be a variable, but it could not be address;
2542 * **x, n:** source date, it could be a variable, but it could not be address;
2543
2544 **Example**
2545
2546 {{code language="lua"}}
2547 Dim a as integer 'define a as integer;
2548
2549 Dim b as integer 'define b as integer;
2550
2551 Dim c as integer 'define c as integer;
2552
2553 b=@W_HDW10 'assigns a value to b
2554
2555 c=@W_HDW20 'assigns a value to c
2556
2557 a=Log (b)/Log(c) 'calculate logarithm
2558
2559 @W_HDW0
2560
2561 =a 'assign the result to (HDW0)
2562 {{/code}}
2563
2564 **Result:**
2565
2566 * HDW10=27,
2567 * HDW20=3,
2568 * HDW0=3
2569
2570 == **Log10** ==
2571
2572 **Function**
2573
2574 a=Log10(x)= Log(x) / Log(10)
2575
2576 **Description**
2577
2578 Log function: return the natural logarithm.
2579
2580 **Parameters**
2581
2582 * **A:** target data, result could be variable, could not be address;
2583 * **x:** source data, it could be variable that needs to be the multiples of 10, can’t be address
2584
2585 **Example**
2586
2587 {{code language="lua"}}
2588 dim a as integer 'define a as integer
2589
2590 dim b as integer 'define b as integer
2591
2592 b=@W_HDW10 'assign a value to b
2593
2594 a= Log (b)/Log(10) 'result
2595
2596 @W_HDW0=a 'assign the result to (HDW0)
2597 {{/code}}
2598
2599 **Result: **
2600
2601 * HDW10=100,
2602 * HDW0=2
2603
2604 == **LTrim** ==
2605
2606 **Function**
2607
2608 val=LTrim("string")
2609
2610 **Description**
2611
2612 Remove the left empty part of the string and return.
2613
2614 **Parameters**
2615
2616 * **Val:** Destination string, it could be either a variable or address;
2617 * **string:** Source string, it could be either a variable or address;
2618
2619 **Example**
2620
2621 {{code language="lua"}}
2622 dim a as string
2623
2624 a=Ltrim("hello")
2625
2626 @W_HDW103=a
2627 {{/code}}
2628
2629 **Result:** HDW103=hello
2630
2631 == **MAX** ==
2632
2633 **Function**
2634
2635 A1=MAX(A2,A3)
2636
2637 **Description**
2638
2639 Compare the value of A2 and A3, assign the greater value to A1.
2640
2641 **Parameters**
2642
2643 * **A1:** Return value (used to store the greater value between A2 with A3).
2644 * **A2:** The first comparison value.
2645 * **A3:** The second comparison value.
2646
2647 (% class="box infomessage" %)
2648 (((
2649 **✎Note:** A1,A2,A3 should be only used in unsigned integer or unsigned address.
2650 )))
2651
2652 **Example**
2653
2654 {{code language="lua"}}
2655 DIM A1 as integer
2656
2657 @W_HDW106=10 'assign the value to (@W_HDW106), unsigned decimal word.
2658
2659 @W_HDW107=5 'assign the value to (?@W_HDW107),unsigned decimal word.
2660
2661 A1 = Max(@W_HDW106,@W_HDW107)
2662
2663 @W_HDW105 = A1
2664 {{/code}}
2665
2666 **Result: **@W_HDW105 = 10
2667
2668 == **Mid** ==
2669
2670 **Function**
2671
2672 A1=mid(A2, start, length)
2673
2674 **Description**
2675
2676 Returns a string contain a specified characters length from a string.
2677
2678 **Parameters**
2679
2680 * **A1:** string contains the selected characters, it needs to be a string
2681 * **A2:** string to be selected, it needs to be a variable or address
2682 * **Start:** the start position of string, it needs to be a variable or address, it means that count begin with 0.
2683 * **Length:** the designated length of string, maximum character length 127 allowed
2684
2685 **Example**
2686
2687 {{code language="lua"}}
2688 DIM A1 as string
2689
2690 A1 = Mid("hellokitty",1,2) 'select the string of in "
2691
2692 @W_HDW106=A1
2693 {{/code}}
2694
2695 **Result: **@W_HDW106 'display "el" on text input and output window
2696
2697 == **MIN** ==
2698
2699 **Function**
2700
2701 A1=MIN(A2,A3)
2702
2703 **Description**
2704
2705 Compare the value of A2 and A3, assign the smaller value to A1.
2706
2707 **Parameters**
2708
2709 * **A1: **Return value (used to store the snaker value between A2 with A3).
2710 * **A2: **The first comparison value.
2711 * **A3: **The second comparison value.
2712
2713 **Example**
2714
2715 {{code language="lua"}}
2716 DIM A1 as integer
2717
2718 @W_HDW106=10 'assign the value to (@W_HDW106), unsigned decimal word.
2719
2720 @W_HDW107=5 'assign the value to (@W_HDW107), unsigned decimal word.
2721
2722 A1 = Min(@W_HDW106,@W_HDW107)
2723
2724 @W_HDW105 = A1
2725 {{/code}}
2726
2727 **Result:** @W_HDW105 = 5
2728
2729 **✎Note:** A1, A2,A3 only used in unsigned integer or unsigned address.
2730
2731 == **MSeconds** ==
2732
2733 **Function**
2734
2735 A1=MSeconds( )
2736
2737 **Description**
2738
2739 A1 is used to display the current milliseconds of system.
2740
2741 **Parameters**
2742
2743 * **A1: **used to store the current milliseconds of system.
2744
2745 **Example**
2746
2747 {{code language="lua"}}
2748 DIM A1 as integer
2749
2750 @W_HDW0= 10 'assign a value to (@W_HDW0), unsigned decimal word
2751
2752 A1=MSeconds() 'return the current milliseconds of system to A1
2753
2754 @W_HDW0=A1
2755
2756 @W_HDW1=A1>>16 'display milliseconds on screen, (HDW0) is an 32-bit unsigned decimal integer address
2757 {{/code}}
2758
2759 **Result:** @W_HDW0 will generate the time value of changing milliseconds unit.
2760
2761 (% class="box infomessage" %)
2762 (((
2763 **✎Note:**
2764
2765 * A1 is 32-bit unsigned integer variable or unsigned integer address;
2766 * MSeconds() function rolls back over to zero once the maximum value has been reached (4294967295->0, 1,2,....4294967295->0, 1, 2,....4294967295->0, 1, 2);
2767 )))
2768
2769 == **MyDeleteFile** ==
2770
2771 **Function**
2772
2773 MyDeleteFile (A1,A2,A3,A4,A5)
2774
2775 **Description**
2776
2777 Delete the specified file
2778
2779 **Parameters**
2780
2781 A1: File location (value is an integer);
2782
2783 In HMI:
2784
2785 * =0: Recipe folder in HMI flash;
2786 * =1: Custom folder in UDisk (USB flash disk);
2787 * = 2: Custom folder in SD card.
2788 * =3: Custom folder in HMI flash;
2789
2790 In simulator:
2791
2792 * = 0: D:/Recipe/
2793 * = 1: C:/WECON/CustomFileDir/
2794 * = 2: C:/WECON/CustomFileDir/
2795 * = 3: C:/WECON/CustomFileDir/
2796
2797 **✎Note:**
2798
2799 A1 can be an address, variable or value.
2800
2801 A2: filename (value is string);
2802
2803 Input the name of the file want to delete.
2804
2805 **✎Note: **
2806
2807 A2 can be an address , variable or a character string, and the length of the file name cannot exceed 32 characters.
2808
2809 A3: folder name (value is integer);
2810
2811 Input the folder where the file want to delete.
2812
2813 **✎Note: **
2814
2815 A3 can be an address , variable or a character string, and the length of the folder name cannot exceed 32 characters.
2816
2817 A4: Delete function type (value is integer)
2818
2819 * = 0: Delete the specified file.
2820 * = 1: Delete all files.
2821
2822 **✎Note: **
2823
2824 A4 can be an address , variable or value.
2825
2826 A5: Return value (value is an integer)
2827
2828 * = 0: parameter error
2829 * = 1: Delete successfully
2830 * = 2: Delete failed
2831 * = 3: Failed to open file
2832
2833 **✎Note:** A5 must be an address.
2834
2835 **Example**
2836
2837 (% class="box" %)
2838 (((
2839 MyDeleteFile(@W_HDW1254,@W_HDW4200,@W_HDW4300,@W_HDW1250,"@W_HDW1252")
2840
2841 ‘According to the value of @W_HDW1250, delete the designated file @W_HDW4200 in the folder @W_HDW4300 or delete all files in the folder @W_HDW4300.
2842 )))
2843
2844 == **NewNoAddr** ==
2845
2846 **Function**
2847
2848 A1= NewNoAddr (A2, length)
2849
2850 **Description**
2851
2852 At the basic of source address A2, offset designated length, obtain a new address A1.
2853
2854 **Parameters**
2855
2856 * **A1: **address after offsetting, it must be String type variable.
2857 * **A2:** source address, it must be an address(e.g.:"@W_HDW2")
2858 * **Length: **offset length, it must be a constant or an integer variable.
2859
2860 **Example**
2861
2862 {{code language="lua"}}
2863 DIM A1 as string
2864
2865 A1=NewNoAddr("@W_HDW0",50) '(HDW0) offsets 50 words address (16 bit), and save the result to A1
2866
2867 @W_HDW1=A1 '(HDW50) save in A1
2868 {{/code}}
2869
2870 **Result: **(@W_HDW1) character input/display will show @W_HDW50
2871
2872 == **NewStatAddr** ==
2873
2874 **Function**
2875
2876 A1= NewStatAddr (A2, length)
2877
2878 **Description**
2879
2880 At the basic of source address A2, offset the designated length, to obtain a new station A1.
2881
2882 **Parameters**
2883
2884 * **A1: **The address after offsetting, it needs to be variable.
2885 * **A2:** Source station address, it needs to be address (e.g.:"@W_1:10").
2886 * **Length: **offset length
2887
2888 **Example**
2889
2890 {{code language="lua"}}
2891 DIM A1 as string
2892
2893 A1=NewStatAddr("@W_1:10",2) 'address 10 of station address 1 that offset 2 station addresses, then save the result to A1
2894
2895 @W_HDW1=A1 'address 3:10 is saved in A1
2896 {{/code}}
2897
2898 **Result: **@W_HDW1 character input/display will show @W_3:10
2899
2900 == **NStringCompare** ==
2901
2902 **Function**
2903
2904 A1= NStringCompare (A2, A3, length)
2905
2906 **Description**
2907
2908 Compare whether the designated length of two strings is the same, return 1 to A1 if yes, otherwise return 0.
2909
2910 **Parameters**
2911
2912 * **A1: **Returned value (compare the designated length of two strings, display 1 when equal, else 0). It could be an address or variable.
2913 * **A2: **the address of string to be compared, it needs to be address.
2914 * **A3: **source string, it needs to be variable or constant string.
2915 * **Length: **string length to be compared
2916
2917 **Example**
2918
2919 {{code language="lua"}}
2920 @W_HDW1= NStringCompare("@W_HDW0","87654",5)
2921
2922 if @W_HDW1=1 then
2923
2924 @B_HDX10.0=1 'result: HDX10.0 set ON 'when the two strings are the same.
2925
2926 endif
2927
2928 if @W_HDW1=0 then
2929
2930 @B_HDX10.0=0 'result:HDX10.0 set OFF 'when not equal.
2931
2932 Endif
2933 {{/code}}
2934
2935 == **Operator** ==
2936
2937 (% class="table-bordered" %)
2938 |=(% scope="row" %)**Operation**|=**Symbol**|=**Example**|=**Return type**
2939 |=Addition|+|A1=A2+A3|Return type depending on the type of variable or address of the addition
2940 |=Subtraction|-|A1=A2-A3|Return type depending on the type of variable or address of the subtraction
2941 |=Multiplication|*|A1=A2*A3|Return type depending on the type of variable or address of the multiplication
2942 |=Division|/|A1=A2/A3|Return type depending on the type of variable or address of the division
2943 |=Remainder|Mod ~(%)|(((
2944 A1=A2 mod A3
2945
2946 A1=A2%A3
2947 )))|Returns the remainder of the division of two numbers. The type of the return value is an integer
2948 |=Logical OR|Or(~|)|(((
2949 A1=A2 or A3
2950
2951 A1=A2|A3
2952 )))|Returns the result of a logical OR. The type of the return value is an integer.
2953 |=Logic AND|And (&)|(((
2954 A1=A2 and A3
2955
2956 A1=A2&A3
2957 )))|Returns the result of a logical AND. The type of the return value is an integer.
2958 |=Logical XOR|Xor (^)|(((
2959 A1=A2 xor A3
2960
2961 A1=A2^A3
2962 )))|Returns the result of a logical XOR. The type of the return value is an integer.
2963 |=Logical reversal|Not (!)|(((
2964 A1=not A1
2965
2966 A1=A2!A3
2967 )))|Returns the result of a logical reversal. The type of the return value is an integer.
2968 |=Left shift|<<|A1=A2<<A3|Shift the value of A2 to the left by A3 digits and return the displacement result. The type of the return value is an integer.
2969 |=Right shift|>>|A1=A2>>A3|Shift the value of A2 to the right by A3 digits and return the displacement result. The type of the return value is an integer.
2970 |=Bit reversal|~~|A1=~~A1|Perform a bit reversal on a value. The type of the return value is an integer.
2971
2972 == **PI_GetTickCount** ==
2973
2974 **Function**
2975
2976 PI_GetTickCount (A1, A2)
2977
2978 **Description**
2979
2980 Writethe startingtime tothe set address asa 32-bit integer.
2981
2982 **Parameters**
2983
2984 * **A1: **Source data could only be the HMI internal or external register starting with "@".
2985 * **A2: **=0: Unit of time for returning 0ms;(the value will become 0 after 49.7 days and so on)
2986 ** =1: Unit of time for returning 10 ms;(the value will become 0 after 497 days and so on)
2987 ** =2: Unit of time for returning 100 ms;(the value will become 0 after 4970 days and so on)
2988 ** =3: Unit of time for returning 1000ms;(the value will become 0 after 49700 days and so on)
2989
2990 (% class="box infomessage" %)
2991 (((
2992 **✎Note: **If user restarts the hmi,all value will be 0.
2993 )))
2994
2995 **Example**
2996
2997 (% class="box" %)
2998 (((
2999 //PI_GetTickCount("@W_HDW100",0)'save the starting time in HDW100 address as a 32-bit integer.//
3000 )))
3001
3002 **Result: **HDW100=123456(different returned data for each moment)
3003
3004 == **Power** ==
3005
3006 **Function**
3007
3008 var = power (expr1, expr2)
3009
3010 **Description**
3011
3012 The value of [expr2] to the power of [expr1] will be assigned to Var.
3013
3014 **Parameters**
3015
3016 * **var:** returned value.
3017 * **expr 1:** base number.
3018 * **expr 2:** power number.
3019
3020 **Example**
3021
3022 {{code language="lua"}}
3023 Dim a as floating
3024
3025 a=power (2, 3) 'the value of 3 to the power of 2 is assigned to a.
3026
3027 Float2D("@W_HDW10",a) 'assign the float value of a to @W_HDW10
3028 {{/code}}
3029
3030 **Result: **@W_HDW10=8
3031
3032 == **PrintText** ==
3033
3034 **Function**
3035
3036 PrintText(A)
3037
3038 **Description**
3039
3040 Print the content of A or locates in A.
3041
3042 **Parameters**
3043
3044 **A:** source data. A could be a variable or a string ( text information),not a register address.
3045
3046 **Example**
3047
3048 A is text information
3049
3050 //PrintText("HMI 8070”)//
3051
3052 **Result: **Printer will print out “HMI 8070”
3053
3054 * A is variable
3055
3056 //Dim a as string//
3057
3058 //a= “HMI 8070”//
3059
3060 //PrintText(a)//
3061
3062 **Result:** Printer will print out “HMI 8070”
3063
3064 **✎Note:**
3065
3066 source data length range:1-128 characters.
3067
3068 == **RadToDeg** ==
3069
3070 **Function**
3071
3072 Var= RadToDeg(expr)
3073
3074 **Description**
3075
3076 Convert radiant value to degree, then assigned to Var.
3077
3078 **Parameters**
3079
3080 * **Var:** return degree value.
3081 * **expr:** input radiant value.
3082
3083 **Example**
3084
3085 {{code language="lua"}}
3086 Dim a as floating
3087
3088 a = RadToDeg(pi)           'assignt the degree value of ? to a.
3089
3090 Float2D("@W_HDW4",a) 'assign the degree value to address "@W_HDW4".
3091 {{/code}}
3092
3093 **Result:** @W_HDW4=180
3094
3095 == **RAND** ==
3096
3097 **Function**
3098
3099 Var = rand(expr1)
3100
3101 **Description**
3102
3103 Generate a random number.
3104
3105 **Parameter**
3106
3107 * **Var:** generated random number.
3108 * **Expr1:** the base number.
3109
3110 **Example**
3111
3112 (% class="box" %)
3113 (((
3114 //@W_HDW0=rand(@W_HDW0) 'Set the value of address@W_HDW0 as the base number to generate random number.//
3115 )))
3116
3117 **Result:** @W_HDW0 random number.
3118
3119 == **ReadAddr** ==
3120
3121 **Function**
3122
3123 Word = ReadAddr(A1)
3124
3125 **Description**
3126
3127 Assigned the red value from A1 to word.
3128
3129 **Parameter**
3130
3131 * **Word: **return value
3132
3133 **Example**
3134
3135 {{code language="lua"}}
3136 Dim word as integer
3137
3138 @W_HDW100=10
3139
3140 word = ReadAddr("@W_HDW100") 'Read the value of address @W_HDW100 and assign to word.
3141
3142 @W_HDW200=word
3143 {{/code}}
3144
3145 **Result:** @W_HDW200=10
3146
3147 == **ReadWordFormFile** ==
3148
3149 **Function**
3150
3151 ReadWordFormFile (A1, A2, A3, A4, A5, A6)
3152
3153 **Description**
3154
3155 Read data of specified length from specified file
3156
3157 **Parameters**
3158
3159 A1: File location (value is an integer);
3160
3161 In HMI:
3162
3163 * =0: Recipe folder in HMI flash;
3164 * =1: Custom folder in UDisk (USB flash disk);
3165 * = 2: Custom folder in SD card.
3166 * =3: Custom folder in HMI flash;
3167
3168 In simulator:
3169
3170 * = 0: D:/Recipe/
3171 * = 1: C:/WECON/CustomFileDir/
3172 * = 2: C:/WECON/CustomFileDir/
3173 * = 3: C:/WECON/CustomFileDir/
3174
3175 **✎Note:** A1 can be an address, variable or value.
3176
3177 A2: File name (value is a string);
3178
3179 Input the file name want to write.
3180
3181 **✎Note: **A2 must be an address, and the length of the file name cannot exceed 32 characters.
3182
3183 A3: Data start address (value is a string);
3184
3185 Input the data want to write
3186
3187 **✎Note: **A3 must be the address.
3188
3189 A4: Data length (value is an integer)
3190
3191 Set the length of the data to be written (unit:word)
3192
3193 **✎Note: **A4 can be an address , variable or value.
3194
3195 A5: Return value (value is an integer)
3196
3197 ~= 1: Successfully read
3198
3199 ~= 2: Failed to open the folder
3200
3201 ~= 3: Read address error
3202
3203 ~= 4: File reading error
3204
3205 **✎Note: **A5 must be an address.
3206
3207 A6: Folder name (value is a string);
3208
3209 Input the folder where to be written the file.
3210
3211 **✎Note:** A6 can be an address or a variable or a character string, and the length of the folder name cannot exceed 32 characters
3212
3213 **Example**
3214
3215 (% class="box" %)
3216 (((
3217 ReadWordFormFile(@W_HDW1254,"@W_HDW4200","@W_HDW2000",@W_HDW4000,"@W_HDW4100", @W_HDW4300)'Write the @W_HDW4000 words in the file @W_HDW4200 in the directory @W_HDW4300 into the address @W_HDW2000 specified location by @W_HDW1254
3218 )))
3219
3220 == **Right** ==
3221
3222 **Function**
3223
3224 val = Right (string, length)
3225
3226 **Description**
3227
3228 Return a string of the specified length from the right side of parameter.
3229
3230 **Parameter**
3231
3232 * **string: **the operated string.
3233 * **length:** the designated number of byte required to return, count from the right side.
3234
3235 **Example**
3236
3237 //@W_HDW103= Right("Hello", 3) 'return "llo"//
3238
3239 **Result: **@W_HDW103="llo"
3240
3241 == **RTrim** ==
3242
3243 **Function**
3244
3245 val = RTrim(str)
3246
3247 **Description**
3248
3249 Clear the empty part on the right side of string [str], then assign the empty part to val
3250
3251 **Parameter**
3252
3253 * **val: **returned value.
3254 * **str:** the string needs to be operated.
3255
3256 **Example**
3257
3258 (% class="box" %)
3259 (((
3260 //@W_HDW0 = RTrim("   -Hell  o-  ") 'retrun"   -Hell  o-"//
3261 )))
3262
3263 **Result:** @W_HDW0display "   -Hell  o-"
3264
3265 == **S2F** ==
3266
3267 **Function**
3268
3269 S2F (A1,A2,s1)
3270
3271 **Description**
3272
3273 S2F is used to translate the string stored in A1 to floating and store the floating number in A2 according to the data format shown in A2.
3274
3275 **Parameters**
3276
3277 * **A1:** initial data address, used to store the string data, it should be the internal address of HMI or external address that started with “@”,like @W_HDW0
3278 * **A2:** destination address, used to store the floating number data. It should be the internal address of HMI or external address that started with “@”,like @W_HDW0
3279 * **S1:** display format of target data, for example m.nf, m means the length of string is m, n means the decimal places, f is the format used to output single precision number. (Since the floating point number is up to 7 digits, the decimal point in the string is also a bit, so it is recommended that the length should not exceed 8 bits)
3280
3281 **Return value:** none
3282
3283 **Example**
3284
3285 (% class="box" %)
3286 (((
3287 The lengTh of string is 8
3288
3289 //@W_HDW0="12345.67"//'Assign the string “12345.67" to HDW1
3290
3291 //S2F("@W_HDW0","@W_HDW100","8.2f") 'read string "12345.67 "from HDW0and convert it into a floating point with 2 decimal places, store in the HDW100//
3292 )))
3293
3294 **Result: **@W_HDW100 address displays “12345.67”.
3295
3296 (% class="box" %)
3297 (((
3298 The length of string is less than 8
3299
3300 //@W_HDW0="1234.5 67"‘assign the string“1234.567”to HDW1//
3301
3302 //S2F("@W_HDW0","@W_HDW100","6.2f") ' read string "1234 .5"from HDW0and convert it into a floating point with 2 decimal places, store in the HDW100 .//
3303 )))
3304
3305 **Result: **the floating value of @W_HDW100 is 1234.50
3306
3307 (% class="box" %)
3308 (((
3309 The length of string is more than 8
3310
3311 //@W_HDW0="12345.6789"’assign the string “12345.6789” to HDW1//
3312
3313 //S2F("@W_HDW0","@W_HDW100","8.2f") ' read string "12345 .67" from HDW0 and convert it into a floating point with 2 decimal places, store in the HDW100 .//
3314 )))
3315
3316 **Result: **the floating value of @W_HDW100 is 12345.67
3317
3318 == **SetB** ==
3319
3320 **Function**
3321
3322 SetB(A1)
3323
3324 **Description**
3325
3326 Set the bit A1 ON.
3327
3328 **Parameters**
3329
3330 * **A1:**Bit address
3331
3332 **Example**
3333
3334 (% class="box" %)
3335 (((
3336 //SetB(@B_HDX100.0) 'Set the address {@B_HDX100.0} ON//
3337 )))
3338
3339 **Result: **@B_HDX100.0=1
3340
3341 == **SetKeyMap** ==
3342
3343 **Function**
3344
3345 SetKeyMap(A1,A2,A3)
3346
3347 **Description**
3348
3349 The key values of the keyboard are mapped so that multiple keyboard buttons perform the same function.
3350
3351 **Parameters**
3352
3353 * **A1:** The starting address of the source key;It needs to be an address format;
3354 * **A2: **The starting address of the mapped value; It needs to be an address format;
3355 * **A3: **Mapping length (continuous length of mapped address); It needs to be a value, the maximum mapping range: 108 key values;
3356
3357 **Example**
3358
3359 (% class="box" %)
3360 (((
3361 //@W_HDW3000 = 3 ' The starting address of the source key//
3362
3363 //@W_HDW3001 = 5//
3364
3365 //@W_HDW3002 = 7//
3366
3367 //@W_HDW3003 = 9//
3368
3369 //@W_HDW3004 = 61//
3370
3371 //@W_HDW4100 = 103 'The starting address of the mapped value//
3372
3373 //@W_HDW4101 = 105//
3374
3375 //@W_HDW4102 = 106//
3376
3377 //@W_HDW4103 = 108//
3378
3379 //@W_HDW4104 = 28//
3380
3381 //SetKeyMap("@W_HDW3000","@W_HDW4100",5) ' Map the values of the HDW4000~~HDW4004 addresses to the HDW3000~~HDW3004 addresses.//
3382 )))
3383
3384 **Result**
3385
3386 Map the value of the HDW4000~~HDW4004 address (mapped to 103 105 106 108 28) to the value of the HDW3000~~HDW3004 address (source key value 3 5 7 9 61)
3387
3388 Button 2 (key value 3) is mapped to the direction key (key value is 103), button 4 (key value 5) is mapped to the left arrow key (key value is 105), and so on. When using the keyboard, the function of input 2 could be performed on both the button 2 and the direction button.
3389
3390 == **SignedInt16** ==
3391
3392 **Function**
3393
3394 val = SignedInt16(A1)
3395
3396 **Description**
3397
3398 Assign the value to {val} from address A1 which is signed integer.
3399
3400 **Parameters**
3401
3402 * **A1: **contain signed integer as "@W_HDW000002"
3403 * **Val: **returned value
3404
3405 **Example**
3406
3407 {{code language="lua"}}
3408 Dim a as integer 'Integer variable a
3409
3410 a = SignedInt16("@W_HDW0") 'read signed integer from HDW0 addresses and assign the value to a
3411
3412 @W_HDW2=a'assign the value a to HDW2
3413 {{/code}}
3414
3415 **Input: **@W_HDW0=-2:
3416
3417 **Result:** @W_HDW2=-2.
3418
3419 == **SignedInt32** ==
3420
3421 **Function**
3422
3423 val = SignedInt32 (A1)
3424
3425 **Description**
3426
3427 Assign the value to {val} from address A1 which is signed even integer.
3428
3429 **Parameters**
3430
3431 * **A1: **the address contains signed even integer
3432 * **Val:** Returned value
3433
3434 **Example**
3435
3436 {{code language="lua"}}
3437 Dim a as integer 'define {a} as a integer
3438
3439 a = SignedInt32("@W_HDW0") 'read signed even integer from HDW0, then assign this value to a.
3440
3441 @W_HDW2=a 'assign the value of a to HDW2
3442
3443 @W_HDW3=a>>16
3444 {{/code}}
3445
3446 **Input: **@W_HDW0=-2
3447
3448 **Result:**
3449
3450 * @W_HDW2=-2
3451 * @W_HDW13=-1
3452
3453 == **Sin** ==
3454
3455 **Function**
3456
3457 val = Sin(A1)
3458
3459 **Description**
3460
3461 Get the sine value of A1, and copy result to val.
3462
3463 **Parameters**
3464
3465 * **A1: **A1 needs to be an angle.
3466 * **Val: **Returned value.
3467
3468 **Example**
3469
3470 {{code language="lua"}}
3471 Dim a as floating 'floating variable a,b
3472
3473 a=sin(pi/6) 'return sinb to a
3474
3475 Float2D("@W_HDW13",a) 'assign the value of the floating variable a to address HDW13.
3476 {{/code}}
3477
3478 **Result:** @W_HDW13=0.5
3479
3480 == **SleepA** ==
3481
3482 **Function**
3483
3484 SleepA(T)
3485
3486 **Description**
3487
3488 Wait time T(ms).
3489
3490 **Parameters**
3491
3492 * **T:** wait time, the unit is [ms]
3493
3494 **Returned value:** none.
3495
3496 **Example**
3497
3498 (% class="box" %)
3499 (((
3500 //SleepA(10) 'wait 10ms//
3501 )))
3502
3503 **Result:** When the script runs to SleepA(10), it means the scripts would go running after waiting 10ms
3504
3505 == **Sqr** ==
3506
3507 **Function**
3508
3509 val = Sqr(A1)
3510
3511 **Description**
3512
3513 Assign a square root value of A1 to val.
3514
3515 **Parameters**
3516
3517 * **A1: **the data need to be operated
3518 * **Val: **Returned value
3519
3520 **Example**
3521
3522 (% class="box" %)
3523 (((
3524 //@W_HDW0 = Sqr(4) 'calculate the square root of HDW0//
3525 )))
3526
3527 **Result:** @W_HDW0=2
3528
3529 == **StAndFtChange** ==
3530
3531 **Function**
3532
3533 StAndFtChange(A1,A2,A3)
3534
3535 **Description**
3536
3537 Calculate the number of seconds from January 1, 1970 to the current time, and also be invertible.
3538
3539 **Parameters**
3540
3541 * **A1: **The start address of curren t time (Enter or output year, month, day, minute, and second); It needs to begin with address"@", and occupies 6 addresses;
3542 * **A2: **The number of seconds; It needs to begin with address “@", data format 32-bit unsigned.
3543 * **A3: **conversion method;
3544 ** A3=0, convert time to seconds;
3545 ** A3=1, convert seconds to time;
3546
3547 **Returned value: **none;
3548
3549 **Example**
3550
3551 Script 1
3552
3553 (% class="box" %)
3554 (((
3555 //StAndFtChange("@W_HDW10","@W_HDW20",0) // //‘use HDW10 as start address, and enter year, month, day, hour, minute, second. The script calculates the number of seconds from January 1, 1970 to the time of the entry, and stores the result in HDW20//
3556 )))
3557
3558 **Input: **HDW10 = 2017,HDW11 = 12, HDW12 = 9 , HDW13 = 15, HDW14 = 15, HDW15 = 0
3559
3560 **Output:** 1512832500
3561
3562 Script 2
3563
3564 (% class="box" %)
3565 (((
3566 //StAndFtChange("@W_HDW30","@W_HDW20",1) ‘read number of seconds from HDW20, and the script calculates the date time, and stores the result start from HDW30//
3567 )))
3568
3569 **Input:** 1512833760
3570
3571 **Output:** HDW30 = 2017, HDW31 = 12, HDW32 = 9, HDW33 = 15, HDW34 = 36, HDW35 = 0
3572
3573 == **Sub** ==
3574
3575 **Function**
3576
3577 Sub name (arglist)
3578
3579 statements
3580
3581 End Sub
3582
3583 **Description**
3584
3585 Declare the name, parameters and codes of the Sub (sub function)
3586
3587 **Parameters**
3588
3589 * **Name: **naming rules refer to variable.
3590 * **Arglist: **variable list.
3591 * **Statements:** the code set of the sub function.
3592
3593 **Example**
3594
3595 {{code language="lua"}}
3596 sub samesub(a,b as integer) ' samesub and integer variable a,b
3597
3598 c=a+b
3599
3600 @W_HDW0=c
3601
3602 endsub
3603
3604 samesub(1,12) 'call function samesub
3605 {{/code}}
3606
3607 **Result:** @W_HDW0=13
3608
3609 == **SWAP** ==
3610
3611 **Function**
3612
3613 SWAP(A1,length)
3614
3615 **Description**
3616
3617 Swap the big-endian with the little-endian from address A1, swap length is adjustable.
3618
3619 **Parameters**
3620
3621 * **A1: **the swapped high endian, need to be an address as HDW_000002.
3622 * **Length: **swap length.
3623
3624 **Returned value:** None.
3625
3626 **Example**
3627
3628 {{code language="lua"}}
3629 @W_HDW103=0x1234 'assign value to HDW103
3630
3631 @W_HDW104=0x2345 'assign value to HDW104
3632
3633 @W_HDW105=0x2565 'assign value to HDW105
3634
3635 @W_HDW106=0x2675 'assign value to HDW106
3636
3637 SWAP(@W_HDW103,4) 'swap the high and low endian for the 4 adjacent addresses start with HDW103.
3638 {{/code}}
3639
3640 **Result:**
3641
3642 * @W_HDW103=0x3412
3643 * @W_HDW104=0x4523
3644 * @W_HDW105=0x6525
3645 * @W_HDW106=0x7526
3646
3647 == **Tan** ==
3648
3649 **Function**
3650
3651 val = Tan(A1)
3652
3653 **Description**
3654
3655 Get the returned tagent value of A1, and then assign to val.
3656
3657 **Parameters**
3658
3659 * **A1: **A1 needs to be an angle.
3660 * **Val: **Returned value.
3661
3662 **Example**
3663
3664 {{code language="lua"}}
3665 Dim a as floating 'define a floating variable a
3666
3667 a=TAN(pi/3) 'calculate the tangent value of pi/3 and assign to a
3668
3669 Float2D("@W_HDW16",a) 'assign the value of a to HDW16
3670 {{/code}}
3671
3672 **Result:** @W_HDW13=1.732
3673
3674 == **Trim** ==
3675
3676 **Function**
3677
3678 val = Trim(A1)
3679
3680 **Description**
3681
3682 Return A string in A1 without empty string next to it.
3683
3684 **Parameters**
3685
3686 * **A1: **The operated string
3687 * **val: **Returned value
3688
3689 **Example**
3690
3691 //{{code language="lua"}}@W_HDW1=Trim(" ab "){{/code}}//
3692
3693 **Result: **@W_HDW1="ab"
3694
3695 == **UCase** ==
3696
3697 **Function**
3698
3699 val = UCase(A1)
3700
3701 **Description**
3702
3703 Capitalize the string data, and then assign the value to val.
3704
3705 **Parameters**
3706
3707 * **A1: **Operated string, address or variable.
3708 * **Val: **Returned value
3709
3710 **Example**
3711
3712 //{{code language="lua"}}@W_HDW1=ucase("abcd") 'Capitalize abcd then assign the value to HDW1{{/code}}//
3713
3714 **Result: **@W_HDW1="ABCD"
3715
3716 == **Variable** ==
3717
3718 **Description**
3719
3720 A variable is any factor, trait, or condition that could exist in differing amounts or types.
3721
3722 **Define variable**
3723
3724 Use Dim to define variable in script. The variable could be string, floating, integer.
3725
3726 **Example:**
3727
3728 {{code language="lua"}}
3729 Dim a as floating ‘define variable {a} as a floating.
3730
3731 Dim b,c,d as integer‘define variable {b,c,d} as integer
3732 {{/code}}
3733
3734 **Naming rules**
3735
3736 The first letter needs to be English letter.
3737
3738 No symbols.
3739
3740 Maximum character length 15 allowed.
3741
3742 == **W2B** ==
3743
3744 **Function**
3745
3746 W2B(A1, A2, A3)
3747
3748 **Description**
3749
3750 Replace the high endian of [A2]+1 with the high endian of A2.
3751
3752 **Parameters**
3753
3754 * **A1:** operated address.
3755 * **A2:** source address.
3756 * **A3: **the conversion length.
3757
3758 **Returned value:** none.
3759
3760 **Example**
3761
3762 {{code language="lua"}}
3763 @W_HDW0 = 4660 'assign 16bit value 1234 to HDW0.
3764
3765 @W_HDW1=0x5678 'assign 16bit value 5678 to HDW1.
3766
3767 @W_HDW2 = 0x2425 'assign 16bit value 2425 to HDW1.
3768
3769 @W_HDW3 = 0x3536 'assign 16bit value 3536 to HDW0.
3770
3771 @W_HDW4 = 0x1415 'assign 16bit value 1415 to HDW0.
3772
3773 W2B(@W_HDW20,@W_HDW0, @W_HDW10)
3774
3775 @W_HDW10=1 ‘save the high endian {34} of HDW0 to HDW20.
3776 {{/code}}
3777
3778 **Result:** @W_HDW20=0x34, @W_HDW21=0, @W_HDW22=0
3779
3780 == **W2D** ==
3781
3782 **Function**
3783
3784 W2D(A1, A2)
3785
3786 **Description**
3787
3788 Convert the unsigned Word to unsigned Dword and save the result in A1.
3789
3790 **Parameters**
3791
3792 * **A1: **operated address .
3793 * **A2:** source address.
3794
3795 Returned value.
3796
3797 **Example**
3798
3799 Unsigned decimal word
3800
3801 (% class="box" %)
3802 (((
3803 //@W_HDW0 = 1234 'assign 1234 to HDW0.//
3804
3805 //W2D(@W_HDW2, @W_HDW0) 'convert unsigned word {1234} from HDW0 to Dword and save in HDW2//
3806 )))
3807
3808 **Result:** @W_HDW0=12345, @W_HDW2=12345, @W_HDW3=0
3809
3810 Signed decimal word
3811
3812 (% class="box" %)
3813 (((
3814 //@W_HDW0 = -12345 'assign value to HDW0: convert {-12344} to unsigned decimal word is {53191}.//
3815
3816 //W2D(@W_HDW2, @W_HDW0) 'save unsigned Dword to HDW0//
3817 )))
3818
3819 **Result: **@W_HDW0=-12345,@W_HDW2=53191,@W_HDW3=0
3820
3821 == **W2F** ==
3822
3823 **Function**
3824
3825 A1 = W2F (A2)
3826
3827 **Description**
3828
3829 Convert a 16bit integer to a 32bit floating, and then save to the next word of A1.
3830
3831 Parameters
3832
3833 * **A1:** operated address.
3834 * **A2:** source address.
3835
3836 **Returned value:** none.
3837
3838 **Example**
3839
3840 A1, A2 are addresses
3841
3842 (% class="box" %)
3843 (((
3844 //@W_HDW0 = 1234 ' assign unsigned word {1234} HDW0 @W_HDW1=W 2F(@W_HDW0) ‘ Convert {1234} to a 32bit floating and then save to HDW1, HDW2.//
3845 )))
3846
3847 **Result: **@W_HDW1=1234'32bit floating
3848
3849 {{code language="lua"}}
3850 A1 is an address,A2 is variable
3851
3852 dim a as integer
3853
3854 a=134 'define a integer 134 to a,
3855
3856 @W_HDW2=W2F (a) 'convert to 32bit floating save to HDW1, HDW2.
3857 {{/code}}
3858
3859 **Result: **@W_HDW1=134' 32bit floating
3860
3861 == **W2S** ==
3862
3863 **Function**
3864
3865 W2S(A1,A2,S1)
3866
3867 **Description**
3868
3869 Convert integer word in address A1 text as S1 format, and then save to A2.
3870
3871 **Parameters**
3872
3873 * **A1:** operated address.
3874 * **A2:** source address.
3875 * **S1:** saving format.
3876 ** d format: Decimal format.d: Real data length.Md: Designated data length. 0md: Designated data length if the length is shorter than m adds 0 at the left.
3877 ** format: Unsigned octal format. Mo and 0mo is also applied.
3878 ** x format: unsigned Hex integer format ?Mx and 0mx is also applied.
3879 ** c format: ASCII format.
3880
3881 **Example**
3882
3883 Decimal format
3884
3885 {{code language="lua"}}
3886 @W_HDW1=1456'assign value {1456} to HDW1.
3887
3888 W2S("@W_HDW1", "@W_HDW10", "6d") ' convert{1456} to decimal text and save to HDW10.
3889 {{/code}}
3890
3891 **Result: **@W_HDW10 shown "1456"
3892
3893 0md
3894
3895 {{code language="lua"}}
3896 @W_HDW1=1456 ' assign value {1456} to HDW1
3897
3898 W2S("@W_HDW1", "@W_HDW10", "06d") ' convert{1456} to integer decimal text and add 2 {0} on the left of the data then save to HDW10.
3899 {{/code}}
3900
3901 **Result:** @W_HDW10 show text "001456"
3902
3903 == **WaitEthernetStart** ==
3904
3905 **Function**
3906
3907 WaitEthernetStart (A1)
3908
3909 **Description**
3910
3911 Waiting for Ethernet to start, it will extend the HMI start up time (only added in PI i series, Ethernet start up is earlier than HMI in other PI series)
3912
3913 **Parameters**
3914
3915 * **A1: **Waiting timeout (1~~20s)
3916 ** If A1=0, the wait timeout is 10s;
3917 ** If A1>20, the wait timeout is 20s;
3918
3919 **Returned value:** None
3920
3921 **Example**
3922
3923 //WaitEthernetStart (15)//
3924
3925 ‘The maximum waiting time is 15 seconds. If Ethernet is not started within 15 seconds, HMI will start the system and no longer wait for ethernet.
3926
3927 == **WHILE ... WEND** ==
3928
3929 **Function**
3930
3931 While condition
3932
3933 [statements]
3934
3935 Wend
3936
3937 **Description**
3938
3939 If the condition is true, then all the commands before Wend in the statement will be executed then recheck the condition, if the condition is false, the command after Wend will be executed.
3940
3941 **Parameters**
3942
3943 * **Condition: **Number or string, the result represents as True or False.
3944
3945 **Returned value:** None.
3946
3947 **Example**
3948
3949 {{code language="lua"}}
3950 while @W_HDW1>50 'the condition is the value of HDW1 bigger than 50.
3951
3952 @W_HDW1=@W_HDW1-1 'when the condition is true, execute subtract 1 from 1HDW.
3953
3954 wend
3955
3956 @W_HDW2=@W_HDW2+1 ' when the condition is false, execute add 1 from 1HDW.
3957 {{/code}}
3958
3959 **Result:** If HDW1=60, after executed; HDW1=50, if the condition is true.
3960
3961 == **WriteAddr** ==
3962
3963 **Function**
3964
3965 WriteAddr(A1,A2)
3966
3967 **Description**
3968
3969 Assign the value from A2 to address A1.
3970
3971 **Parameters**
3972
3973 * **A1:** operated address
3974 * **A2:** source address
3975
3976 **Returned value:** None.
3977
3978 **Example**
3979
3980 {{code language="lua"}}
3981 dim f as integer ' integer f
3982
3983 f=13 ' assign the value 13 to f
3984
3985 WriteAddr("@W_HDW1",f) ' write the value to HDW1.
3986
3987 WriteAddr("@W_HDW10",@W_HDW2) ' write the value from HDW2 to HDW10.
3988 {{/code}}
3989
3990 **Result:**
3991
3992 * HDW1=13
3993 * HDW10= HDW2'IF HDW2=1456,Then HDW10=1456;IF HDW2=-123,Then HDW10=-123
3994
3995 == **WriteWordToFile** ==
3996
3997 **Function**
3998
3999 WriteWordToFile (A1,A2,A3,A4,A5,A6)
4000
4001 **Description**
4002
4003 Write data of designated length to specified file
4004
4005 **Parameters**
4006
4007 A1: File location (value is an integer);
4008
4009 In HMI:
4010
4011 * =0: Recipe folder in HMI flash;
4012 * =1: Custom folder in UDisk (USB flash disk);
4013 * = 2: Custom folder in SD card.
4014 * =3: Custom folder in HMI flash;
4015
4016 In simulator:
4017
4018 * = 0: D:/Recipe/
4019 * = 1: C:/WECON/CustomFileDir/
4020 * = 2: C:/WECON/CustomFileDir/
4021 * = 3: C:/WECON/CustomFileDir/
4022
4023 **✎Note: **A1 can be an address, variable or value.
4024
4025 A2: File name (value is a string);
4026
4027 Input the file name want to write.
4028
4029 **✎Note: **A2 must be an address, and the length of the file name cannot exceed 32 characters.
4030
4031 A3: Data start address (value is a string);
4032
4033 Input the data want to write
4034
4035 **✎Note: **A3 must be the address.
4036
4037 A4: Data length (value is an integer)
4038
4039 Set the length of the data to be written (unit:word)
4040
4041 **✎Note: **A4 can be an address , variable or value.
4042
4043 A5: Return value (value is an integer)
4044
4045 * = 1: Successfully written
4046 * = 2: Failed to open the folder
4047 * = 3: Read address error
4048 * = 4: File writing error
4049 * = 5: The file already exists
4050
4051 **✎Note: **A5 must be an address.
4052
4053 A6: Folder name (value is a string);
4054
4055 Input the folder where to be written the file.
4056
4057 (% class="box infomessage" %)
4058 (((
4059 **✎Note: **A6 can be an address or a variable or a character string, and the length of the folder name cannot exceed 32 characters
4060 )))
4061
4062 **Example**
4063
4064 (% class="box" %)
4065 (((
4066 WriteWordToFile(@W_HDW1254,"@W_HDW4200","@W_HDW1000",@W_HDW4000,"@W_HDW4100", @W_HDW4300)'Write the @W_HDW4000 words in the address @W_HDW1000 to the file @W_HDW4200 in directory @W_HDW4300 specified location by @W_HDW1254
4067 )))