Basics
Core syntax of the TapHome scripting language — association, multi-line algorithms, return values, variables, IF/ELSE, SWITCH, loops, NaN, comments, numeric literals, and mathematical/logical expressions.
Association
Mu := Se + 2;Multi-line algorithm
Each line is divided by semicolon
Last := Current;
Current := 0;Returned value
- Result of last line of code
- RETURN(expression) stops execution of algorighm and returns content inside brackets
(Co2 > 800) AND (Wind < 10);
equals:
RETURN((CO2 > 800) and (Wind < 10));Temporary variable
Lives within the single execution of the script.
VAR X := 5;IF clause
Excel style
IF(logical_expression, value_if_true, value_if_false);
IF(logical_expression, value_if_true);Multi-line style
IF X < 5
RETURN(1);
ELSEIF X > 10
RETURN(3);
ELSE
RETURN(0);
ENDSwitch
Tests an expression against a list of cases and returns the corresponding value of the first matching case, with a default value if nothing else is met.
SWITCH(expression, case1, value1, [case2, ...], [value2, ...], default_value)Example:
SWITCH( MODBUSR(H, 168, UInt16),
0, 0,
0x0002, 1,
0x0004, 2,
0x0008, 3,
0x0010, 4,
0x0040, 5,
0x0800, 6,
NaN)
Loop
LOOP / WHILE … repeats a series of commands based on a specified condition until that condition is met. CONTINUE … skips the execution of commands and continues to the next cycle. BREAK … terminates the loop.
Example with condition at the beginning:
int i := 10;
while i > 0
i := i - 1;
if i > 5
continue;
else
break;
end
loopExample with condition at the end:
int i := 10;
do
i := i + i;
loop while i < 10NaN (not a number) value
NaN can be returned as a value in case real value is not known.
IF Temperature > 250
RETURN(NaN);ISNAN(expression) function Returns TRUE if expression is not a number.
ISNULL
Returns true if the parameter is NULL, false otherwise. Used for String and Bytearray types. Example: if XML element is not found, returned value ISNULL.
The syntax of the function is:
ISNULL(object)Sleep
Sleeps the script for number of miliseconds. Use only in very specific cases.
SLEEP(5);Comments
New line starting with character #
# commentNumeric literals
Hexadecimal numbers
Expressions can also interpret hexadecimal numbers. Prefix 0x is required and the rest is not case sensitive.
0x0A = 10
0xA0A0 (41120)
0xa0a0 (41120)Binary numbers
0b1010 = 10
0b10101010 (170)Mathematical expressions
+, -, *, /
(20.5 + 9.5) / 2 (15)Logical expressions
AND, OR, !, =, !=, >, <
(!IsRaining OR (Wind>30))
MultiValueSwitchState != 2 (Not equal to 2)