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.

Update modbus profile
#7
First, you should never access serial port directly if it's used by the Modbus mapper, it will lead to random errors.

It might be that read fails for some reason and returns nil which ends up being sent as 0.
Try this:
Code:
result = mb:readregisters(26)
if result then
  grp.write('2/3/7',result)
end

Another approach is to create a scheduled script which runs every X minutes (depending on frequently you want to resend values). Mark each required object with resend tag, tune interval value in your script as needed.
Code:
now = os.time()
interval = 120 -- resend time in seconds

-- go through all objects with "resend" tag
objects = grp.tag('resend')
for _, object in ipairs(objects) do
  delta = now - object.updatetime
  
  -- check if value must be sent again
  if delta >= interval then
    object:write(object.data)
  end
end
Reply


Messages In This Thread
Update modbus profile - by sx3 - 02.10.2016, 09:48
RE: Update modbus profile - by admin - 02.10.2016, 10:08
RE: Update modbus profile - by sx3 - 02.10.2016, 10:40
RE: Update modbus profile - by admin - 02.10.2016, 12:15
RE: Update modbus profile - by sx3 - 02.10.2016, 19:05
RE: Update modbus profile - by sx3 - 03.10.2016, 04:28
RE: Update modbus profile - by admin - 03.10.2016, 07:18
RE: Update modbus profile - by sx3 - 03.10.2016, 07:53
RE: Update modbus profile - by sx3 - 03.10.2016, 10:23
RE: Update modbus profile - by FatMax - 16.11.2016, 11:13
RE: Update modbus profile - by admin - 16.11.2016, 11:21
RE: Update modbus profile - by FatMax - 16.11.2016, 11:34
RE: Update modbus profile - by admin - 16.11.2016, 11:58

Forum Jump: