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.

Convert 2 byte to bits
#1
From a Gira weatherstation i recieive an error code as a 2 byte value. Each bit represents an error code like below.
Now i like to create a text object that shows the current state of this error object. So if there's one or more error it should show me all errors (in a loop by more then one error).


Bit 0: Condensatiebeveiliging actief
Bit 1: Droogfase van het sensoroppervlak
Bit 2: Waarden van digitaal-analoogomzetter ongeldig
Bit 3: Meetwaarde van druksensor ongeldig
Bit 4: Meetwaarde van helderheidssensor noord ongeldig
Bit 5: Meetwaarde helderheidssensor oost ongeldig
Bit 6: Meetwaarde van helderheidssensor zuid ongeldig
Bit 7: Meetwaarde van helderheidssensor west ongeldig
Bit 8: Schemermeetwaarde ongeldig
Bit 9: Meetwaarde van globale stralingssensor ongeldig
Bit 10: Meetwaarde van luchttemperatuursensor ongeldig
Bit 11: Meetwaarde van neerslagsensor ongeldig
Bit 12: Meetwaarde van windsnelheidssensor ongeldig
Bit 13: Meetwaarde van windrichtingsensor ongeldig
Bit 14: Meetwaarde van de vochtmeting ongeldig
Bit 15: Interne systeemfout
Reply
#2
See this: https://forum.logicmachine.net/showthread.php?tid=1081
Reply
#3
(02.05.2024, 07:46)admin Wrote: See this: https://forum.logicmachine.net/showthread.php?tid=1081

Thanks admin. So far so good.. But now i like to make a text loop showing each error for 2 seconds.

Code:
value = event.getvalue()

errors = {
    [0] = 'Condensatiebeveiliging actief',
    [1] = 'Droogfase van het sensoroppervlak',
    [2] = 'Waarden van digitaal-analoogomzetter ongeldig',
    [3] = 'Meetwaarde van druksensor ongeldig',
    [4] = 'Meetwaarde van helderheidssensor noord ongeldig',
    [5] = 'Meetwaarde helderheidssensor oost ongeldig',
    [6] = 'Meetwaarde van helderheidssensor zuid ongeldig',
    [7] = 'Meetwaarde van helderheidssensor west ongeldig',
    [8] = 'Schemermeetwaarde ongeldig',
    [9] = 'Meetwaarde van globale stralingssensor ongeldig',
    [10] = 'Meetwaarde van luchttemperatuursensor ongeldig',
    [11] = 'Meetwaarde van neerslagsensor ongeldig',
    [12] = 'Meetwaarde van windsnelheidssensor ongeldig',
    [13] = 'Meetwaarde van windrichtingsensor ongeldig',
    [14] = 'Meetwaarde van de vochtmeting ongeldig',
    [15] = 'Interne systeemfout',
}

result = {}

for i = 0, 15 do
  mask = bit.lshift(1, i)
  if bit.band(mask, value) ~= 0 then
    if errors[ i ] then
      table.insert(result, errors[ i ])
    end
  end
end

text = table.concat(result, '\n')
grp.update('5/6/3', text)
Reply
#4
Set the event script execution mode to "Last instance only" and add this code:
Code:
if #result == 0 then
  return
end

while true do
  for _, text in ipairs(result) do
    grp.update('5/6/3', text)
    os.sleep(2)
  end
end
Reply
#5
(02.05.2024, 11:50)admin Wrote: Set the event script execution mode to "Last instance only" and add this code:
Code:
if #result == 0 then
  return
end

while true do
  for _, text in ipairs(result) do
    grp.update('5/6/3', text)
    os.sleep(2)
  end
end

Thanks admin. This works great.
Reply


Forum Jump: