Heres a function to enable RTU. Change RTU settings as you please.
Call this function in init. You should also set a storage so you know it has been done, so you don't enable RTU each time the device reboots.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
function enableRTU ()
function webrequest (
mod ,
act ,
vars ,
data )
require (
'json' )
require (
'dbenv' )
require (
'uci' )
local path
vars =
vars or {}
function getvar (
v )
return vars [
v ]
end
json.data =
function ()
return data or {}
end
if mod ==
'plugin' then
path =
'plugins/' ..
act ..
'/web.lua'
else
path =
'web/' ..
mod ..
'/' ..
act ..
'.lua'
end
return dofile (
'/lib/genohm-scada/' ..
path )
end
Set_enabled =
1
Set_port =
"/dev/RS485"
Set_baudrate =
19200
Set_parity =
2
Set_duplex =
"H"
Set_port1 =
""
Set_baudrate1 =
115200
Set_parity1 =
2
Set_duplex1 =
"H"
Set_port2 =
""
Set_baudrate2 =
115200
Set_parity2 =
2
Set_duplex2 =
"H"
requestdata = {
enabled =
"" ..
Set_enabled ,
port =
"" ..
Set_port ,
baudrate =
"" ..
Set_baudrate ,
parity =
"" ..
Set_parity ,
duplex =
"" ..
Set_duplex ,
port_1 =
"" ..
Set_port1 ,
baudrate_1 =
"" ..
Set_baudrate1 ,
parity_1 =
"" ..
Set_parity1 ,
duplex_1 =
"" ..
Set_duplex1 ,
port_2 =
"" ..
Set_port2 ,
baudrate_2 =
"" ..
Set_baudrate2 ,
parity_2 =
"" ..
Set_parity2 ,
duplex_2 =
"" ..
Set_duplex2 ,
}
result =
webrequest (
'plugin' ,
'modbus' , {
request =
'config-save' },
requestdata )
if result ==
'{"success":true}' then
alert (
'Modbus RTU enabled' )
else
alert (
'Enable Modbus RTU FAILED!' )
end
end