Wiki source code of 08 Macro Script

Version 28.1 by Hunter on 2023/02/20 16:37

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