Wiki source code of 08 Macro Script

Version 36.1 by Karen on 2023/06/02 14:54

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