Changes for page 01 Lua Functions
Last modified by Theodore Xu on 2023/10/26 10:51
Summary
-
Page properties (4 modified, 0 added, 0 removed)
Details
- Page properties
-
- Title
-
... ... @@ -1,1 +1,1 @@ 1 -01 Lua Functions1 +01 Lua script function - Parent
-
... ... @@ -1,1 +1,1 @@ 1 -V-BOX.V-Net.1\.User Manual.04 Lua Script.WebHome1 +V-BOX.V-Net.1\.User Manual.04 Lua script.WebHome - Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. Stone1 +XWiki.admin - Content
-
... ... @@ -1,66 +1,70 @@ 1 1 = **1 Interface Description** = 2 2 3 -== **Data type definition** == 3 +== **1.1 Data type definition** == 4 4 5 -|=**Type**|=**Description** 6 -|=nil|Null 7 -|=boolean|Boolean (the value is true or false) 8 -|=number|Integer or floating point (signed or unsigned) 9 -|=string|String 10 -|=table|Table 11 -|=function|Functions 5 +(% class="table-bordered" style="width:749.989px" %) 6 +|(% style="width:375px" %)**Type**|(% style="width:372px" %)**Description** 7 +|(% style="width:375px" %)nil|(% style="width:372px" %)Null 8 +|(% style="width:375px" %)boolean|(% style="width:372px" %)Boolean, the value is true or false 9 +|(% style="width:375px" %)number|(% style="width:372px" %)Integer or floating point, signed or unsigned 10 +|(% style="width:375px" %)string|(% style="width:372px" %)String 11 +|(% style="width:375px" %)table|(% style="width:372px" %)Table 12 +|(% style="width:375px" %)function|(% style="width:372px" %)Functions 12 12 13 -== **Built-in function library clipping** == 14 +== **1.2 Built-in function library clipping** == 14 14 15 15 Full features supported: coroutine/debug/ math/ package/ string/ table/ utf8 16 16 17 -//Some features supported (available in []):** **os[clock/ date/ difftime/ time]// 18 +//,,Some features supported (available in []):** **os[clock/ date/ difftime/ time],,// 18 18 19 -//Not supported: io/ file// 20 +//,,Not supported: io/ file,,// 20 20 21 -== **Return value description** == 22 +== **1.3 Return value description** == 22 22 23 23 The function return type multi means multiple return values (at least 2), usually: 24 24 25 -//1st: nil// 26 +//,,1st: nil;,,// 26 26 27 -//2nd: the error message// 28 +//,,2nd: the error message;,,// 28 28 29 29 ((( 30 -== **Function parameter description** == 31 +== **1.4 Function parameter description** == 31 31 ))) 32 32 33 - Supposeafunction prototypeis defined:34 +**Assume the function prototype:** 34 34 35 - {{code language="LUA"}}36 -student(string name, number age[, number class]) 36 +|((( 37 +//student(string name, number age[, number class])// 37 37 38 -Function: 39 +**Function:** 39 39 40 40 Register a student 41 41 42 -Parameters: 43 +**Parameters:** 43 43 44 -name: student name 45 +//name//: student name 45 45 46 -age: student age 47 +//age//: student age 47 47 48 -[class=1]: Student class 49 +//[class=1]//: Student class 49 49 50 -Return: 51 +**Return:** 51 51 52 52 Succeed: true 53 53 54 54 Failed: multi 55 - {{/code}}56 +))) 56 56 57 -** Explanation**58 +**Comment** 58 58 59 -1. string name indicates that the first parameter name is a string 60 -1. number age indicates that the second parameter age is numeric 61 -1. [, number class] indicates that the third parameter class is a numeric value, and it is optional. Specify the default class in class 1 in the parameter description. 62 -1. **Any parameter in the [] is considered to be an optional parameter, and may not be transmitted when called. The default value will be given in the parameter description.** 60 +1.string name indicates that the first parameter name is a string 63 63 62 +2.number age indicates that the second parameter age is numeric 63 + 64 +3. [, number class] indicates that the third parameter class is a numeric value, and it is optional. Specify the default class in class 1 in the parameter description. 65 + 66 +{{id name="OLE_LINK4"/}}{{id name="OLE_LINK5"/}}4. Any parameter in the brackets of [] is considered to be an optional parameter, and may not be transmitted when called. The default value will be given in the parameter description. 67 + 64 64 **Call example** 65 65 66 66 |((( ... ... @@ -89,17 +89,20 @@ 89 89 90 90 **Comment** 91 91 92 -1. From the print result, the first line and the second line are successfully called and returns true; the third line fails the call, the error message is translated as: the bar student has been registered, and there is indeed an error in the code. 93 -1. The fourth line of code uses two variables to receive the return value. The call failed, the first variable stat is nil, and the second variable err stores the error message. Then print it out using print, which is the output of the third line. This example shows how to capture and view the error message. 96 +1.From the print result, the second line of the first line is successfully called and returns true; the third line fails the call, the error message is translated as: the bar student has been registered, and there is indeed an error in the code. 94 94 95 - ==**Modification ofthePrintFunction**==98 +2.The fourth line of code uses two variables to receive the return value. The call failed, the first variable stat is nil, and the second variable err stores the error message. Then print it out using print, which is the output of the third line. This example shows how to capture and view the error message. 96 96 97 - Fortheconvenience ofremote development, the print datais sent tothe frontend (web page) by meansofnetwork transmission, and theusercan see the result of the debug output, becauseit consumes certaindata and occupies the bandwidth of the server (or occupies server resources). Sothe following restrictionsare made.100 +== **1.5 Modification of the Print Function** == 98 98 99 -1. **Interval limit: **When debugging, transfer once every 2~~3 seconds; 100 -1. **Data limit: **The transfer data cannot be larger than 1.5KB in a single transmission, otherwise the extra part will be ignored; 101 -1. **Transmission limit: **The data transmission will be stopped automatically after the debugging windows is not closed normally. Only when it is in the debugging window and the switch is on, there is data transmission; 102 +For the convenience of remote development, the print data is sent to the front end (web page) by means of network transmission, and the user can see the result of the debug output, because it consumes certain data and occupies the bandwidth of the server (or occupies server resources). So make the following restrictions: 102 102 104 +**1.Interval limit: **When debugging, transfer once every 2~~3 seconds; 105 + 106 +**2.Data limit: **The transfer data cannot be larger than 1.5KB, and the extra part will be ignored; 107 + 108 +**3.Transmission limit: **The data transmission will be stopped automatically after the debugging windows is not closed normally. Only when it is in the debugging window and the switch is on, there is data transmission; 109 + 103 103 Users should pay attention to avoid printing a lot of useless information, should minimize the debug output 104 104 105 105 In addition, please refer to the front-end documentation for how to use view debugging. ... ... @@ -107,38 +107,39 @@ 107 107 ((( 108 108 = **2 Address Operation** = 109 109 110 - 117 +**~ Form 2.1** 111 111 ))) 112 112 113 -|=16-bit data formal|=HLword|=32-bit data formal|=HLword|= 64-bit data formal|=HLword 114 -|12(Default)|0|1234(Default)|0|((( 115 -12345678(Default) 116 -)))|((( 117 -0 120 +(% class="table-bordered" style="width:982px" %) 121 +|(% style="width:167px" %) 16-bit data formal|(% style="width:142px" %) HLword|(% style="width:194px" %) 32-bit data formal|(% style="width:177px" %) HLword|(% style="width:147px" %) 64-bit data formal|(% style="width:152px" %) HLword 122 +|(% style="width:167px" %) 12(Default)|(% style="width:142px" %) 0|(% style="width:194px" %) 1234(Default)|(% style="width:177px" %) 0|(% style="width:147px" %)((( 123 + 12345678(Default) 124 +)))|(% style="width:152px" %)((( 125 + 0 118 118 ))) 119 -|21|6|((( 120 -3412(High and low word conversion) 121 -)))|2|((( 122 -34127856 (High and low word conversion) 123 -)))|2 124 -| | |2143|3|((( 125 -21436587 126 -)))|3 127 -| | |4321|6|((( 128 -87654321 129 -)))|6 130 -| | | | |((( 131 -78563412 132 -)))|7 133 -| | | | |((( 134 -56781234 135 -)))|8 136 -| | | | |((( 137 -65872143 138 -)))|9 139 -| | | | |((( 140 -43218765 141 -)))|10 127 +|(% style="width:167px" %) 21|(% style="width:142px" %) 6|(% style="width:194px" %)((( 128 + 3412(High and low word conversion) 129 +)))|(% style="width:177px" %) 2|(% style="width:147px" %)((( 130 + 34127856 (High and low word conversion) 131 +)))|(% style="width:152px" %) 2 132 +|(% style="width:167px" %) |(% style="width:142px" %) |(% style="width:194px" %) 2143|(% style="width:177px" %) 3|(% style="width:147px" %)((( 133 + 21436587 134 +)))|(% style="width:152px" %) 3 135 +|(% style="width:167px" %) |(% style="width:142px" %) |(% style="width:194px" %) 4321|(% style="width:177px" %) 6|(% style="width:147px" %)((( 136 + 87654321 137 +)))|(% style="width:152px" %) 6 138 +|(% style="width:167px" %) |(% style="width:142px" %) |(% style="width:194px" %) |(% style="width:177px" %) |(% style="width:147px" %)((( 139 + 78563412 140 +)))|(% style="width:152px" %) 7 141 +|(% style="width:167px" %) |(% style="width:142px" %) |(% style="width:194px" %) |(% style="width:177px" %) |(% style="width:147px" %)((( 142 + 56781234 143 +)))|(% style="width:152px" %) 8 144 +|(% style="width:167px" %) |(% style="width:142px" %) |(% style="width:194px" %) |(% style="width:177px" %) |(% style="width:147px" %)((( 145 + 65872143 146 +)))|(% style="width:152px" %) 9 147 +|(% style="width:167px" %) |(% style="width:142px" %) |(% style="width:194px" %) |(% style="width:177px" %) |(% style="width:147px" %)((( 148 + 43218765 149 +)))|(% style="width:152px" %) 10 142 142 143 143 * If HLword enters any other value, it will be treated as invalid. 144 144 ... ... @@ -145,9 +145,9 @@ 145 145 Demo: Reads a 32-bit floating-point number at position D0 of PLC 146 146 147 147 156 +(% style="text-align:center" %) 157 +[[image:企业微信截图_20210506180640.png||class="img-thumbnail" height="301" width="600"]] 148 148 149 -[[image:企业微信截图_20210506180640.png||height="301" width="600" class="img-thumbnail"]] 150 - 151 151 == **2.1 addr_getshort(string addr[, number type, number hlword])** == 152 152 153 153 **Function:** ... ... @@ -200,7 +200,7 @@ 200 200 201 201 **Function:** 202 202 203 -Read 16-bit unsigned decimal address 211 +{{id name="OLE_LINK6"/}}Read 16-bit unsigned decimal address 204 204 205 205 **Parameters:** 206 206 ... ... @@ -292,7 +292,7 @@ 292 292 293 293 **Function:** 294 294 295 -Read 32-bit unsigned decimal address 303 +{{id name="OLE_LINK7"/}}Read 32-bit unsigned decimal address 296 296 297 297 **Parameters:** 298 298 ... ... @@ -368,7 +368,7 @@ 368 368 369 369 //num//: value 370 370 371 -[type = 0]not read through 1: read through 379 +{{id name="OLE_LINK8"/}}[type = 0]not read through 1: read through 372 372 373 373 [hlword = 0] Don't convert,See Form 2.1 374 374 ... ... @@ -1492,7 +1492,7 @@ 1492 1492 1493 1493 **✎Note: ** 1494 1494 1495 -//HSW// is a system special register, so please refer to the system special register table during use. Do not use addresses that are not mentioned in the table, and use the addresses stated in the table with caution (example: restart ("@W_HSW0") Writing a value of 1 will cause V-BOX to restart). 1503 +//{{id name="OLE_LINK1"/}}HSW// is a system special register, so please refer to the system special register table during use. Do not use addresses that are not mentioned in the table, and use the addresses stated in the table with caution (example: restart ("@W_HSW0") Writing a value of 1 will cause V-BOX to restart). 1496 1496 1497 1497 //Without any conditions. Direct use ("@W_HSW0") will cause the V-BOX to restart continuously.// When using ("@W_HSW0") address, please add judgment conditions, such as: connection to MQTT fails, there is no network, the value of a PLC address meets the condition or counts to a certain value. 1498 1498 ... ... @@ -1835,7 +1835,7 @@ 1835 1835 Faied: multi 1836 1836 1837 1837 ((( 1838 -== **9.7 remote_com_start(string config)** == 1846 +== **9.7 {{id name="_Toc22969"/}}remote_com_start(string config)** == 1839 1839 ))) 1840 1840 1841 1841 **Function:** ... ... @@ -1875,7 +1875,7 @@ 1875 1875 Failed: multi 1876 1876 1877 1877 ((( 1878 -== **9.9 remote_com_state()** == 1886 +== **9.9{{id name="_Toc22824"/}} remote_com_state()** == 1879 1879 ))) 1880 1880 1881 1881 **Function:** ... ... @@ -1889,4 +1889,4 @@ 1889 1889 1. number, current pass-through status: 0-none 1,2-starting pass-through 3-penetrating 4,5-finishing pass-through 6-pass-through error 1890 1890 1. string, pass-through server domain name and port number, xxxx (domain name): xxx (port number) 1891 1891 1892 -Failed: multi 1900 +{{id name="OLE_LINK9"/}}Failed: multi