@dobot-plus/template 1.2.17 → 1.3.2

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 CHANGED
@@ -1,19 +1,19 @@
1
- --- @module control
1
+ --- @module $PLUGIN_NAME$
2
2
  --- @description This is the control module for the plugin.
3
3
  --- 该模块为插件的功能模块,用于实现各种控制功能。
4
4
 
5
- local control = {}
5
+ local $PLUGIN_NAME$ = {}
6
6
 
7
- control.controlMethod1 = function(params)
7
+ $PLUGIN_NAME$.controlMethod1 = function(params)
8
8
  -- TODO 实现函数逻辑
9
9
  end
10
10
 
11
- control.controlMethod2 = function(params)
11
+ $PLUGIN_NAME$.controlMethod2 = function(params)
12
12
  -- TODO 实现函数逻辑
13
13
  end
14
14
 
15
- control.controlMethod3 = function(params)
15
+ $PLUGIN_NAME$.controlMethod3 = function(params)
16
16
  -- TODO 实现函数逻辑
17
17
  end
18
18
 
19
- return control
19
+ return $PLUGIN_NAME$
package/lua/daemon.lua CHANGED
@@ -2,7 +2,7 @@
2
2
  --- @description This is the daemon module for the plugin.
3
3
  --- 该模块插件的入口进程,在插件安装成功后自动执行该文件中的 EventLoop 方法,该方法会不断的执行,直到程序退出。
4
4
 
5
- local mqtt = require('utils.mqtt')
5
+ local mqtt = require('$PLUGIN_NAME$.mqtt')
6
6
 
7
7
  local function handleInLoop()
8
8
  local data = {}
package/lua/httpAPI.lua CHANGED
@@ -2,7 +2,7 @@
2
2
  --- @description This is the http module for the plugin.
3
3
  --- 该模块为控制器处理插件的 http 请求提供接口
4
4
 
5
- local control = require("control")
5
+ local $PLUGIN_NAME$ = require("$PLUGIN_NAME$")
6
6
 
7
7
  local httpModule = {}
8
8
 
@@ -32,7 +32,7 @@ end
32
32
  --- 该方法会在http请求接收到后,自动执行,对应请求的 url为: http://<控制器ip>:<插件端口>/dobotPlus/[插件名]_[插件版本]/demoMethod1。
33
33
  httpModule.demoMethod1 = function(params)
34
34
  -- TODO 需要在接收到http请求后执行的操作
35
- control.controlMethod1(params)
35
+ $PLUGIN_NAME$.controlMethod1(params)
36
36
  return {
37
37
  --- Your responce data
38
38
  status = true
@@ -44,7 +44,7 @@ end
44
44
  --- @param params table
45
45
  --- @return string
46
46
  httpModule.demoMethod2 = function(params)
47
- control.controlMethod2(params)
47
+ $PLUGIN_NAME$.controlMethod2(params)
48
48
  return {
49
49
  --- Your responce data
50
50
  status = true
@@ -56,7 +56,7 @@ end
56
56
  --- @param params table
57
57
  --- @return string The return value will response the http request, the return value is not necessory
58
58
  httpModule.demoMethod3 = function(params)
59
- control.controlMethod3(params)
59
+ $PLUGIN_NAME$.controlMethod3(params)
60
60
  return {
61
61
  --- Your responce data
62
62
  status = true
package/lua/userAPI.lua CHANGED
@@ -2,8 +2,8 @@
2
2
  --- @description This is the user API module for the plugin.
3
3
  --- 该模块为脚本编程和积木编程提供插件接口
4
4
 
5
- require("utils.await485")
6
- local control = require("control")
5
+ require("$PLUGIN_NAME$.modbus")
6
+ local $PLUGIN_NAME$ = require("$PLUGIN_NAME$")
7
7
 
8
8
  local userApiModule = {}
9
9
 
@@ -16,21 +16,21 @@ end
16
16
  --- This function can be used in the httpAPI module also
17
17
  ---@param params table
18
18
  function userApiModule.demoMethod1(params)
19
- return control.controlMethod1(params)
19
+ return $PLUGIN_NAME$.controlMethod1(params)
20
20
  end
21
21
 
22
22
  --- This function will be called when you add it in the blockly programming or script programming
23
23
  --- This function can be used in the httpAPI module also
24
24
  ---@param params table
25
25
  function userApiModule.demoMethod2(params)
26
- return control.controlMethod2(params)
26
+ return $PLUGIN_NAME$.controlMethod2(params)
27
27
  end
28
28
 
29
29
  --- This function will be called when you add it in the blockly programming or script programming
30
30
  --- This function can be used in the httpAPI module also
31
31
  ---@param params table
32
32
  function userApiModule.demoMethod3(params)
33
- return control.controlMethod3(params)
33
+ return $PLUGIN_NAME$.controlMethod3(params)
34
34
  end
35
35
 
36
36
  -- This function will be called when the plugin is installed
@@ -0,0 +1,50 @@
1
+ require('$PLUGIN_NAME$.variables')
2
+ require("$PLUGIN_NAME$.util")
3
+ local lockerName = "$PLUGIN_NAME$_Locker"
4
+
5
+ --- SetTool485(baudrate, parity, stop, identify)
6
+ --- err, id = ModbusCreate(ip, port, slaveId, isRTU): use endTool for 485 communication
7
+ --- err:int, 0: success, 1: over max master num, 2: master init failed, 3: master connect to poll failed
8
+ --- err, id = ModbusRTUCreate(slave_id, baud, parity, data_bit, stop_bit): use controller for 485 communication
9
+ function createModbusMasterClient(slaveID)
10
+ SetTool485(115200, 'E', 1, 1)
11
+ local err, id = ModbusCreate("127.0.0.1", 60000, tonumber(slaveID), true)
12
+ --- local err, id = ModbusRTUCreate(slave_id, baud, parity, data_bit, stop_bit)
13
+ if err ~= 0 then
14
+ print("Schunk ModbusCreate error:"..err)
15
+ return nil
16
+ end
17
+ return id
18
+ end
19
+
20
+ --- @param reg table {addrDec: number, length: number}
21
+ function getRegsData(reg, slaveID)
22
+ local clientID = createModbusMasterClient(slaveID)
23
+ if clientID == nil then
24
+ return {}
25
+ end
26
+ local result = Lock(lockerName, 10000, 10000)
27
+ Wait(10)
28
+ local data = GetHoldRegs(clientID, reg.addrDec, reg.length)
29
+ Wait(10)
30
+ UnLock(lockerName)
31
+ ModbusClose(clientID)
32
+ return data
33
+ end
34
+
35
+ --- @param reg table {addrDec: number, length: number}
36
+ --- @param values table length should be the same as reg.length
37
+ --- @return err int, 0: success, -1: failed
38
+ function setRegsData(reg, values, slaveID)
39
+ local clientID = createModbusMasterClient(slaveID)
40
+ if clientID == nil then
41
+ return -1
42
+ end
43
+ local result = Lock(lockerName, 10000, 10000)
44
+ Wait(10)
45
+ local err = SetHoldRegs(clientID, reg.addrDec, reg.length, values, 'U16')
46
+ Wait(10)
47
+ UnLock(lockerName)
48
+ ModbusClose(clientID)
49
+ return err
50
+ end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dobot-plus/template",
3
- "version": "1.2.17",
3
+ "version": "1.3.2",
4
4
  "engines": {
5
5
  "node": "20"
6
6
  },
@@ -1,55 +0,0 @@
1
- require('utils.variables')
2
- require("utils.util")
3
- local lockerName = "dobot_485_lock"
4
-
5
- --- 配置并锁定 485 接口。
6
- --- @param duration number|nil 锁定持续时间(毫秒),默认为 10000 毫秒。
7
- --- @param waitTime number|nil 等待锁定的最大时间(毫秒),默认为 10000 毫秒。
8
- --- @return boolean 返回是否成功锁定。
9
- function Use485(duration, waitTime)
10
- local _duration = 10000
11
- if duration then
12
- _duration = duration
13
- end
14
-
15
- local result = Lock(lockerName, _duration, waitTime == nil and 10000 or waitTime)
16
- Wait(10)
17
- return result
18
- end
19
-
20
- --- 使用 485 接口写入 Modbus 寄存器。
21
- --- @param modbusID number Modbus 从机地址。
22
- --- @param address number 寄存器地址。
23
- --- @param datas table 要写入的数据列表。
24
- --- @return boolean 返回是否成功写入。
25
- function WriteBy485(modbusID, address, datas)
26
- local result = Lock(lockerName, 10000, 10000)
27
- Wait(10)
28
-
29
- SetHoldRegs(modbusID, address, #datas, datas)
30
-
31
- Wait(10)
32
- UnLock485()
33
- return result
34
- end
35
-
36
- --- 使用 485 接口读取 Modbus 寄存器。
37
- --- @param modbusID number Modbus 从机地址。
38
- --- @param address number 寄存器地址。
39
- --- @param num number 要读取的寄存器数量。
40
- --- @return table 返回读取的数据列表。
41
- function ReadBy485(modbusID, address, num)
42
- local result = Lock(lockerName, 10000, 10000)
43
- Wait(10)
44
-
45
- local registerData = GetHoldRegs(modbusID, address, num)
46
-
47
- Wait(10)
48
- UnLock485()
49
- return registerData
50
- end
51
-
52
- --- 解锁 485 接口。
53
- function UnLock485()
54
- UnLock(lockerName)
55
- end