12.11.2024, 13:33
it works like this.
Resident
event-based.
Resident
Code:
require('luamodbus')
mb = luamodbus.tcp()
PLC_IpNo1 = '192.168.1.102'
PLC_IpNo2 = '192.168.1.103'
mb:open(PLC_IpNo1, 502)
mb:connect()
storage.set('strPLC_IpNo1', PLC_IpNo1)
storage.set('strPLC_IpNo2', PLC_IpNo2)
-- -- --
curr = mb:readregisters(0)
prev = storage.get('prev_value')
if curr ~= prev then
storage.set('prev_value', curr)
grp.update('32/1/2', curr)
end
mb:close()
event-based.
Code:
PLC_IpNo = storage.get('strPLC_IpNo1')
require('luamodbus')
mb = luamodbus.tcp()
mb:open(PLC_IpNo, 502)
mb:connect()
value = event.getvalue()
mb:writeregisters(0, value)
mb:close()