Description

Learn about the difference between items that run on a trigger and those that are "run always."

Video recorded using: Ignition 8.1

Transcript

(open in window)

[00:00] In previous lessons,we've thought through a couple of the ways we can work with Expression items inside of transaction groups. But it's important we address one fundamental question behind Expression logic. That question is, when do the Expressions actually evaluate? Because Expression items in groups can be used in so many different ways, there are actually two separate options available to answer that question. The first option is Run-Always, which allows an Expression to run according to the transaction groups base timer or schedule, and the second is Triggered, which will only evaluate on valid executions of the group, meaning ones where the trigger is applied and we're preparing to actually take the transaction groups action. Before we explore these two options, I want to note that if a group is not using a Trigger as configured in the Trigger tab here, there's not going to be a difference between the two approaches. They'll effectively have the same results. With that said, to demonstrate the difference between these two modes, let's walk through a quick example. I've set up a basic historical group here with some OPC items, just some data points I'd like to log and a couple of Expression items called Running and Sum.

[01:11] We've been working with some of these items already in this series. Right now I have both of our Expression items configured under run, always. So they appear in this run always Expression items box. Before we dive in deeper it's important to understand what our transaction group trigger is really doing here. For now I'll just say that my group will log data for as long as the running item here is set to true, and stop logging data when the value is false. I've used the trigger tab here to configure that behavior. For more info on transaction group triggers check out our topic on the trigger tab. So moving on here, just incidentally I have the running items set up to use my running tag in the tag browser, which will keep things simple. Referencing a tag value like this doesn't require an Expression item, but it'll be helpful for our demonstration. To test my trigger set up here, I'll toggle my running tag to false, like so, and that'll update our Expression item, and we'll see that our group stops running.

[02:07] So our execution count stops ticking up and we'll no longer get any new records being logged. Our executions will be suspended for as long as the running item stays false. Notice that even though my group is not currently running, both of my Expression items we'll continue to evaluate every second, which is precisely because they are configured as run, always Expression items. If they were configured as triggered Expression items, they would have halted execution along with the rest of the group. With that in mind, let's look at what each of these expressions is doing, and then decide whether they should be configured as run always or triggered. And we'll start with our sum item here, which is giving us a sum of the three signed values in our group and saving that to its own column in the database table. At present with our group not running and data not being logged, There's no need to perform that calculation, since we don't plan on actually saving the sum. As a result we can easily reduce the overhead of our group by configuring this Expression item as triggered. To do that I'm just going to double-click on the sum item, find the evaluation options heading towards the bottom of this interface and turn off the run, always check box, and that's all I really have to do.

[03:12] So when I click, okay, here, we'll see that the item has moved into the triggered table. We also could have clicked and dragged the item over directly. for a simple Expression like our sum, the performance benefits here won't be too noticeable, but for an Expression item running bulky sequel queries or using more complex Expression functions like run scripts, this optimization could eliminate unnecessary database, device, and network traffic when the group is not active. So now that we've addressed the sum item let's take a look at the running item. For this item, we need to take into account that it's being used as the transaction group trigger, which actually makes it imperative that we mark this Expression item as run, always, because we can't trigger our group off an item that itself only evaluates when the group is triggered. We would end up with a group that is impossible to turn on. In fact, it isn't directly possible to configure a triggered Expression item as a trigger for our group.

[04:04] So we'll leave that item in the run always box. In summary, most Expression items can be configured as triggered Expression items provided that they're not being used in the transaction groups trigger configuration. Any Expression items that are being used for the group triggers should be configured as run always. And again, if your group is not using a trigger at all the two options are effectively the same.

You are editing this transcript.

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