Expressions
The scripting language has two types of expressions: mathematical and boolean expressions. These are discussed below.
Mathematical expressions
Mathematical expressions involve variables, constants, operators and functions.
The variables and constants can be of type integer, floating point or field.
The value, timestamp and quality properties of fields are affected by mathematical operators. The mathematical operators are:
These operators perform mathematical calculations on arguments of integer and floating point type.
When the operators are applied to variables of field type, the value, timestamp and quality is calculated as follows.
-
Value - Calculated using the operator and the 2 arguments
-
timestamp - The latest timestamp of the 2 arguments are used
-
Quality - The worst quality of the 2 arguments are used
Some of the operators may also be applied to arguments of type time and duration. The tables list the arguments and the result of the operator. The rows lists the type of the first argument and the columns the type of the second argument.
Thus according to the Add table below, when we add time and duration we will get time (e.g. triggerTime := now + 1:00:00.)
For the add and subtract operators with one numeric argument and the other argument either of type time or duration, the numeric argument is treated as a duration in milliseconds.
Example
// Result is a time 5 milliseconds later than the timestamp of input1
futureTime := input1.timestamp + 5
// Total duration is 1 minute and 10 milliseconds
duration := 1:00 + 10
Example
// duration is 5 times longer than dur1
duration := dur1 * 5
// x is a floating point value such that duration1 := duration2 * x
x := duration1 / duration2
Boolean expressions
Boolean expressions are constructed from variables, relational operators and logical operators:
When comparing numeric expressions with a duration expression the numeric expression is interpreted as a duration in milliseconds. This is the same as with the add and subtract operators.
Note : When used with field arguments the operators only return true when both arguments have good quality. This is because when the values are invalid when the quality is bad and the operators cannot calculate a result.
Consider the statement
if inputField1 = inputField2 then
// True statements
else
// False statements
endif
The 'True statements' will only be executed when the values are equal and both qualities are good. The 'False statements' will be executed in any other condition. This includes the condition when the values are equal and one of the qualities is bad.
<, <=, > and >= cannot be used with boolean and quality type expressions.
The logical operators only work with boolean arguments.
Example
tooShort := duration < 5 // true if duration is less than 5 milliseconds
if not tooShort then output1 := 0.0 endif
Related topics: