This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Modbus tcp scripting help
#1
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:

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
Reply


Messages In This Thread
Modbus tcp scripting help - by christian.hegland@caverion.com - 11.12.2022, 13:00
RE: Modbus tcp scripting help - by admin - 12.12.2022, 07:37

Forum Jump: