11.12.2022, 13:00
(This post was last modified: 11.12.2022, 13:10 by christian.hegland@caverion.com.)
Hi,
I'm having a hard time understanding how to make a simple script, for controlling a modbus device (off, Auto)
I've made a trigger sensor which I've tagged, and used in event based scripting.
But it seems like its working almost as expexted, nut sometimes the registers not get fullt set. Maybe theres some comm.issues
which causes some timeouts or drops.
Is there anyway to make a for-loop to run the script for X runs, until the register feedback is what i sent as command?
Would also be great to use only one script for multiple mbslave ID's. So a loop here also starting from slave 1 til 3 for instance.
Now I'm currently running this script duplicated for 3 devices on the same Modbus TCP gateway, modified only the mbslave ID.
This is the script:
I'm having a hard time understanding how to make a simple script, for controlling a modbus device (off, Auto)
I've made a trigger sensor which I've tagged, and used in event based scripting.
But it seems like its working almost as expexted, nut sometimes the registers not get fullt set. Maybe theres some comm.issues
which causes some timeouts or drops.
Is there anyway to make a for-loop to run the script for X runs, until the register feedback is what i sent as command?
Would also be great to use only one script for multiple mbslave ID's. So a loop here also starting from slave 1 til 3 for instance.
Now I'm currently running this script duplicated for 3 devices on the same Modbus TCP gateway, modified only the mbslave ID.
This is the script:
Code:
require('luamodbus')
mb = luamodbus.tcp()
mb:open('192.168.1.7', 502)
mb:connect()
mb:setslave(2)
if event.getvalue() >= 0 then
mb:writeregisters(367, 0) -- Manual stop command
else
mb:writeregisters(367, 3) -- Auto command
end
mb:close()
Best regards
Christian
Christian