12.02.2024, 10:33
(12.02.2024, 08:20)tomnord Wrote: What is the best way, when using grp.create, to check if the GA is allready created? I'm thinking of making a dynamic script, so that when I add new GA's and tag them correctly the script will generate new virtual GA's.
I use function block like this when automatically generating addresses in my programs...
Code:
--**********CREATE GROUP ADDRESSES******************
function createga(groupaddress,datatype,name)
exist = grp.alias(groupaddress)
if exist == nil then
address = grp.create({
datatype = datatype,
address = groupaddress,
name = name,
comment = 'Automatically created object',
units = '',
tags = { },
})
end
end
User script (HEATING_config):
Code:
Main_GA = '33'
group_address_for_frontend_update = '/0/0' --If any modifications on values or chart must be updated, this variable is used.
group_address_for_backend_update = '/0/1' --If any modifications on values or data file must be updated, this variable is used.
Scheduled/Resident/Event script:
Code:
require('user.HEATING_config')
createga( Main_GA .. group_address_for_backend_update, dt.bool,'HEATING - Update backend')
createga( Main_GA .. group_address_for_frontend_update, dt.bool,'HEATING - Update frontend')
--DO SOMETHING
Hope this helps...