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]