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 Script.WebHome1 +V-BOX.V-Net.1\.User Manual.04\.Lua script function and operation.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,11 +89,12 @@ 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 100 +== **1.5 Modification of the Print Function** == 101 + 97 97 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: 98 98 99 99 **1.Interval limit: **When debugging, transfer once every 2~~3 seconds; ... ... @@ -109,38 +109,39 @@ 109 109 ((( 110 110 = **2 Address Operation** = 111 111 112 - 117 +**~ Form 2.1** 113 113 ))) 114 114 115 -|=16-bit data formal|=HLword|=32-bit data formal|=HLword|= 64-bit data formal|=HLword 116 -|12(Default)|0|1234(Default)|0|((( 117 -12345678(Default) 118 -)))|((( 119 -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 120 120 ))) 121 -|21|6|((( 122 -3412(High and low word conversion) 123 -)))|2|((( 124 -34127856 (High and low word conversion) 125 -)))|2 126 -| | |2143|3|((( 127 -21436587 128 -)))|3 129 -| | |4321|6|((( 130 -87654321 131 -)))|6 132 -| | | | |((( 133 -78563412 134 -)))|7 135 -| | | | |((( 136 -56781234 137 -)))|8 138 -| | | | |((( 139 -65872143 140 -)))|9 141 -| | | | |((( 142 -43218765 143 -)))|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 144 144 145 145 * If HLword enters any other value, it will be treated as invalid. 146 146 ... ... @@ -147,9 +147,9 @@ 147 147 Demo: Reads a 32-bit floating-point number at position D0 of PLC 148 148 149 149 156 +(% style="text-align:center" %) 157 +[[image:企业微信截图_20210506180640.png||class="img-thumbnail" height="301" width="600"]] 150 150 151 -[[image:企业微信截图_20210506180640.png||height="301" width="600" class="img-thumbnail"]] 152 - 153 153 == **2.1 addr_getshort(string addr[, number type, number hlword])** == 154 154 155 155 **Function:** ... ... @@ -202,7 +202,7 @@ 202 202 203 203 **Function:** 204 204 205 -Read 16-bit unsigned decimal address 211 +{{id name="OLE_LINK6"/}}Read 16-bit unsigned decimal address 206 206 207 207 **Parameters:** 208 208 ... ... @@ -294,7 +294,7 @@ 294 294 295 295 **Function:** 296 296 297 -Read 32-bit unsigned decimal address 303 +{{id name="OLE_LINK7"/}}Read 32-bit unsigned decimal address 298 298 299 299 **Parameters:** 300 300 ... ... @@ -370,7 +370,7 @@ 370 370 371 371 //num//: value 372 372 373 -[type = 0]not read through 1: read through 379 +{{id name="OLE_LINK8"/}}[type = 0]not read through 1: read through 374 374 375 375 [hlword = 0] Don't convert,See Form 2.1 376 376 ... ... @@ -1494,7 +1494,7 @@ 1494 1494 1495 1495 **✎Note: ** 1496 1496 1497 -//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). 1498 1498 1499 1499 //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. 1500 1500 ... ... @@ -1837,7 +1837,7 @@ 1837 1837 Faied: multi 1838 1838 1839 1839 ((( 1840 -== **9.7 remote_com_start(string config)** == 1846 +== **9.7 {{id name="_Toc22969"/}}remote_com_start(string config)** == 1841 1841 ))) 1842 1842 1843 1843 **Function:** ... ... @@ -1877,7 +1877,7 @@ 1877 1877 Failed: multi 1878 1878 1879 1879 ((( 1880 -== **9.9 remote_com_state()** == 1886 +== **9.9{{id name="_Toc22824"/}} remote_com_state()** == 1881 1881 ))) 1882 1882 1883 1883 **Function:** ... ... @@ -1891,4 +1891,4 @@ 1891 1891 1. number, current pass-through status: 0-none 1,2-starting pass-through 3-penetrating 4,5-finishing pass-through 6-pass-through error 1892 1892 1. string, pass-through server domain name and port number, xxxx (domain name): xxx (port number) 1893 1893 1894 -Failed: multi 1900 +{{id name="OLE_LINK9"/}}Failed: multi