The operators in expressions are symbols that not only let you connect data values together but also determine how the values work together to convert the data source. The following types of operators are permitted in your expressions:
- Mathematical operators
- Relational operators
- Boolean operators
To access these operators, click the Mathematical Functions button on the Expression Builder dialog box and select them from the expanded operator keypad. You can also add numerals to your expressions by clicking the appropriate numeral in the Numeric area.
In addition to these operators, the Expression Builder allows you to select a set of functions. These functions are not shown on the expanded operator keypad and must be entered manually. The following table summarizes the available functions and their syntax. All trigonometric functions require values entered in radians.
When you select the function... |
The Expression Builder calculates the... |
Syntax |
ABS |
Absolute value of number. |
ABS (number) |
ACOS |
Arccosine of number. |
ACOS (number) |
ASIN |
Arcsine of number. |
ASIN (number) |
ATAN |
Arctangent of number. |
ATAN (number) |
COS |
Cosine of number. |
COS (number) |
EXP |
Anti-log of number. |
EXP (number) |
INT |
Integer value of number. |
INT (number) |
LOG |
Natural log of number. |
LOG (number) |
LOG10 |
Base 10 log of number. |
LOG10 (number) |
SIN |
Sine of number. |
SIN (number) |
SQRT |
Square root of the number. |
SQRT (number) |
TAN |
Tangent of number. |
TAN (number) |
For more information on these functions, refer to the Working with Functions section in the Creating Recipes manual.
The operators and their associated syntax are described in the following sections with examples of each.
Mathematical Operators
Mathematical operators let you add, subtract, multiply, and divide two or more values. Using these operators, you can create a mathematical expression. You can also change the operator's order of precedence in the mathematical expression by using parentheses.
Mathematical expressions are evaluated by determining the data value on each side of the mathematical operator and then performing the mathematical operation. For example, consider the following expression:
5+Fix32.SCADA1.AI1.F_CV
When this expression is evaluated, the current value of the iFIX tag AI1 is determined and then it is added to 5. If the value is 50, for example, the expression evaluates to 55.
Because of the way the expressions are evaluated, the values on both sides of an operator must both be either a numeric value or a string, but not one of each. You cannot, for example, add the descriptive string "Pump1 for Main Water Supply" to the data source Fix32.SCADA1.AI1.F_CV. However, you can add that same string to the data source Fix32.SCADA1.AI1.A_DESC.
Syntax: Mathematical Operators
The syntax for each mathematical operator in provided in the following table:
Operator |
Syntax |
+ (addition) |
value + value |
- (subtraction) |
value -value |
* (multiplication) |
value * value |
/ (division) |
value / value |
( (left parenthesis) |
(value + value) * value |
) (right parenthesis) |
(value + value) * value |
Example: Mathematical Operators
Consider the following expressions:
Expression |
Value |
5+Fix32.SCADA1.AI1.F_CV |
The current value of AI1 plus 5. If AI5 is 100, the expression evaluates to 105. |
"5"+Fix32.SCADA1.AI1.A_CV |
The current value of AI1 and the string "5" concatenated together. If AI1 is 100, the expression evaluates to 1005. |
Fix32.SCADA1.AI5.F_CV*OPC1.N35 |
The product of the iFIX tag AI1 and the I/O address N35. If the tag's value is 100, and the I/O point's value is 50, the expression evaluates to 5000. |
Alarms.Rect1.Width/Alarms.Rect1.Height |
The quotient of Rect1's width divided by its height. If both properties are equal, the expression evaluates to 1. |
Alarms.Pump5.HorizontalFillPercentage + Fix32.SCADA1.AI1.F_CV |
The value of Pump5's HorizontalFillPercentage property plus the current value of the iFIX tag AI1. If the HorizontalFillPercentage property's value is 50 and AI1's value is 100, the expression evaluates to 150. |
Alarms.Prompt.Caption+"Enter tagname" |
The value of Prompt's Caption property and the string "Enter tagname" concatenated together. If the Caption property value is null, then the string evaluates to "Enter tagname". |
Relational Operators
Relational operators let you compare two values to determine how they relate to each other.
Syntax: Relational Operators
The syntax for relational operators is shown in the following table.
Operator |
Syntax |
= (equal to) |
value = value |
<> (not equal to) |
value <> value |
> (greater than) |
value > value |
< (less than) |
value < value |
>= (greater than or equal to) |
value >= value |
<= (less than or equal to) |
value <= value |
Example: Relational Operators
Relational operators are commonly used in boolean conditions to determine if part or all of an expression is true or false. An example:
Fix32.SCADA1.AI1.F_CV = 50
When this expression is evaluated, the value of the left side of the operator is compared to the right side. If the two values match, the condition is true. Otherwise, it is false.
You can compare any data value to any other data value. For example, consider the following boolean conditions:
Condition |
Value |
3>1 |
TRUE |
5 = "Enter tagname" |
FALSE |
Fix32.SCADA1.AI1.F_CV = 100 |
TRUE, if the current value of AI1 is 100. |
Fix32.SCADA1.AI1.F_CV >= OPC1.N35 |
TRUE, if the current value of AI1 is greater than OPC1.N35. |
Alarms.Rect1.Width = Alarms.Rect1.Height |
TRUE, if Rect1 is a square. |
Alarms.Prompt.Caption ="Enter tagname" |
TRUE, if the value of Prompt's Caption property is "Enter tagname". |
Boolean Operators
Boolean operators let you connect two or more boolean conditions.
Syntax: Boolean Operators
The syntax for each operator is listed in the following table.
Operator |
Syntax |
AND |
condition AND condition |
OR |
condition OR condition |
NOT |
NOT condition |
Example: AND Operator
The AND operator is used when both parts of the expression must be true. For example, suppose that in a factory, several ingredients need to be mixed together for up to 5 minutes while the mixture is being heated to 200 degrees. When both of these conditions (5 minutes and 200 degrees) are true, you want to create an expression to display the following text:
Mixing...
To accomplish these tasks, a rectangle object, MixTime, has been set up as a progress bar to show the time elapsed as a percentage. A text object, Temperature, has also been animated to show the current temperature.
Next, a text object needs to be created for the Mixing message. This object needs its Visible property animated with the following expression:
Mixing.MixTime.VerticalFillPercentage < 100 AND Mixing.Temperature.AnimatedCaption.InputValue < 200
This expression is true only when the mixing time is less than 5 minutes and the temperature is less than 200 degrees. When either condition is no longer true, the mixer stops and the message is no longer visible.
Example: OR Operator
Now suppose you want to display instructions to the operator about the next stage of the process when mixing stops. To do this, you can create another text object and animate its Visible property with the following expression:
Mixing.MixTime.VerticalFillPercentage >= 100 OR Mixing.Temperature.AnimatedCaption.InputValue >= 200
Example: NOT Operator
Unlike AND or OR, the NOT operator does not connect two boolean conditions. Instead, it inverts the value of a condition. For example, if the following condition is true:
Alarms.Tank3.HorizontalFillPercentage>80
then the following condition is false:
NOT Alarms.Tank3.HorizontalFillPercentage>80
Changing the Order of Precedence
When evaluating an expression, iFIX defines an order of precedence for each operator. The order of precedence determines which operators (and the values on each side of the operator) are evaluated first. The following table lists each operator from highest to lowest precedence.
Operator |
Precedence |
( ), NOT, - (unary minus) |
1 |
*, /, AND |
2 |
+, - (subtraction), OR |
3 |
<, <=, >, >= |
4 |
=, <> |
5 |
You can change the order of precedence by enclosing an expression in parentheses. Parentheses are regarded with the highest priority; thus all expressions within the parentheses are evaluated first. Operators with the same precedence are evaluated in the order they appear from left to right.
Example: Changing the Order of Precedence
For example, consider the following expressions:
Expression |
Value |
6+4/2 |
8 |
(6+4)/2 |
5 |
Bit Operators for Expressions
The GETBIT function allows for bit-level manipulations of data. The GETBIT function has the following syntax:
GETBIT ( nBitNumber nNumberBits uiSourceToken )
You can enter comma to spearate the arguments, but you must have a space between the arguments to separate them.
The source token is promoted to the closest unsigned integer data representation that maintains its length. The corresponding zero based range of bits (bit zero is the most significant bit) is extracted from the source and an integer is returned which corresponds to the value these bits define if they existed starting in the least significant bit of their own integer. For example:
GETBIT ( 8 4 N.T.F )
IMPORTANT: Be aware that you must have spaces in between the operator and operands in expressions.