This lesson is part of the Scripting in Ignition course. You can browse the rest of the lessons below.

LESSON LIST

Autoplay Off

LESSON

Tag Event Scripts

Description

Learn how to configure a script for tag events. Tag events trigger when a tags value or quality changes or when an alarm on a tag reaches a new state.

Video recorded using: Ignition 8.1

Transcript

(open in window)

[00:00] In ignition sometimes we might want to configure some custom functionality when a tag changes in some way. Ignition offers many built-in ways of handling changes in tag values from alarming to transaction groups to tag history. But when nothing does quite what we need, we can configure a script on a tag that will run under certain conditions. These are known as tag event scripts, which are similar to many event handlers you would find on different components. So if I edit this total time active tag, for example, we can click into the scripting category where we see five events that can trigger a script. We can trigger a script when the value of a tag or the tag's quality changes using the value events. Below this, we have alarm events that trigger whenever an alarm reaches a new state. This could be active, cleared, or acknowledged. Let's close out of this editor and take a look at my window. Here we have a few things going on. I have this motor running with its temperature displayed.

[01:04] Below this I have an alarm status table for an alarm set on the motor temperature tag. The alarm goes active when the motor's temperature rises over 100 degrees and the alarm will clear when it goes below that set point. What I'd like to do is use the alarms data to calculate the amount of time the alarm was active. Let's make use of the alarm event scripts on the motor temperature tag by first editing it and then going into the scripting category. We'll make use of an alarm cleared script. The alarm cleared function comes with a number of arguments that we'll see across many of the alarm events. We have the full path to the tag that triggers the alarm. The alarm's name. An object, alarm event that provides many alarm properties, the full path to the alarm, and a missed events flag that indicates when events have been skipped due to an event overflow. There's also this tag argument that gets used in every tag event, not just the alarm events. Let's calculate the total duration of our alarm. To start, I'll create a start time variable and I'll set this to alarm event dot active data dot get timestamp to give us the time our alarm when active.

[02:11] Similarly, I'll need an end time variable and I'll set this to alarm event dot cleared data dot get timestamp to give us the time the alarm cleared. We'll calculate our duration by subtracting our start time from our end time. Finally, we will add an if condition here to evaluate when the alarm was active for a significant amount of time. We'll say when the alarm was active for more than five seconds. I'll write the value of our duration to the total time active tag, which already has tag history set up. With our scripts in place, let's click on, okay. We'll watch our motor here and we'll see our motor's temperature rise over 100 degrees. The alarm will remain active for about five seconds, and once it clears, we'll see the total time duration of our alarm be written to the total time active tag.

You are editing this transcript.

Make any corrections to improve this transcript. We'll review any changes before posting them.