Changes for page 01 Lua Functions

Last modified by Theodore Xu on 2023/10/26 10:51

From version 21.1
edited by Theodore Xu
on 2023/10/26 10:51
Change comment: There is no comment for this version
To version 12.1
edited by Hunter
on 2023/02/18 15:29
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.AiXia
1 +XWiki.Hunter
Content
... ... @@ -1,5 +1,17 @@
1 1  = **1 Interface description** =
2 2  
3 +(% style="width:749.222px" %)
4 +|=(% scope="row" style="width: 374px;" %)z|=(% style="width: 373px;" %)cxz
5 +|=(% style="width: 374px;" %) |(% style="width:373px" %)
6 +|=(% style="width: 374px;" %) |(% style="width:373px" %)
7 +
8 +|分类|宽|高
9 +|网页全屏|700-850|400
10 +|手机全屏|300|400
11 +|其他大图片|400左右|400左右
12 +|小图片|200左右|200左右
13 +
14 +
3 3  == **Data type definition** ==
4 4  
5 5  |=**Type**|=**Description**
... ... @@ -1356,14 +1356,186 @@
1356 1356  {{/code}}
1357 1357  
1358 1358  (((
1359 -
1371 += **8 Internal register** =
1360 1360  )))
1361 1361  
1374 +The internal registers of the box are divided into bit addresses and word addresses, which can be accessed in two ways (taking HDW as an example):
1375 +
1376 +**Access by word, prefix @W_HDW.**
1377 +
1378 +For example: @W_HDW0 represents the first word of the system data area, @W_HDW1 represents the second word of the system data area.
1379 +
1380 +**Access in bit mode, the prefix is @B_HDX, the number in front of "." indicates the number of the word, and the number behind is the bit number of the word.**
1381 +
1382 +**For example:** @B_HDX1020.12, its meaning is to access the system data area in bit mode, the specific location is the 13th bit of the 1020th word.
1383 +
1384 +(% class="box infomessage" %)
1362 1362  (((
1363 -= **8 General Functions** =
1386 +**✎Note: **
1387 +
1388 +* The address in @B_HDX is taken from the word in @W_HDW, so pay special attention when using the address.
1389 +** For example, @B_HDX1020.12 is to access the 13th bit of the 1020th word. The value of this bit is the same as the word obtained by @W_HDW001020. The 13th bit of this word is actually the same bit as @B_HDX1020.12.
1390 +* The address of the bit address @B_HDX has a decimal point, while the word address is an integer.
1364 1364  )))
1365 1365  
1393 +
1366 1366  (((
1395 +== **Data storage area(HDW/HDX)** ==
1396 +)))
1397 +
1398 +The system storage area (HDW) of the V-BOX is used to store temporary data:
1399 +
1400 +1. Access by word, the number range is: "@W_HDW0"-"@W_HDW299999".
1401 +1. Access in bit mode, the number range is: "@B_HDX0.0"-"@B_HDX299999.15".
1402 +
1403 +(((
1404 +== **Special data area (HSW/HSX)** ==
1405 +
1406 +(% class="box infomessage" %)
1407 +(((
1408 +**✎Note: **
1409 +
1410 +* //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).
1411 +* //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.
1412 +)))
1413 +)))
1414 +
1415 +The system data area (HSW) of the box is used for system special registers (system reserved). Use //addr_getword// to obtain the following register information:
1416 +
1417 +(% class="table-bordered" %)
1418 +|=(% style="width: 151px;" %)address|=(% style="width: 169px;" %)function|=(% style="width: 456px;" %)Read and write status: read only, write only, read and write
1419 +|(% style="width:151px" %)@W_HSW0|(% style="width:169px" %)restart|(% style="width:456px" %)read and write
1420 +|(% style="width:151px" %)@W_HSW1|(% style="width:169px" %)Box time: year|(% style="width:456px" %)read and write
1421 +|(% style="width:151px" %)@W_HSW2|(% style="width:169px" %)Box time: month|(% style="width:456px" %)read and write
1422 +|(% style="width:151px" %)@W_HSW3|(% style="width:169px" %)Box time: day|(% style="width:456px" %)read and write
1423 +|(% style="width:151px" %)@W_HSW4|(% style="width:169px" %)Box time: hour|(% style="width:456px" %)read and write
1424 +|(% style="width:151px" %)@W_HSW5|(% style="width:169px" %)Box time: minute|(% style="width:456px" %)read and write
1425 +|(% style="width:151px" %)@W_HSW6|(% style="width:169px" %)Box time: second|(% style="width:456px" %)read and write
1426 +|(% style="width:151px" %)@W_HSW7|(% style="width:169px" %)Box time: week|(% style="width:456px" %)read and write
1427 +|(% style="width:151px" %)@W_HSW8|(% style="width:169px" %)Ethernet IP1|(% style="width:456px" %)read only
1428 +|(% style="width:151px" %)@W_HSW9|(% style="width:169px" %)Ethernet IP2|(% style="width:456px" %)read only
1429 +|(% style="width:151px" %)@W_HSW10|(% style="width:169px" %)Ethernet IP3|(% style="width:456px" %)read only
1430 +|(% style="width:151px" %)@W_HSW11|(% style="width:169px" %)Ethernet IP4|(% style="width:456px" %)read only
1431 +|(% style="width:151px" %)@W_HSW12|(% style="width:169px" %)Ethernet Mask 1|(% style="width:456px" %)read only
1432 +|(% style="width:151px" %)@W_HSW13|(% style="width:169px" %)Ethernet Mask 2|(% style="width:456px" %)read only
1433 +|(% style="width:151px" %)@W_HSW14|(% style="width:169px" %)Ethernet Mask 3|(% style="width:456px" %)read only
1434 +|(% style="width:151px" %)@W_HSW15|(% style="width:169px" %)Ethernet Mask 4|(% style="width:456px" %)read only
1435 +|(% style="width:151px" %)@W_HSW16|(% style="width:169px" %)Ethernet Gateway 1|(% style="width:456px" %)read only
1436 +|(% style="width:151px" %)@W_HSW17|(% style="width:169px" %)Ethernet Gateway 2|(% style="width:456px" %)read only
1437 +|(% style="width:151px" %)@W_HSW18|(% style="width:169px" %)Ethernet Gateway 3|(% style="width:456px" %)read only
1438 +|(% style="width:151px" %)@W_HSW19|(% style="width:169px" %)Ethernet Gateway 4|(% style="width:456px" %)read only
1439 +|(% style="width:151px" %)@W_HSW21|(% style="width:169px" %)Ethernet MAC1|(% style="width:456px" %)read only
1440 +|(% style="width:151px" %)@W_HSW22|(% style="width:169px" %)Ethernet MAC2|(% style="width:456px" %)read only
1441 +|(% style="width:151px" %)@W_HSW23|(% style="width:169px" %)Ethernet MAC3|(% style="width:456px" %)read only
1442 +|(% style="width:151px" %)@W_HSW24|(% style="width:169px" %)Ethernet MAC4|(% style="width:456px" %)read only
1443 +|(% style="width:151px" %)@W_HSW25|(% style="width:169px" %)Ethernet MAC3|(% style="width:456px" %)read only
1444 +|(% style="width:151px" %)@W_HSW26|(% style="width:169px" %)Ethernet MAC4|(% style="width:456px" %)read only
1445 +|(% style="width:151px" %)@W_HSW128|(% style="width:169px" %)WIFI IP1|(% style="width:456px" %)read only
1446 +|(% style="width:151px" %)@W_HSW129|(% style="width:169px" %)WIFI IP2|(% style="width:456px" %)read only
1447 +|(% style="width:151px" %)@W_HSW130|(% style="width:169px" %)WIFI IP3|(% style="width:456px" %)read only
1448 +|(% style="width:151px" %)@W_HSW131|(% style="width:169px" %)WIFI IP4|(% style="width:456px" %)read only
1449 +|(% style="width:151px" %)@W_HSW132|(% style="width:169px" %)WIFI Mask 1|(% style="width:456px" %)read only
1450 +|(% style="width:151px" %)@W_HSW133|(% style="width:169px" %)WIFI Mask 2|(% style="width:456px" %)read only
1451 +|(% style="width:151px" %)@W_HSW134|(% style="width:169px" %)WIFI Mask 3|(% style="width:456px" %)read only
1452 +|(% style="width:151px" %)@W_HSW135|(% style="width:169px" %)WIFI Mask 4|(% style="width:456px" %)read only
1453 +|(% style="width:151px" %)@W_HSW136|(% style="width:169px" %)WIFI Gateway 1|(% style="width:456px" %)read only
1454 +|(% style="width:151px" %)@W_HSW137|(% style="width:169px" %)WIFI Gateway 2|(% style="width:456px" %)read only
1455 +|(% style="width:151px" %)@W_HSW138|(% style="width:169px" %)WIFI Gateway 3|(% style="width:456px" %)read only
1456 +|(% style="width:151px" %)@W_HSW139|(% style="width:169px" %)WIFI Gateway 4|(% style="width:456px" %)read only
1457 +|(% style="width:151px" %)@W_HSW140|(% style="width:169px" %)WIFI MAC1|(% style="width:456px" %)read only
1458 +|(% style="width:151px" %)@W_HSW141|(% style="width:169px" %)WIFI MAC2|(% style="width:456px" %)read only
1459 +|(% style="width:151px" %)@W_HSW142|(% style="width:169px" %)WIFI MAC3|(% style="width:456px" %)read only
1460 +|(% style="width:151px" %)@W_HSW143|(% style="width:169px" %)WIFI MAC4|(% style="width:456px" %)read only
1461 +|(% style="width:151px" %)@W_HSW144|(% style="width:169px" %)WIFI MAC5|(% style="width:456px" %)read only
1462 +|(% style="width:151px" %)@W_HSW145|(% style="width:169px" %)WIFI MAC6|(% style="width:456px" %)read only
1463 +|(% style="width:151px" %)@W_HSW146|(% style="width:169px" %)WIFI Signal value|(% style="width:456px" %)read only
1464 +|(% style="width:151px" %)@W_HSW148|(% style="width:169px" %)4G IP1|(% style="width:456px" %)read only
1465 +|(% style="width:151px" %)@W_HSW149|(% style="width:169px" %)4G IP2|(% style="width:456px" %)read only
1466 +|(% style="width:151px" %)@W_HSW150|(% style="width:169px" %)4G IP3|(% style="width:456px" %)read only
1467 +|(% style="width:151px" %)@W_HSW151|(% style="width:169px" %)4G IP4|(% style="width:456px" %)read only
1468 +|(% style="width:151px" %)@W_HSW152|(% style="width:169px" %)4G Mask 1|(% style="width:456px" %)read only
1469 +|(% style="width:151px" %)@W_HSW153|(% style="width:169px" %)4G Mask 2|(% style="width:456px" %)read only
1470 +|(% style="width:151px" %)@W_HSW154|(% style="width:169px" %)4G Mask 3|(% style="width:456px" %)read only
1471 +|(% style="width:151px" %)@W_HSW155|(% style="width:169px" %)4G Mask 4|(% style="width:456px" %)read only
1472 +|(% style="width:151px" %)@W_HSW156|(% style="width:169px" %)4G Gateway 1|(% style="width:456px" %)read only
1473 +|(% style="width:151px" %)@W_HSW157|(% style="width:169px" %)4G Gateway 2|(% style="width:456px" %)read only
1474 +|(% style="width:151px" %)@W_HSW158|(% style="width:169px" %)4G Gateway 3|(% style="width:456px" %)read only
1475 +|(% style="width:151px" %)@W_HSW159|(% style="width:169px" %)4G Gateway 4|(% style="width:456px" %)read only
1476 +|(% style="width:151px" %)@W_HSW160|(% style="width:169px" %)4G MAC1|(% style="width:456px" %)read only
1477 +|(% style="width:151px" %)@W_HSW161|(% style="width:169px" %)4G MAC2|(% style="width:456px" %)read only
1478 +|(% style="width:151px" %)@W_HSW162|(% style="width:169px" %)4G MAC3|(% style="width:456px" %)read only
1479 +|(% style="width:151px" %)@W_HSW163|(% style="width:169px" %)4G MAC4|(% style="width:456px" %)read only
1480 +|(% style="width:151px" %)@W_HSW164|(% style="width:169px" %)4G MAC5|(% style="width:456px" %)read only
1481 +|(% style="width:151px" %)@W_HSW165|(% style="width:169px" %)4G MAC6|(% style="width:456px" %)read only
1482 +|(% style="width:151px" %)@W_HSW166|(% style="width:169px" %)4G Signal value|(% style="width:456px" %)read only
1483 +
1484 +**Others**
1485 +
1486 +* Access password: addr_getstring("@W_HSW27", 16)
1487 +* Machine code: addr_getstring("@W_HSW60", 64)
1488 +* Positioning method (@W_HSW167): (read only)
1489 +** Latitude and longitude
1490 +*** Longitude: addr_getdouble("@W_HSW168") (read only)
1491 +*** Latitude: addr_getdouble("@W_HSW172") (read only)
1492 +** Base station positioning
1493 +*** LAC: addr_getdword("@W_HSW168") (read only)
1494 +*** CI: addr_getdword("@W_HSW172") (read only)
1495 +* Convert base station to latitude and longitude via API
1496 +** Longitude: addr_getdouble("@W_HSW187") (read only)
1497 +** Latitude: addr_getdouble("@W_HSW183") (read only)
1498 +* Operator information: addr_getdword("@W_HSW181") (read only)
1499 +* Networking mode: addr_getword("@W_HSW177") (read only)
1500 +** 0: Ethernet
1501 +** 1: WIFI
1502 +** 2: 4G
1503 +** 3: 2G
1504 +* Map fence flag: addr_getword("@W_HSW178") (read only)
1505 +** 0: No map fence is drawn
1506 +** 1: Draw a map fence and the box is in the fence
1507 +** 2: Draw a map fence and the box is not in the fence
1508 +* SIM card status addr_getword("@W_HSW179") (read only)
1509 +** 1: No card detected
1510 +** 2: Card insertion detected
1511 +** 3: The card status is abnormal
1512 +* MQTT status addr_getword("@W_HSW180") (read only)
1513 +** 1: online, 2: offline
1514 +* IO interface, X is read only, Y is read and write (H series)
1515 +** addr_getbit(addr1), addr_setbit(addr2)
1516 +** addr1:"@B_Y0" "@B_Y1" "@B_X0" "@B_X1"
1517 +** addr2:"@B_Y0" "@B_Y1"
1518 +* Obtaining IMEI (read only)
1519 +** addr_getstring("@W_HSW191",17)
1520 +* Obtaining ICCID (read only)
1521 +** addr_getstring("@W_HSW225",15)
1522 +* (((
1523 +TSAP settings of Siemens LOGO PLC*
1524 +
1525 +(((
1526 +addr_setword("@W_0#HSW1200",8192) means set the Local TSAP as 20.00
1527 +)))
1528 +
1529 +* (((
1530 +addr_setword("@W_0#HSW1201",4096) means set the Remote TSAP as 10.00
1531 +)))
1532 +)))
1533 +
1534 +(((
1535 +== **Power-down storage area (HAW/HAX)** ==
1536 +
1537 +The system storage area (HAW) is used for the system power-down hold registers:
1538 +
1539 +1. Accessed as a word, numbered in the range: "@W_HAW0"-"@W_HAW199999".
1540 +1. Accessed by bit, the numbering range is: "@B_HAX0.0"-"@B_HAX199999.15".
1541 +
1542 +(% class="box infomessage" %)
1543 +(((
1544 +**✎Note:** HAW/HAX is a power-down hold, that is, the registers of this type can retain the data before power-down in case of power-down.
1545 +)))
1546 +
1547 += **9 General Functions** =
1548 +)))
1549 +
1550 +(((
1367 1367  == **send_sms_ira(string number, string message)** ==
1368 1368  )))
1369 1369  
... ... @@ -1629,7 +1629,7 @@
1629 1629  end
1630 1630  {{/code}}
1631 1631  
1632 -= **9 Special function for V-NET** =
1816 += **10 Special function for V-NET** =
1633 1633  
1634 1634  == **normal_get_alldata()** ==
1635 1635  
... ... @@ -1700,8 +1700,186 @@
1700 1700  
1701 1701  Failed: nil
1702 1702  
1703 -= **10 Message summary algorithm** =
1887 += **11 MySQL database operation** =
1704 1704  
1889 +== **luaMySql.init(string sourcename, string username, string password, string host, number port, string character)** ==
1890 +
1891 +**Function:** Configure database connection parameters
1892 +
1893 +**Parameter:**
1894 +
1895 +sourcename: the name of database
1896 +
1897 +username: the username of the connection
1898 +
1899 +password: the password of the connection
1900 +
1901 +host: the host name of the connection
1902 +
1903 +port: the host port of the connection
1904 +
1905 +character: the character set of the connection
1906 +
1907 +**Return:**
1908 +
1909 +Succeed: string
1910 +
1911 +Failed: multi
1912 +
1913 +== **luaMySql.exec(string statement)** ==
1914 +
1915 +**Function:** Execute the given SQL statement without returning the result set (add, delete, change)
1916 +
1917 +**Parameter:**
1918 +
1919 +statement: the given SQL statement
1920 +
1921 +**Return:**
1922 +
1923 +Succeed: status: returns the number of rows affected by SQL statement execution.
1924 +
1925 +Failed: nil, errorString
1926 +
1927 +== **luaMySql.execWithResult(string statement)** ==
1928 +
1929 +**Function:** Execute the given SQL statement returning the result set (check)
1930 +
1931 +**Parameter:**
1932 +
1933 +statement: the given SQL statement
1934 +
1935 +**Return:**
1936 +
1937 +Succeed: table: returns the result set
1938 +
1939 +Failed: nil, errorString
1940 +
1941 +**For example:**
1942 +
1943 +{{code language="LUA"}}
1944 +mysql = require"mysqlclient"
1945 +
1946 +function DataInitRight()
1947 +
1948 +local dbName = "db_lua1"
1949 +
1950 +local user = "root"
1951 +
1952 +local pwd = "123456"
1953 +
1954 +local host = "192.168.56.186"
1955 +
1956 +local port = 3306
1957 +local character = "UTF8"
1958 +
1959 +mysql.init(dbName, user, pwd, host, port, character)
1960 +
1961 +end
1962 +
1963 +function ExecFunc()
1964 +
1965 +status, errorString = mysql.exec("delete from tb_lua1 where mykey =
1966 +
1967 +10;")
1968 +
1969 +if nil == status then
1970 +
1971 +print("ExecFunc() error:", errorString)
1972 +
1973 +return -1
1974 +
1975 +else
1976 +
1977 +print("the number of rows affected by the command:", status)
1978 +
1979 +end
1980 +
1981 +return 0
1982 +
1983 +end
1984 +
1985 +function ExecWithResultFunc()
1986 +
1987 +status, errorString = mysql.execWithResult("select * from tb_lua1;")
1988 +
1989 +if nil == status then
1990 +
1991 +print("ExecWithResultFunc() error:", errorString)
1992 +
1993 +return -1
1994 +
1995 +else
1996 +
1997 +print("ExecWithResultFunc()
1998 +
1999 +success
2000 +
2001 +: status
2002 +
2003 +type
2004 +
2005 +=
2006 +
2007 +",
2008 +
2009 +type(status))
2010 +
2011 +print("ExecWithResultFunc() success : status len = ", #status)
2012 +
2013 +local num = #status
2014 +
2015 +local i = 1
2016 +
2017 +if num > 0 then
2018 +
2019 +for i = 1, num, 1 do
2020 +
2021 +local var = string.format("select result[%d] :mykey = %d,
2022 +
2023 +value = %s", i, status[i].mykey, status[i].value)
2024 +
2025 +print(var)
2026 +
2027 +end
2028 +
2029 +end
2030 +
2031 +print("---------------")
2032 +
2033 +end
2034 +
2035 +return 0
2036 +end
2037 +
2038 +function luaMysql_apiTest.main()
2039 +
2040 +print("script running ...")
2041 +
2042 +DataInitRight()
2043 +
2044 +--use exec demo
2045 +
2046 +if ExecFunc() < 0 then
2047 +
2048 +return
2049 +
2050 +end
2051 +
2052 +--use execWithResult demo
2053 +
2054 +if ExecWithResultFunc() < 0 then
2055 +
2056 +return
2057 +
2058 +end
2059 +
2060 +print("script running success")
2061 +
2062 +end
2063 +{{/code}}
2064 +
2065 += **12 Message summary algorithm** =
2066 +
1705 1705  == **hmac(string hash_func, string key, string message)** ==
1706 1706  
1707 1707  **Function:** HMAC calculate