Hello everyone.
Is there a way to add an alarm to an OPC boolean tag via script?
With adding an alarm I mean without manually pressing the button shown below in the image. But automatically created via a script that I would then run inside a button.
I know that there is the 'system.tag.configure' to modify the alarm configurations. But without adding the tag alarm I am not able to use it.
Thank you all.
It is system.tag.configure. The docs show an example for alarms.
2 Likes
Yes I saw. And through the following script I get to create an OPC boolean tag from scratch.
# The provider and folder the Tag will be placed at.
baseTagPath = "[default]MyPath"
# Properties that will be configured on that Tag.
name = "BitAlarm_00_"
opcItemPath = "nsu=KEPServerEX;s=DR_1.CH_1.Allarmi[x].Allarmi[00].BitAlarm[x].BitAlarm[00]"
opcServer = "KEPServerEX"
valueSource = "opc"
dataType = "Boolean"
alarms = [
{
"name": "Alarm_0_1.",
"priority": "High",
"setpointA": 1,
"label": "Example",
"displayPath": "12345",
"shelvingAllowed": False
}
]
# Configure the tag.
tag = [
{
"name": name,
"opcItemPath" : opcItemPath,
"opcServer": opcServer,
"valueSource": valueSource,
"dataType": dataType,
"alarms": alarms
}
]
# Set the collision policy to Abort. Thus, if a Tag already exists at the base path,
# we will not override the Tag. If you are overwriting an existing Tag, then set this to "o".
collisionPolicy = "o"
# Create the Tag.
system.tag.configure(baseTagPath, tag, collisionPolicy)
My situation however is the following: I import the tags directly by importing them from KepServerEx, then it creates the variable tree with folders and subfolders of the various alarm tags.
From this situation I would like to alarm the various tags to be able to configure them. The problem is that I cannot add the alarm via script.
What do you mean ?
That's exactly what this script does.
The alarms in the alarms
list are the alarms you're adding to the tag. Isn't that what you want ?
Use system.tag.getConfiguration
to retrieve your tags configurations, add the alarms you want, then use system.tag.configure
.
1 Like
Yes. I have tried to alarm an existing tag using this script:
tagPath = "MyTagPath"
tagConfig = system.tag.getConfiguration(tagPath, returnDefaults=True)[0]
alarmConfig = {
"name": "Alarm_0",
"enabled": True,
"priority": "High",
"label": "Test",
}
tagConfig['alarms'] = [alarmConfig]
system.tag.configure(tagPath, tagConfig, "o")
But the response is this:
[Bad_Unsupported("The target path 'MyTagPath' cannot accept children tags.")]
Because that's not how configure
works. You're trying to add a tag in itself.
foo = system.tag.getConfiguration("foo")[0]
foo['alarms'] = [
{
"name": "Alarm_0",
"enabled": True,
"priority": "High",
"label": "Test",
}
]
system.tag.configure("", foo)
Note how I'm not passing the tag path, but its parent's path ?
It's because configure
is initially supposed to take a list of tags. Just like the read*
and write*
functions.
If you pass a list of tags, you can't expect a single tag path to work.
Try to change the path you pass to configure
.
2 Likes
Using your script it creates a tag outside of each folder of the variable tree alarmed with the indicated properties.
while the tag I would like to alarm does not undergo any modification
foo = system.tag.getConfiguration("MyTagPath")[0]
foo['alarms'] = [
{
"name": "Alarm_0",
"enabled": True,
"priority": "High",
"label": "Test",
}
]
system.tag.configure("", foo)
Well you need to pass the path of the folder where you want to put the tag as a parameter to configure
... I can't do that for you.
Let's make an example.
Let's say your tag path is [default]site_a/machine_1/foo
.
Then it will look like this
foo = system.tag.getConfiguration("[default]site_a/machine_1/foo")[0]
...
system.tag.configure("[default]site_a/machine_1", foo)
2 Likes
It works. Thank you so much for your patience!!