Seite 1 von 1
#1 Alle Variablen zustände verschicken ?
Verfasst: Di 10. Feb 2015, 11:32
von koboldo
Moin,
gibt es eine Möglichkeit alle Variablen/Zustände mit einer Funktion auszulesen ?
Mir ist schon klar, das ich jede Variable mit get 'variable' auslesen und dann weiterverarbeiten kann,
allerdings würde ich wenn es geht dieses irgendwie einfacher gestalten :scared:
Gibt es da eine bessere Möglichkeit, mit irgendeiner Schleife oder so ?
Gruß
Jörg
#2 RE: Alle Variablen zustände verschicken ?
Verfasst: Di 10. Feb 2015, 11:58
von DOMIQ-Support
Here is sample function that allows to read all 12 variables in a loop:
Code: Alles auswählen
function readVariables(seg,node)
local ch = string.format('LCN.variable.%s.%s.',seg,node)
local variables = {}
for i=1,12 do
variables[i] = get(ch..i)
end
return variables
end
You need to pass segment and node number as arguments. Function will return an array with variable numbers as keys and variable values as values of array elements.
And here is an example how to call this function in the Logic:
Code: Alles auswählen
variables40 = readVariables(0,40)
-- here is code to print all values:
for k,v in pairs(variables40) do
print('K: '..k..' value: '..v)
end
If you need to access single variable value (in this example variable no. 1 in module 40) then you can do it like this:
local a = variables40[1]
#3 RE: Alle Variablen zustände verschicken ?
Verfasst: Di 10. Feb 2015, 16:35
von koboldo
Danke, schon mal nicht schlecht :O
Bei dieser Lösung muss ich ja immer angeben, wieviele Variablen es gibt...
Ich eher etwas, wie ich mir alles was unter dem Reiter Zustand zu finden ist auslesen kann...
Gibt es dafür auch etwas ?
#4 RE: Alle Variablen zustände verschicken ?
Verfasst: Fr 13. Feb 2015, 08:23
von DOMIQ-Support
If you need to get values of non-zero variables this script will work too, because if a variable is not present in the State then the state.get command will return 0. So you just need to check if value is non-zero.