If I’m writing to a list of say 5 tags and at any point in time any combination of them could exist or not exist, is there any penalty/issue with using system.tag.writeBlocking() to write to all 5 regardless of which one(s) exist? When I run it with a test tag that doesn’t exist in the script console it just returns bad not found. This shouldn’t cause any issues and the tags that do exist should be written with the correct value, right?
I should also note that some of these tags exist on other tag providers which also may or may not exist, which may actually be more of an issue because using a provider in the tag path that doesn’t exist does throw an error.
Curious to me that a tag that doesn’t exist on a provider that does exist is handled differently than just a provider that doesn’t exist
The decision of what to do when a write happens to a nonexistent tag path is made by the individual provider. While most of them probably do the same as the default local provider, there's no guarantee of that at the interface level - e.g. MQTT could do something different from the 'System' provider could do something different from a remote provider.
That would definitely be a solution. Remove it from the list if it doesn’t exist.
I’ve actually got these tag paths in a dict before making them in a list so I went ahead and used a filter because I know which ones I’ll have based on the providers that exist.
This does take up time... if this is on the gateway itself then it'll be much faster. If this is something that is being written to on the HMI layer, I'm not sure I would recommend this as a solution.
Agreed. I did not want to do a for loop to check if each tag exists and remove it from the list if it doesn’t.
For the record, this was my solution:
area_tags = {
1: ["[Area_01]Alarms/ALM_","[Area_01]Alarms/PLC14_ALM_"],
5: ["[Area_05]Alarms/ALM_"],
8: ["[Area_08]Alarms/ALM_","[Area_08]Vendor_Systems/IFAS_CP/Alarms/ALM_"],
10: ["[Area_10]Alarms/ALM_","[Area_10]Alarms/PLC11_ALM_"],
15: ["[Area_15]Alarms/ALM_"],
17: ["[Area_17]Alarms/ALM_"],
18: ["[Area_18]Alarms/ALM_"],
19: ["[Area_19]Alarms/ALM_"],
}
stationArea = system.tag.readBlocking(['Areas/Station_Area'])[0].value
#filter out tags if this is not the master
if not stationArea == 0:
area_tags = { key: value for key, value in area_tags.items() if key == stationArea}
if reset:
suffix = "Reset"
else:
suffix = "ACK"
if not areas:
tagsToWrite = [tag + suffix for tag_list in area_tags.values() for tag in tag_list]
else:
tagsToWrite = [tag + suffix for area,tag_list in area_tags.items() if area in areas for tag in tag_list]
valsToWrite = [1 for tag in tagsToWrite]
system.tag.writeBlocking(tagsToWrite, valsToWrite)