@dobot-plus/template 1.3.6 → 1.3.7
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/utils/modbus.lua +9 -6
- package/package.json +1 -1
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
|