How to use Variables in Expressions
Normally, when using a variable in an expression, you simply include the variable name in the expression. For example:
EXP(LOG(INLET.PRESSURE)/2)
Where INLET.PRESSURE is the variable name.
However, some variations are useful to know.
Using variable attributes in an expression
In addition to using variable values, you can also use extended attributes in an expression. To use an extended attribute you append the attribute reference to the variable name as follows.
- To use a text attribute you append :An where n is the numeric reference of the text attribute. Example @MYBRANCH.MYVAR:A3
- To use a binary attribute you append :Bn where n is the numeric reference of the binary attribute. Example @MYBRANCH.MYVAR:B1
Using the ?.VarName syntax
Unless prefixed with the @ character, variable names that you include in an expression are relative to any branch being used. However, it is possible to reference variables starting back from the root of the branch hierarchy by using the ?.VarName syntax. For example, the expression is used with the branch ProcessB.Machine2.Engine1 but you need to use the variable ProcessB.NumRunning. In that case, you can use ?.NumRunning in the expression. The question mark tells the expression engine to start from the root level in the branch hierarchy when resolving the variable name and in this example, it would result in the variable name ProcessB.NumRunning being used in the expression at run-time.
You can use more question marks to address all intermediate levels in the branch hierarchy. For example, ?.?.?.VarName would go down three levels from the root.
Using the square bracket [] syntax
A variable name must be enclosed in square brackets if it starts with a number, includes a special character such as the * (star) or starts with a reserved string (such as TS_Local or TS_Utc). This is so that the Expression Engine correctly interprets it as a variable name and is useful when you need to use alarm counters or other variables that do not strictly follow the variable naming rules in expressions.
For example:
If 01_BranchXYZ.Var1 and 01_BranchXYZ.Var2 are 2 variables in a project, an expression such as [01_BranchXYZ.Var1] + [01_BranchXYZ.Var2] will be parsed properly by the expression engine whereas 01_BranchXYZ.Var1 + 01_BranchXYZ.Var2 will cause a failure.