Hi everyone, I have a question, I need into the tag property edit the "readOnly" parameter.
I tried use system.tag.getConfigure(...), modify the "readOnly" property and next use system.tag.configure(...) to aply the new config to tag.
It work, but, many others property were mark with "overide".
I need only modify (aplied a "overide") to this parameter and not another. Is that possible? Any idea?
Thk
Hi again, I found "one" solution...and I created a function for this..
def setTagProperty(tagPath, propertyName, propertyValue):
config = system.tag.getConfiguration(tagPath, False)
basePath = '/'.join(tagPath.split('/')[:-1])
pattern = ["path", propertyName]
for key in config[0]:
if key not in pattern:
a = config[0].pop(key)
config[0][propertyName] = propertyValue
return system.tag.configure(basePath, config)
Use:
pathTag = "[node]PV/INV/INV_1/DATA/GENERAL/IHMI/OUT_W_SET/BLK_ENA"
setTagProperty(pathTag,"readOnly",True)
I listen to other ideas...
edit: nope, mistake
That said, if you're pulling the config with system.tag.getConfiguration
, you should only be writing back what was already configured.
I'm getting good results with
def setTagProp(tagpath, propname, value):
conf = system.tag.getConfiguration(tagpath, recursive=False)[0]
conf[propname] = value
system.tag.configure(tagpath[:-len(conf['name'])], [conf])
I tried that — in fact, it was my first choice — but many other properties were marked with 'override'.
Per example "script", "alarms", etc. This elements existed in the dict from system.tag.getConfiguration(...) and It were marked with "override" after of use system.tag.configure().
I created tags from a UDT, maybe it's related.
You can just create the barebones tag json yourself with just the tag name and the readOnly prop, and write it with tag.configure ensuring to set the mode to merge with "m". No need to use getConfiguration
I thought I tried that and it didn't work...
Maybe I messed something up
Yes, It work, and It very simple and elegant.
parentPath = "[default]IHMI/OUT_W_SET"
param = system.util.jsonEncode(
{ "readOnly" : True,
"name" : "BLK_ENA"})
system.tag.configure(parentPath, param,'m')
Thank you.
You don't need to encode it to json.
def setTagProp(tagpath, propname, value):
if '/' in tagpath:
path, name = tagpath.rsplit('/')
else:
path, sep, name = tagpath.partition(']')
path += sep
tag = {
'name': name,
propname: value
}
system.tag.configure(path, [tag], 'm')
I would expect system.tag.writeBlocking(["path/to/tag.readOnly"], [True])
to work as well.
Yes, but once set to True
, you cannot use .writeBlocking
to set it back to False
. Only .configure
can do that.
Exactly, That It were the main problem, set to False from True to protect and unprotect the tag writing.
Thank everyone.