@dobot-plus/template 1.3.6 → 1.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lua/control.lua +4 -4
- package/lua/daemon.lua +3 -2
- package/lua/httpAPI.lua +10 -13
- package/lua/userAPI.lua +8 -8
- package/lua/utils/modbus.lua +9 -6
- package/lua/utils/mqtt.lua +2 -2
- package/package.json +1 -1
- package/ui/Blocks.tsx +1 -1
- package/ui/Toolbar.tsx +1 -1
package/lua/control.lua
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
--- @module $PLUGIN_NAME$
|
|
2
2
|
--- @description This is the control module for the plugin.
|
|
3
|
-
---
|
|
3
|
+
--- This module contains the main control functions that will be called by the plugin's main logic.
|
|
4
4
|
|
|
5
5
|
local $PLUGIN_NAME$ = {}
|
|
6
6
|
|
|
7
7
|
$PLUGIN_NAME$.controlMethod1 = function(params)
|
|
8
|
-
-- TODO
|
|
8
|
+
-- TODO implement the logic for controlMethod1
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
$PLUGIN_NAME$.controlMethod2 = function(params)
|
|
12
|
-
-- TODO
|
|
12
|
+
-- TODO implement the logic for controlMethod2
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
$PLUGIN_NAME$.controlMethod3 = function(params)
|
|
16
|
-
-- TODO
|
|
16
|
+
-- TODO implement the logic for controlMethod3
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
return $PLUGIN_NAME$
|
package/lua/daemon.lua
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
--- @module daemon
|
|
2
2
|
--- @description This is the daemon module for the plugin.
|
|
3
|
-
---
|
|
3
|
+
--- This module is the entry process of the plugin, and the EventLoop method in this file will be automatically executed after the plugin is successfully installed.
|
|
4
|
+
--- The method will continue to execute until the program exits.
|
|
4
5
|
|
|
5
6
|
local mqtt = require('$PLUGIN_NAME$.mqtt')
|
|
6
7
|
|
|
@@ -11,7 +12,7 @@ end
|
|
|
11
12
|
|
|
12
13
|
function StopHandler()
|
|
13
14
|
print('program is stopped')
|
|
14
|
-
--
|
|
15
|
+
-- Execute any operations that need to be performed when the program stops
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
local function EventLoop()
|
package/lua/httpAPI.lua
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
--- @module httpAPI
|
|
2
2
|
--- @description This is the http module for the plugin.
|
|
3
|
-
---
|
|
3
|
+
--- This module provides interfaces for the controller to handle HTTP requests for the plugin.
|
|
4
4
|
|
|
5
5
|
local $PLUGIN_NAME$ = require("$PLUGIN_NAME$")
|
|
6
6
|
|
|
7
7
|
local httpModule = {}
|
|
8
8
|
|
|
9
|
-
--- This function will be called when plugin uninstalled
|
|
10
|
-
--- 插件卸载时执行该函数
|
|
9
|
+
--- This function will be called when the plugin is uninstalled
|
|
11
10
|
httpModule.OnUninstall = function()
|
|
12
|
-
-- TODO
|
|
11
|
+
-- TODO implement the operations that need to be performed when the plugin is uninstalled
|
|
13
12
|
end
|
|
14
13
|
|
|
15
|
-
--- This function will be called when plugin installed
|
|
16
|
-
--- 插件安装时自动执行该函数
|
|
14
|
+
--- This function will be called when the plugin is installed
|
|
17
15
|
httpModule.OnInstall = function()
|
|
18
|
-
-- TODO
|
|
16
|
+
-- TODO implement the operations that need to be performed when the plugin is installed
|
|
19
17
|
end
|
|
20
18
|
|
|
21
19
|
--- This function will be called when plugin installed, this action will export some http method for device hotkey binding
|
|
22
|
-
--- 插件安装时自动执行该函数,该函数会导出一些的http方法,供设备热键绑定使用
|
|
23
20
|
httpModule.OnRegistHotKey = function()
|
|
24
|
-
--
|
|
21
|
+
-- Short press: optional demoMethod1 demoMethod2, Long press: optional demoMethod3
|
|
25
22
|
return {press = {"demoMethod1", "demoMethod2"}, longPress = {"demoMethod3"}}
|
|
26
23
|
end
|
|
27
24
|
|
|
@@ -29,12 +26,12 @@ end
|
|
|
29
26
|
--- The return value will response the http request, the return value is not necessory
|
|
30
27
|
--- @param params table
|
|
31
28
|
--- @return string The return value will response the http request, the return value is not necessory
|
|
32
|
-
---
|
|
29
|
+
--- This method will be automatically executed when the HTTP request is received, corresponding to the URL: http://<controller_ip>:<plugin_port>/dobotPlus/[plugin_name]_[plugin_version]/demoMethod1
|
|
33
30
|
httpModule.demoMethod1 = function(params)
|
|
34
|
-
-- TODO
|
|
31
|
+
-- TODO implement the operations that need to be performed when the HTTP request is received
|
|
35
32
|
$PLUGIN_NAME$.controlMethod1(params)
|
|
36
33
|
return {
|
|
37
|
-
--- Your
|
|
34
|
+
--- Your response data
|
|
38
35
|
status = true
|
|
39
36
|
}
|
|
40
37
|
end
|
|
@@ -46,7 +43,7 @@ end
|
|
|
46
43
|
httpModule.demoMethod2 = function(params)
|
|
47
44
|
$PLUGIN_NAME$.controlMethod2(params)
|
|
48
45
|
return {
|
|
49
|
-
--- Your
|
|
46
|
+
--- Your response data
|
|
50
47
|
status = true
|
|
51
48
|
}
|
|
52
49
|
end
|
package/lua/userAPI.lua
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
--- @module userAPI
|
|
2
2
|
--- @description This is the user API module for the plugin.
|
|
3
|
-
---
|
|
3
|
+
--- This module provides plugin interfaces for script programming and blockly programming.
|
|
4
4
|
|
|
5
5
|
require("$PLUGIN_NAME$.modbus")
|
|
6
6
|
local $PLUGIN_NAME$ = require("$PLUGIN_NAME$")
|
|
@@ -8,7 +8,7 @@ local $PLUGIN_NAME$ = require("$PLUGIN_NAME$")
|
|
|
8
8
|
local userApiModule = {}
|
|
9
9
|
|
|
10
10
|
function PauseHandler()
|
|
11
|
-
---
|
|
11
|
+
--- This function will be called when the program is paused
|
|
12
12
|
print(" --- PauseHandler .... --- ")
|
|
13
13
|
end
|
|
14
14
|
|
|
@@ -35,18 +35,18 @@ end
|
|
|
35
35
|
|
|
36
36
|
-- This function will be called when the plugin is installed
|
|
37
37
|
-- The export functions will be registered to the corresponding code block or script in blockly programming or script programming
|
|
38
|
-
--
|
|
39
|
-
--
|
|
40
|
-
--
|
|
38
|
+
-- This function will be automatically executed after the plugin is installed, and the ExportFunction function will export the method in the second parameter for use in script programming and blockly programming
|
|
39
|
+
-- For example: ExportFunction('A', B) will export the B function in the current module and rename it to 'A'
|
|
40
|
+
-- In script programming and blockly programming, you can use A to use this function
|
|
41
41
|
function userApiModule.OnRegist()
|
|
42
42
|
EcoLog(" --- OnRegist .... --- ")
|
|
43
|
-
---
|
|
43
|
+
--- This function will be called when the program is paused
|
|
44
44
|
RegistePauseHandler('PauseHandler')
|
|
45
|
-
-- 0.
|
|
45
|
+
-- 0. Export functions
|
|
46
46
|
local isErr = ExportFunction("demoMethod1", userApiModule.demoMethod1) or
|
|
47
47
|
ExportFunction("demoMethod2", userApiModule.demoMethod2) or
|
|
48
48
|
ExportFunction("demoMethod3", userApiModule.demoMethod3)
|
|
49
|
-
-- 1.
|
|
49
|
+
-- 1. Error handling
|
|
50
50
|
if isErr then
|
|
51
51
|
EcoLog(" --- ERR to register .... --- ", isErr)
|
|
52
52
|
dobotTool.SetError(0)
|
package/lua/utils/modbus.lua
CHANGED
|
@@ -2,12 +2,15 @@ require('$PLUGIN_NAME$.variables')
|
|
|
2
2
|
require("$PLUGIN_NAME$.util")
|
|
3
3
|
local lockerName = "dobot_485_lock"
|
|
4
4
|
|
|
5
|
+
local modbus = {}
|
|
6
|
+
|
|
5
7
|
--- SetTool485(baudrate, parity, stop, identify)
|
|
6
8
|
--- err, id = ModbusCreate(ip, port, slaveId, isRTU): use endTool for 485 communication
|
|
7
9
|
--- err:int, 0: success, 1: over max master num, 2: master init failed, 3: master connect to poll failed
|
|
8
10
|
--- err, id = ModbusRTUCreate(slave_id, baud, parity, data_bit, stop_bit): use controller for 485 communication
|
|
9
|
-
function
|
|
10
|
-
SetTool485(
|
|
11
|
+
modbus.createModbusMasterClient = function(slaveID)
|
|
12
|
+
--- SetTool485(baudrate, parity, stop)
|
|
13
|
+
SetTool485(115200, 'E', 1)
|
|
11
14
|
local err, id = ModbusCreate("127.0.0.1", 60000, tonumber(slaveID), true)
|
|
12
15
|
--- local err, id = ModbusRTUCreate(slave_id, baud, parity, data_bit, stop_bit)
|
|
13
16
|
if err ~= 0 then
|
|
@@ -18,8 +21,8 @@ function createModbusMasterClient(slaveID)
|
|
|
18
21
|
end
|
|
19
22
|
|
|
20
23
|
--- @param reg table {addrDec: number, length: number}
|
|
21
|
-
function
|
|
22
|
-
local clientID = createModbusMasterClient(slaveID)
|
|
24
|
+
modbus.getRegsData = function(reg, slaveID)
|
|
25
|
+
local clientID = modbus.createModbusMasterClient(slaveID)
|
|
23
26
|
if clientID == nil then
|
|
24
27
|
return {}
|
|
25
28
|
end
|
|
@@ -40,8 +43,8 @@ end
|
|
|
40
43
|
--- @param reg table {addrDec: number, length: number}
|
|
41
44
|
--- @param values table length should be the same as reg.length
|
|
42
45
|
--- @return err int, 0: success, -1: failed
|
|
43
|
-
function
|
|
44
|
-
local clientID = createModbusMasterClient(slaveID)
|
|
46
|
+
modbus.setRegsData = function(reg, values, slaveID)
|
|
47
|
+
local clientID = modbus.createModbusMasterClient(slaveID)
|
|
45
48
|
if clientID == nil then
|
|
46
49
|
return -1
|
|
47
50
|
end
|
package/lua/utils/mqtt.lua
CHANGED
|
@@ -9,8 +9,8 @@ mqttFunc.MQTTConnect(connectId)
|
|
|
9
9
|
|
|
10
10
|
return {
|
|
11
11
|
mqtt = mqttFunc,
|
|
12
|
-
---
|
|
13
|
-
--- @param data table
|
|
12
|
+
--- Publish data to the specified MQTT topic.
|
|
13
|
+
--- @param data table The data to be published, which will be encoded in JSON format.
|
|
14
14
|
publish = function(data)
|
|
15
15
|
mqttFunc.MQTTPublish(connectId, MQTT_PUBLISH_TOPIC, jsonLuaUtils.encode(data), 0, false)
|
|
16
16
|
end
|
package/package.json
CHANGED
package/ui/Blocks.tsx
CHANGED
package/ui/Toolbar.tsx
CHANGED