21.04.2025, 09:54
(18.04.2025, 15:16)imprashant Wrote: Hi, I have done the changes in the mbslave (user library script). But still I didn't understand how will I disable one Zone to communicate with the SCADA over modbus rtu. Do I need to make some changes in resident script as well. Please guide.
Previously the script I was using was working but sometimes I have to send command 2-3 times from Modscan in order to execute command in LM5. The script I was using:
local mb = require('user.mbslave')
local mbrtu = require('luamodbus').rtu()
mbrtu:open('/dev/RS485-1', 9600, 'N', 8, 1, 'H')
mbrtu:connect()
mbrtu:setslave('*') -- Accept multiple RTU slave IDs
mb.setswap('w')
mb.setfloat16precision(2)
local ga1 = '0/0/11' --zone 1 enable/disable
local ga2 = '0/0/12' --zone 2 enable/disable
local current_mapping = nil
-- Predefine mappings for easy reuse
local mapping1 = {
[1] = {
coils = {
[0] = '0/0/1',
},
registers = {
[0] = '0/0/2',
}
}
}
local mapping2 = {
[1] = {
coils = {
[1] = '0/0/3',
},
registers = {
[1] = '0/0/4',
}
}
}
while true do
local val1 = grp.getvalue(ga1)
local val2 = grp.getvalue(ga2)
if not val1 and current_mapping ~= "mapping1" then
mb.setmapping(mapping1)
current_mapping = "mapping1"
log("Applied Mapping 1")
elseif not val2 and current_mapping ~= "mapping2" then
mb.setmapping(mapping2)
current_mapping = "mapping2"
log("Applied Mapping 2")
end
mb.rtuhandler(mbrtu)
os.sleep(1) -- small delay to prevent CPU hogging
end