LESSON

Expression Tags

Description

Expression Tags use Ignition's expression language to derive a value. They are useful when referencing another Tag's value, or when you simply need to apply some conditional logic to your Tags.

Video recorded using: Ignition 8.1

Transcript

(open in window)

[00:00] In this lesson, we'll cover expression tags. Expression tags utilize Ignition's expression language, to derive their value. This OPC tag in my tag browser is bringing in a temperature reading in degrees Celsius. I can write an expression using ignition expression language that will take my Celsius temperature reading, and convert it to Fahrenheit. I will begin by right clicking anywhere in the tag browser, going down to new tag and creating a new standard expression tag. I will name this tag temp F for Fahrenheit, and I will set a stat type to float. Similar to how an OPC tag needs an OPC item path to figure out which device connection to pull its value from, an expression tag needs an expression. To write our expression, I can edit the tags expression property by clicking on the pencil icon here. This will bring up the expression editor. If I type three times 423 and hit commit down below, I see that my expression gets assigned to the tag. What I mean by this is if I hit okay, my tag will show my evaluated expression value which is 1269.

[01:06] Let's modify the expression so that it takes in my Celsius temperature tags value and converts it to Fahrenheit. I will double click on our expression tag to bring up the tag editor again, and modify our expression like so. Here, my expression has 32 to the product of C and nine over five. I need to replace C with my Celsius temperature tag, so I will delete C and press on the tag icon here on the right. This allows me to bring in whatever tag value I wanted to my expression. I will drill down to my Celsius temperature tag and click okay. Now my expression is complete. I will commit and press okay to finish my configuration, and we can see that now my tag shows the converted temperature value. Every time my OPC time value changes, it causes our expression to evaluate, and therefore we will have a Fahrenheit convert its temperature for every Celsius temperature value you get from OPC. This is one of the main reasons why you would want to use an expression tag.

[02:01] If you want to store calculation in that tag and perhaps use other tag values in your calculations, expression tags are the way to go. Now let's go back to our Fahrenheit tag's configuration. We can see that there's an execution mode property. Now, full descriptions of these will be in our user manual, but you have three options right now, event driven, the top item there, basically means that there's something inside of the expression that's going to change. We want to run this expression whenever that changes. So in this case, the value of our temp C tag is changing, which is dragging the expression tags execution. You can also set it to fixed rate, the middle option here, which allows you to determine how often this tag should update using an execution rate. Finally, you can select a tag group. This means that this tags execution will follow the execution rules outlined by the tag you have configured above. So really there's three ways to determine how to update the value of this one tag. Expression tags are very powerful because you can define an expression to be whatever you want. Ignitions expression language allows you to run Python scripts from an expression.

[03:04] Similarly expressions also allow you to run SQL queries from an expression. This coupled with an ample list of expression functions makes expression tags the most versatile of all tag types.

You are editing this transcript.

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