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.

Read with Wait function
#2
Use this function:
Code:
function readresponse(alias, timeout)
  local obj, lb, ts, tu, delta, value
  obj = grp.find(alias)

  if not obj then
    return nil, 'object not found'
  end

  timeout = timeout or 3

  lb = require('localbus').new(timeout / 10)
  lb:sethandler('groupresponse', function(event)
    if event.dst == obj.address then
      value = busdatatype.decode(event.datahex, obj.datatype)
    end
  end)

  grp.read(obj.address)
  ts, tu = os.microtime()

  repeat
    lb:step()
    delta = os.udifftime(ts, tu)
  until value ~= nil or delta >= timeout

  if value ~= nil then
    return value
  else
    return nil, 'timeout'
  end
end

res, err = readresponse('0/0/3')
log(res, err)
Reply


Messages In This Thread
Read with Wait function - by Thomas - 02.07.2019, 14:02
RE: Read with Wait function - by admin - 03.07.2019, 08:18
RE: Read with Wait function - by Thomas - 03.07.2019, 09:59
RE: Read with Wait function - by admin - 03.07.2019, 11:42
RE: Read with Wait function - by admin - 23.07.2019, 11:06

Forum Jump: