Each of the OT channel upload message actions can use a conditional expression to decide whether the message is forwarded or not. If a conditional expression is being used then as soon as a message arrives at the OT bus stop for processing, the bus stop will evaluate the expression and only carry out the action if the result is positive.
To use a conditional expression select only if in the Execute parameter when editing the action.
A C# .NET interpreter is used to parse and evaluate condition expressions. That means there are some restrictions:
Evaluation is performed in a separate domain space and is restricted only for System assembly.
There is no possibility to declare variables, methods or classes and it is forbidden to interact with OT bus stop models.
Channel message tag references and bus stop variables act as variables.
Variables (tags or bus stop variables) need to be wrapped in square brackets, bus stop variable are prefixed by ‘@’.
Tag variable example [TagName1], [TagName2].
Bus Stop variable example [@BV1], [@BV2].
The data type of the variable is very important. When writing a comparison the data type on the left side needs to be the same as date type on right side.
For example, if the variable [Tag1] is an integer then a numerical constant or integer tag type must be used on the right side:
[Tag1]==10
[Tag1]>500
[Tag1] <= 3.259
If the variable is string or date time type, the logic is the same:
[TagDateTime1]>DateTime.Parse(16/5/2018)
[TagDateTime1].Second %2 == 1 is equivalent to DateTime.Parse([TagDateTime1].ToString()).Second % 2 == 1
We can also combine more variables of different data types.
([TagDateTime1].Hour == 8 && [Tag2]>500) || [Tag3]==Active
Besides standard math operators (+-*/) .NET math assembly is fully supported.
Example of using a math function:
Math.Pow([Tag1],2)+ [Tag1]>5
100+Math.Abs([Tag1]) == 110
Math.Sqrt([Tag1]*100)<3
You can combine various data types to produce a formatted string and compare it with some constant. In the following examples all tags have a string data type:
Example 1
string.Concat([Var1],[Var2]) == HelloWord
Tag Var1 equals "Hello", tag Var2 equals "World".
Result: "HelloWorld" == "HelloWorld" (the action will be processed)
Example 2
[Var1]+[Var2].ToString() == Egg count: 5
Tag Var1 equals "Egg count: ", tag Var2 equals 15 (number, integer).
Result: "Eggs count: 15" == "Eggs count: 5" (the action will NOT be processed)
Can we improve this topic?