Mastering Forge #17: Mapping Variables Using Expressions

Welcome to the 17th tutorial on our series Mastering Forge.

In our previous article, Mastering Forge #16, we demonstrated Forge’s role-based user management capabilities.

Back in our Mastering Forge #4 tutorial we briefly covered Advanced Mapping like Offset, Scale, Split array and Bit Read. In this tutorial, we’ll take it a step further by introducing the new Expression feature in Advanced Mapping. This feature lets you define a variable’s value using custom formulas and logic. You can perform arithmetic operations across multiple nodes, apply conditional if-else statements based on node values, and more—all using JEXL syntax.

If you prefer your tutorials in video format instead, you can watch our tutorial on Forge’s Expressions feature on our YouTube channel.

During this tutorial, we’ll be using the following products:

Example 1: Sum of Variables

In this example, we’ll create our first expression, which is a simple sum of two variables.

1. Navigate to Forge’s Address Space and search for an unused variable for the Expression. We’ll use the variable MyKitchen/MyCoffee/Parameters/BoilerTempWater that was introduced in our earlier tutorials. Right-click the variable and press Expression.

Example Select Expression

2. Start by writing the expression

  • Create a formula that sums two variables, a + b. The variable names can be chosen freely.
  • Map both variables to Simulation Server variables by clicking the search icons. Select Sinusoid for variable a and Sawtooth for variable b.
  • Finally, click Save.
Example Define Expression

3. You can check that the Expression works by opening Prosys OPC UA Browser, right-clicking the used variables and selecting Monitor Data. The value of BoilerTempWater should now be the sum of the previously defined two variables.

Checking results example 1

Example 2: If-else Statement

In our second example, we’ll define a simple alarm mechanism using if-else statements. If a certain value reaches an alarm threshold, the alarm variable is set to true.

1. Create a boolean variable named Alarm_1 under MyKitchen/MyCoffee/ErrorConditions. We’ll create the Expression for this variable.

2. Define the expression as in the image below. Select variable a to be Sinusoid from Simulation Server and click Save.

Define expression example 2

3. Start monitoring Alarm_1 variable in Browser. The boolean value should be true when Sinusoid is greater than 1. Otherwise it should be false.

Checking results example 2

Next Steps

This wraps up the 17th article of the Mastering Forge series. Here’s a recap of what we did in this tutorial:

  1. Created a simple Expression where a variable received the sum of two other variables as its value.
  2. Defined a second Expression that used an if-else condition to determine the state of a boolean variable depending on a float variable’s value.
 

In the next article, we’ll explore the Event Mapper module, which allows you to extract and map data from events for further use.

If you want to learn more about Forge and its capabilities, you can request a detailed introduction by emailing sales@prosysopc.com or using our contact form. We’d be delighted to provide tailored information about Forge that aligns with your interests and requirements.

A headshot of Iivo Yrjölä

Iivo Yrjölä

Customer Integration & Support, Prosys OPC

Email: iivo.yrjola@prosysopc.com

Related Posts

Interested in this topic?

Get updated about new posts through our newsletter!
Scroll to Top