LogicMachine Forum
the average value of tagged objects - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: the average value of tagged objects (/showthread.php?tid=291)

Pages: 1 2


RE: the average value of tagged objects - admin - 18.10.2024

You need to assign a common tag to all inputs that belong to a single gate. Make sure that output object is not tagged.


RE: the average value of tagged objects - 2MAX - 18.10.2024

(18.10.2024, 06:10)admin Wrote: You need to assign a common tag to all inputs that belong to a single gate. Make sure that output object is not tagged.
Can you send an example to me?


RE: the average value of tagged objects - admin - 18.10.2024

In object properties there's Tags field. Each OR gate group of objects must have a unique tag.


RE: the average value of tagged objects - 2MAX - 18.10.2024

(18.10.2024, 06:19)admin Wrote: In object properties there's Tags field. Each OR gate group of objects must have a unique tag.

Maybe I´m the stupid, but I dont know how to assign group adresses ('2/2/1','2/2/3','2/2/4','2/2/5','2/2/6','2/2/7','2/2/8','2/2/9','2/2/10','2/2/11','2/2/12','2/2/13','2/2/14') to tag group


RE: the average value of tagged objects - admin - 18.10.2024

Go to Objects tab, click 2/2/1 to open Edit object form and set Tags field to group_1. Do this for all other objects from the same group.

You can use Object filter and Mass edit to assign tags to multiple objects at once.


RE: the average value of tagged objects - 2MAX - 18.10.2024

(18.10.2024, 06:37)admin Wrote: Go to Objects tab, click 2/2/1 to open Edit object form and set Tags field to group_1. Do this for all other objects from the same group.

You can use Object filter and Mass edit to assign tags to multiple objects at once.

ok, i do this but something is wrong because error of nill compare

Code:
if not client then   -- each group has 3 fields:   -- tag - status object tag   -- output - status output object   -- mode - calculate mode (and/or/avg)   groups = {     { tag = 'vnt251', output = '6/2/51', mode = 'or' },     { tag = 'vnt252', output = '6/2/52', mode = 'or' },     { tag = 'vnt254', output = '6/2/54', mode = 'or' },     { tag = 'vnt150', output = '6/1/50', mode = 'or' },     { tag = 'vnt152', output = '6/1/52', mode = 'or' },     { tag = 'vnt153', output = '6/1/53', mode = 'or' },   }       -- time to wait between last telegram from any status in group and update   updatedelay = 0.5   timeout = updatedelay / 2   -- object value cache   values = {}   -- object datatype cache   datatypes = {}   -- send update only when value changes   grp.checkupdate = function(alias, value)     if values[ alias ] ~= value then       grp.update(alias, value)     end   end   calc = {}   -- AVERAGE value   calc['avg'] = function(group)     local result, count, value = 0, 0     for _, address in ipairs(group.objects) do       value = values[ address ]       -- number must be in [0..100] range       if type(value) == 'number' then         result = result + value         count = count + 1       -- boolean true is 100%, false is 0%       elseif type(value) == 'boolean' then         if toboolean(value) then           result = result + 100         end         count = count + 1       end     end     if count > 0 then       result = math.floor(result / count + 0.5)       grp.checkupdate(group.output, result)     end   end   -- AND gate   calc['and'] = function(group)     local result = true     for _, address in ipairs(group.objects) do       result = result and toboolean(values[ address ])     end     grp.checkupdate(group.output, result)   end   -- OR gate   calc['or'] = function(group)     local result = false     for _, address in ipairs(group.objects) do       result = result or toboolean(values[ address ])     end     grp.checkupdate(group.output, result)   end   -- MAX value   calc['max'] = function(group)     local result = -math.huge     for _, address in ipairs(group.objects) do       local value = values[ address ]       if type(value) == 'number' then         result = math.max(result, value)       end     end     grp.checkupdate(group.output, result)   end   -- MIN value   calc['min'] = function(group)     local result = math.huge     for _, address in ipairs(group.objects) do       local value = values[ address ]       if type(value) == 'number' then         result = math.min(result, value)       end     end     grp.checkupdate(group.output, result)   end   -- SUM value   calc['sum'] = function(group)     local result = 0     for _, address in ipairs(group.objects) do       local value = values[ address ]       if type(value) == 'number' then         result = result + value       end     end     grp.checkupdate(group.output, result)   end   -- prepare each group   for _, group in ipairs(groups) do     object = grp.find(group.output)     -- cache output status object value and datatype     values[ object.address ] = object.data     datatypes[ object.address ] = object.datatype     group.output = object.address     -- group input status object list     group.objects = {}     -- find all status objects and cache values and datatypes     objects = grp.tag(group.tag)     for _, object in ipairs(objects) do       values[ object.address ] = object.data       datatypes[ object.address ] = object.datatype       table.insert(group.objects, object.address)     end     -- force update on first run     group.timer = 0     -- calc function reference     group.fn = calc[ group.mode ]   end   -- handle group writes   function eventhandler(event)     local dst, datatype     dst = event.dst     datatype = datatypes[ event.dst ]     -- unknown object, stop     if not datatype then       return     end     values[ dst ] = dpt.decode(event.datahex, datatype)     -- check if any group needs to be updated     for _, group in ipairs(groups) do       for _, address in ipairs(group.objects) do         if address == dst then           group.timer = updatedelay         end       end     end   end   require('genohm-scada.eibdgm')   client = eibdgm:new({ timeout = 0.1 })   client:sethandler('groupwrite', eventhandler) end delta = 0 repeat   tsec, tusec = os.microtime()   client:step()   tdelta = os.udifftime(tsec, tusec)   -- clock jump   if tdelta < 0 then     delta = timeout   else     delta = delta + tdelta   end until delta >= timeout -- check if any group has an active timer for _, group in ipairs(groups) do   timer = group.timer   if timer then     timer = timer - delta     -- timer expired, run calc function     if timer <= 0 then       group.fn(group)       timer = nil     end     group.timer = timer   end end



RE: the average value of tagged objects - Daniel - 18.10.2024

most likely a tag is assigned to wrong object


RE: the average value of tagged objects - 2MAX - 18.10.2024

(18.10.2024, 08:47)Daniel Wrote: most likely a tag is assigned to wrong object

All off objects are 1.bit switch and output too


RE: the average value of tagged objects - Daniel - 18.10.2024

send me your backup to PM


RE: the average value of tagged objects - Daniel - 18.10.2024

Disable Autoload for this user library Dobeh_ventilatoru
add require('user.Dobeh_ventilatoru') in every script you want this to run


RE: the average value of tagged objects - 2MAX - 20.10.2024

(18.10.2024, 11:00)Daniel Wrote: Disable Autoload for this user library Dobeh_ventilatoru
add require('user.Dobeh_ventilatoru') in every script you want this to run

Ok, but error message from script "Svetla pro ventilátory" is still there.


RE: the average value of tagged objects - Daniel - 21.10.2024

Disable and enable this script to restart it.


RE: the average value of tagged objects - 2MAX - 21.10.2024

(21.10.2024, 07:49)Daniel Wrote: Disable and enable this script to restart it.

Restart of script doesnt work, after restart LM, it works fine. Thank for Your help.