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.

Get object name
#8
Event script (attached to a tag):
Code:
value = event.getvalue()
name = grp.find(event.dst).name

now = os.time()

h_key = 'h_alarm'
l_key = 'l_alarm'

h_lim_obj  = string.gsub(name, '_PV', '_HAL')
l_lim_obj  = string.gsub(name, '_PV', '_LAL')

alarm_h_obj = string.gsub(name, '_PV', '_AHL')
alarm_l_obj = string.gsub(name, '_PV', '_ALL')

h_alarm = value > grp.getvalue(h_lim_obj)
l_alarm = value < grp.getvalue(l_lim_obj)

if h_alarm then
  storage.exec('hsetnx', h_key, name, now)
else
  storage.exec('hdel', h_key, name)
  grp.checkwrite(alarm_h_obj, false)
end

if l_alarm then
  storage.exec('hsetnx', l_key, name, now)
else
  storage.exec('hdel', l_key, name)
  grp.checkwrite(alarm_l_obj, false)
end

Resident script. Adjust the sleep time as needed (at least 5 seconds) depending on the average delay between objects value being detected as out of bounds and the alarm object change to 1.
Code:
if not check then
  storage.openconn()

  check = function(storage_key, alarm_obj_key)
    local now = os.time()
    local items = storage.exec('hgetall', storage_key)

    for name, time in pairs(items) do
      local delay_obj = string.gsub(name, '_PV', '_AD')
      time = time + grp.getvalue(delay_obj)

      if now >= time then
        local alarm_obj = string.gsub(name, '_PV', alarm_obj_key)
        grp.checkwrite(alarm_obj, true)
      end
    end
  end
end

check('h_alarm', '_AHL')
check('l_alarm', '_ALL')
Reply


Messages In This Thread
Get object name - by tomnord - 04.06.2021, 08:35
RE: Get object name - by admin - 04.06.2021, 08:42
RE: Get object name - by tomnord - 04.06.2021, 09:19
RE: Get object name - by admin - 04.06.2021, 10:14
RE: Get object name - by tomnord - 04.06.2021, 11:33
RE: Get object name - by admin - 04.06.2021, 12:42
RE: Get object name - by tomnord - 04.06.2021, 12:49
RE: Get object name - by admin - 04.06.2021, 13:46

Forum Jump: