Expressions / Script language

TapHome Icon

Multi-line scripting language with syntax highlighting, usable in smart rules Equation, Formula and Script, and also in Modbus and Packet parser interfaces.

Syntax Highlighting Example

Basics

Association

1
Mu := Se + 2;

Multi-line algorithm

Each line is divided by semicolon

1
2
Last := Current;
Current := 0;

Returned value

  • Result of last line of code
  • RETURN(expression) stops execution of algorighm and returns content inside brackets
1
2
3
(Co2 > 800) AND (Wind < 10);
equals:
RETURN((CO2 > 800) and (Wind < 10));

Temporary variable

Lives within the single execution of the script.

1
VAR X := 5;

IF clause

Excel style

1
2
IF(logical_expression, value_if_true, value_if_false);
IF(logical_expression, value_if_true);

Multi-line style

1
2
3
4
5
6
7
IF X < 5
  RETURN(1);
ELSEIF X > 10
  RETURN(3);
ELSE
  RETURN(0);
END

Switch

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.

1
SWITCH(expression, case1, value1, [case2, ...], [value2, ...], default_value)

Example:

1
2
3
4
5
6
7
8
9
SWITCH( MODBUSR(H, 168, UInt16),
  0, 0,
  0x0002, 1,
  0x0004, 2,
  0x0008, 3,
  0x0010, 4,
  0x0040, 5,
  0x0800, 6,
  NaN)
SWITCH Example

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
int i := 10;
while i > 0
    i := i - 1;
    
    if i > 5
        continue;
    else
        break;
    end
loop

Example with condition at the end:

1
2
3
4
int i := 10;
do
    i := i + i;
loop while i < 10

NaN (not a number) value

NaN can be returned as a value in case real value is not known.

1
2
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:

1
ISNULL(object)

Sleep

Sleeps the script for number of miliseconds. Use only in very specific cases.

1
SLEEP(5);

Comments

New line starting with character #

1
# comment

Numeric literals

Hexadecimal numbers

Expressions can also interpret hexadecimal numbers. Prefix 0x is required and the rest is not case sensitive.

0x0A = 10

1
2
0xA0A0   (41120)
0xa0a0   (41120)

Binary numbers

0b1010 = 10

1
0b10101010   (170)

Mathematical expressions

+, -, *, /

1
(20.5 + 9.5) / 2    (15)

Logical expressions

AND, OR, !, =, !=, >, <

1
2
(!IsRaining OR (Wind>30))
MultiValueSwitchState != 2 (Not equal to 2)

Functions

LINEAR

Returns linearly adjusted value – linear interpolation.

1
LINEAR(input, value1_input, value1_output, value2_input, value2_output, [type])

Parameters - input… input value - value1_input… value at the input at the lower limit - value1_output… value at the output at the lower limit - value2_input… value at the input at the upper limit - value2_output… value at the output at the upper limit - [type]… optional parameter. Defines what the result should be when the input value is out of range value1_input ↔︎ value2_input: - without parameter (same as with parameter BOUNDS)… If the input value is outside the defined range, the output value will be one of the extremes (minimum or maximum) - INFINITE… If the input value is outside the defined range, the result is an extrapolated value - STRICT… If the input value is outside the defined range, the output value will be NaN (not a number)

LINEAR Function Graph

Examples

1
2
3
4
5
Example 1: LINEAR(250,  0,0,  50,500)   (Result is 25°C)

Example 2: LINEAR(Co2,  400,0,  1200,1)
          (If value from Co2 sensor is 400ppm, output for air recovery will be 0%. 
           If Co2 is 1200, output will be 100%. And if e.g. Co2=800, output will be 50%)

Examples for different [type] attributes: - input = 11 - value1_input = 0, value1_output = 400 - value2_input = 10, value2_output = 2000 - result for different [type] parameters: - BOUNDS (default value) = 2000 - INFINITE = 2160 - STRICT = NaN

HYSTERESIS

Hysteresis can be used to filter signals so that the output reacts less rapidly than it otherwise would by taking recent system history into account. For example, a thermostat controlling a heater may switch the heater on when the temperature drops below A, but not turn it off until the temperature rises above B.

Returns 0 or 1.

1
HYSTERESIS(value, upper_bound, lower_bound, upper_output, lower_output, last_value)

Example: maintain a temperature of 20 °C within 2 ºC hysteresis range. Turn the heater on when the temperature drops to below 18 °C and off when the temperature exceeds 22 °C).

1
heater := HYSTERESIS(temperature,   22, 18,   0, 1,   heater);

Mathematical functions

MIN

The MIN function returns the minimum of the provided numeric values. It accepts between 1 and 100 arguments or a single collection. NaN and NULL values are ignored.

1
2
MIN( n1, n2, n3, …)
MIN( collection )

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
MIN(40, 80)  		= 40
MIN(2, 2, 6) 		= 2
MIN(80, NAN)		= 80
MIN(NAN, NAN)		= NaN

VAR data := {10, 20, 30}; MIN(data) 	= 10
MIN({1, 2, 3})							= 1
MIN({1, NaN, 3})						= 1

VAR d1 := DATETIME(2014, 12, 8, 0, 0, 0, 0, DateTimeKind.Utc);
VAR d2 := DATETIME(2015, 12, 8, 0, 0, 0, 0, DateTimeKind.Utc);
MIN(d1, d2)			... Result is d1

MINSTRICT

The MINSTRICT function returns the minimum of the provided numeric values. It accepts between 1 and 100 arguments or a single collection. If any of the provided values is NaN or NULL, the function returns NaN/NULL.

1
2
MINSTRICT( n1, n2, n3, …)
MINSTRICT( collection )

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
MINSTRICT(40, 80)  		= 40
MINSTRICT(2, 2, 6) 		= 2
MINSTRICT(80, NAN)		= NaN
MINSTRICT(NAN, NAN)		= NaN

VAR data := {10, 20, 30}; MINSTRICT(data) 	= 10
MINSTRICT({1, 2, 3})						= 1
MINSTRICT({1, NaN, 3})						= NaN

VAR d1 := DATETIME(2014, 12, 8, 0, 0, 0, 0, DateTimeKind.Utc);
VAR d2 := DATETIME(2015, 12, 8, 0, 0, 0, 0, DateTimeKind.Utc);
MINSTRICT(d1, NULL, d2)		... Result is NULL

MAX

The MAX function returns the maximum of the provided numeric values. It accepts between 1 and 100 arguments or a single collection. NaN and NULL values are ignored.

1
2
MAX( n1, n2, n3, …)
MAX( collection )

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
MAX(40, 80)  			= 80
MAX(2, 2, 6) 			= 6
MAX(80, NAN)			= 80
MAX(NAN, NAN)			= NaN

VAR data := {10, 20, 30}; MAX(data) = 30
MAX({1, 2, 3})						= 3
MAX({1, NaN, 3})					= 3

VAR d1 := DATETIME(2014, 12, 8, 0, 0, 0, 0, DateTimeKind.Utc);
VAR d2 := DATETIME(2015, 12, 8, 0, 0, 0, 0, DateTimeKind.Utc);
MAX(d1, d2)				... Result is d2

MAXSTRICT

The MAXSTRICT function returns the maximum of the provided numeric values. It accepts between 1 and 100 arguments or a single collection. If any of the provided values is NaN or NULL, the function returns NaN/NULL.

1
2
MAXSTRICT( n1, n2, n3, …)
MAXSTRICT( collection )

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
MAXSTRICT(40, 80)  			= 80
MAXSTRICT(2, 2, 6) 			= 6
MAXSTRICT(80, NAN)			= NaN
MAXSTRICT(NAN, NAN)			= NaN

VAR data := {10, 20, 30}; MAXSTRICT(data) 	= 30
MAXSTRICT({1, 2, 3})				= 3
MAXSTRICT({1, NaN, 3})				= NaN

VAR d1 := DATETIME(2014, 12, 8, 0, 0, 0, 0, DateTimeKind.Utc);
VAR d2 := DATETIME(2015, 12, 8, 0, 0, 0, 0, DateTimeKind.Utc);
MAXSTRICT(d1, NULL, d2)		... Result is NULL

AVG

The AVG function calculates the average (mean) of the provided numeric values. It accepts between 1 and 100 arguments or a single collection. NaN values are ignored.

1
2
AVG( n1, n2, n3, …)
AVG( collection )

Examples:

1
2
3
4
5
6
7
8
9
AVG(40, 80)  		= 60
AVG(2, 2, 6) 		= 3.3333
AVG(80, NAN)		= 80
AVG(‘a’, ‘c’)		= ‘b’
AVG(NAN, NAN)		= NaN

VAR data := {10, 20, 30}; AVG(data) 	= 20
AVG({1, 2, 3})							= 2
AVG({1, NaN, 3})						= 2

AVGSTRICT

The AVGSTRICT function calculates the average (mean) of the provided numeric values. It accepts between 1 and 100 arguments or a single collection. If any of the provided values is not a number, the function returns NaN.

1
2
AVGSTRICT( n1, n2, n3, …)
AVGSTRICT( collection )

Examples:

1
2
3
4
5
6
7
8
AVGSTRICT(40, 80)  		= 60
AVGSTRICT(2, 2, 6) 		= 3.3333
AVGSTRICT(80, NAN)		= NaN
AVGSTRICT(NAN, NAN)		= NaN

VAR data := {10, 20, 30}; AVGSTRICT(data) 	= 20
AVGSTRICT({1, 2, 3})						= 2
AVGSTRICT({1, NaN, 3})						= NaN

ROUND

1
ROUND(value1)    

Returns the rounded value.

1
2
3
4
Example 1: ROUND(2.01)   (Result is 2)
Example 2: ROUND(2.49)   (Result is 2)
Example 3: ROUND(2.5)   (Result is 3)
Example 4: ROUND(2.99)   (Result is 3)

ABS

The ABS function returns the absolute value (i.e. the modulus) of any supplied number.

1
ABS(number)

Examples:

1
2
ABS(100)  ...   100
ABS(-100)   ...   100

DEWPOINT

1
DEWPOINT(temperature, relativeHumidity)

Returns the dew point temperature given the current temperature and relative humidity. Dew point is calculated according to this equation.

1
2
Example 1: DEWPOINT(20, 0.50) (Result is ~9.26)
Example 2: DEWPOINT(0, 1.00) (Result is 0)

POWER

The POWER function calculates a given number, raised to a supplied power.

1
POWER(number, power)

Examples:

  • POWER(2,3) … 2^3 = 8
  • POWER(10, -3) … 0,001
  • POWER(25, 0) … 1

MOD

The MOD function returns the remainder of a division between two supplied numbers.

1
MOD(number, divisor)

Arguments:

  • number - The number to be divided.
  • divisor - The value that the number argument is divided by.

Examples:

  • MOD(6, 4)  … 2
  • MOD(6, 2.5) … 1

CEIL

The CEIL function rounds a supplied number away from zero, to the nearest multiple of a given number.

1
CEIL(number, significance)

Arguments:

  • number   - The number that is to be rounded.
  • significance (optional) - The multiple of significance that the supplied number should be rounded to. If the significance is not specified, then it is equal to 1. (This should generally have the same arithmetic sign (positive or negative) as the supplied number argument)

Examples:

  • CEIL(22.25,0.1) … 22.3
  • CEIL(22.25,1) … 23
  • CEIL(22.25) … 23
  • CEIL(-22.25,-1) … -23
  • CEIL(-22.25,1) … -22
  • CEIL(-22.25) … -22
  • CEIL(-22.25,-5) … -25

FLOOR

The FLOOR function rounds a supplied number towards zero to the nearest multiple of a specified significance.

1
FLOOR(number, significance)

Arguments:

  • number - The number that is to be rounded.
  • significance (optional) -The multiple of significance that the supplied number is to be rounded to. If the significance is not specified, then it is equal to 1. (This should generally have the same arithmetic sign (positive or negative) as the supplied number argument)

Examples:

  • FLOOR(22.25,0.1)… 22.2
  • FLOOR(22.25,1) … 22
  • FLOOR(22.25) … 22
  • FLOOR(-22.25,-1) … -22
  • FLOOR(-22.25,1) … -23
  • FLOOR(-22.25) … -23
  • FLOOR(-22.25,-5) … -20

RAND

The Rand function generates a random real number between 0 and 1.

1
RAND()

Examples:

  • RAND()

RANDINT

The RANDINT function generates a random integer between two supplied integers.

1
RANDINT(bottom, top)

Examples:

  • RANDINT(1,5)
  • RANDINT(-2,2)

SIGN

The SIGN function returns the arithmetic sign (+1, -1 or 0) of a supplied number. I.e. if the number is positive, the SIGN function returns +1, if the number is negative, the function returns -1 and if the number is 0 (zero), the function returns 0.

1
SIGN(number)

Examples:

  • SIGN(100) … 1
  • SIGN(0) … 0
  • SIGN(-100) … -1

SQRT

The SQRT function calculates the positive square root of a supplied number.

1
SQRT(number)

Examples:

  • SQRT(25) … 5

LOG

The LOG function calculates the logarithm of a given number, to a supplied base.

1
LOG(number, base)

Arguments:

  • number - The positive real number that you want to calculate the logarithm of.
  • base (optional) - An optional argument that specifies the base to which the logarithm should be calculated. If the argument is not specified, then the base argument uses the default value 10.

Examples:

  • LOG(4,0.5) … -2
  • LOG(100) … 2

LN

The LN function calculates the natural logarithm of a given number.

1
LN(number)

where the number argument is the positive real number that you want to calculate the natural logarithm of.

Examples:

  • LN(100) … 4,60517

Bit operations

GETBIT

Returns a value of a bit in the specified position.

1
GETBIT(number, bit_position)

Arguments:

  • number - number to extract value of specific bit from
  • bit_position - position of bit, starting with 0, from right

Examples:

  • GETBIT(2, 0) → first bit of number 2 (0b0010) is 0
  • GETBIT(4,2) → third bit of number 4 (0b0100) is 1

GETBITS

Returns value of specified number of bits in the specified position.

1
GETBITS(number, start_bit, number_of_bits)

Examples:

  • GETBITS(216, 3, 2) → number 216 = 0b1101 1000; value of 4th bit from the right is 1, 5th bit is 1, therefore result is 0b0011 = 3
  • GETBITS(0xFF, 0, 4) → number 0xFF = 255 = 0b1111 1111; value of first 4 bits from right is 0b1111 = 0xF = 15

GETBYTE

Returns a value of a byte in the specified number.

1
GETBYTE( number, byte_position )

Arguments:

  • number - number to extract value of specific byte from
  • byte_position - position of byte, starting from 0, from right

Examples:

1
2
3
GETBYTE(256, 0)  →  0001 0000 0000 →  0
GETBYTE(256, 1)   →  0001 0000 0000  →  1
GETBYTE(259, 0)   →  0001 0000 0011   →  3

SETBYTE

Assigns a new value to the specified byte in the provided number, and returns assigned value.

1
SETBYTE( number, byte_position, new_value )

Examples:

1
2
3
4
SETBYTE(1, 0, 0)   →   0
SETBYTE(256, 0, 255)   →   511
SETBYTE(256, 1, 1)	  →   256
SETBYTE(259, 1, 2)	  →    515

SETBIT

Assigns a new value to the specified bit in the provided number and returns a new number.

1
SETBIT(number, bit_position, new_value)

Arguments:

  • number - number to be modified
  • bit_position - position of bit, starting with 0, from right
  • new_value - 0 or 1 - value that is going to be set to specified bit

Examples:

  • SETBIT(1, 1, 1) → 3
  • SETBIT(3, 1, 1) → 3
  • SETBIT(4, 2, 0) → 4
  • SETBIT(12, 1, 0) → 14

SETBITS

Assigns a new value to the specified bits in the provided number and returns a new number.

1
SETBITS(number, start_bit, number_of_bits, new_value)

Examples:

  • SETBITS(192, 4, 2, 3) → 240
  • SETBITS(192, 5, 2, 3) → 224

«   (LEFT BIT SHIFT)

1
8 << 2   (32)

Excel: BITLSHIFT(number, shift_amount)

» (RIGHT BIT SHIFT)

1
32 >> 2   (8)

Excel: BITRSHIFT(number, shift_amount)

& (BITWISE AND)

1
3 & 1   (1)

Excel: BITAND(number1, number2)

| (BITWISE OR)

1
2 | 1 (3)

Excel: BITOR(number1, number2)

See the example of bit operations in Google Sheets: https://docs.google.com/spreadsheets/d/1hF5FMpGMJbgYh-YLwWrq2n186_ATyGyLUb689__IhLY/edit?usp=sharing

Or try interactive tool at http://bitwisecmd.com/

Text, String and Byte array

LENGTH

Returns length of an object or number of bytes. Object can be a number, boolean, string or Collection.

1
LENGTH( object )

Examples:

1
2
3
4
LENGTH(“Hello World”)			(Result is 11)
LENGTH(“40”)				(Result is 2)
LENGTH(40)					(Result is 8)
LENGTH(BYTECOLLECTION(“010203”)	(Result is 3)

BYTECOLLECTION

Creates a Collection from specified hexadecimal values

1
BYTECOLLECTION( bytes )

Examples:

1
2
BYTECOLLECTION(“010203”) 				(Result is Collection<UInt8> {01, 02, 03})
BYTECOLLECTION(“aa, be1-1,fe”) 			(Result is Collection<UInt8> {aa be 11 fe})

INDEXOF

Returns index of specified element in string or collection. Returns -1 if element cannot be found.

1
INDEXOF( string/collection, element )

Examples:

1
2
3
4
5
6
INDEXOF("Hello", “H”)					(Result is 0)
INDEXOF("Hello World", “Wor”)				(Result is 6)
INDEXOF("Hello World", “Wor”)				(Result is 6)
INDEXOF("Hello World", “or12”)				(Result is -1)
INDEXOF(BYTECOLLECTION("ab cd ee ff 01 02"), 2)	(Result is 5)
INDEXOF({1, 2, 3}, 3)						(Result is 2)

COPY

Copies specified string or collection (or part of them)

1
COPY( string/collection, startIndex, length)

Examples:

1
2
3
4
5
COPY("Hello")					(Result is “Hello”)
COPY("Hello World", 2)				(Result is “llo World”)
COPY("Hello World", 2, 4)				(Result is “llo ”)
COPY(BYTEARRAY("01020304")			(Result is byte array 01020304)
COPY(BYTEARRAY("01020304", 2, 1)		(Result is byte array 03)

REPLACE

Returns a new string or collection, in which all occurrences of specified value are replaced with new value.

1
REPLACE( string/collection, oldValue, newValue)

Examples:

1
2
3
REPLACE("Hello", “l”, “”)				(Result is “Heo”)
REPLACE("Hello", “lo”, “22”)			(Result is “Hel22”)
REPLACE(BYTECOLLECTION(“050607"), 5, 9)	(Result is Collection<UInt8>{09, 06, 07}

SPLIT

Splits string to substrings based on separator parameters.

1
2
3
4
SPLIT( string, string )
SPLIT( string, char )
SPLIT( string, Collection<string> )
SPLIT( string, Collection<char> )

Examples:

1
2
3
SPLIT("1;2;3;4", “;”)			(Result is Collection<String>{“1”, “2”, “3”, “4”})
SPLIT("1;2;3.4", “2;”)		(Result is Collection<String>{“1;”, “3.4”})
SPLIT("1;2;3.4", {“2”, “3.”)		(Result is Collection<String>{“1;”, “;”, “4”})

COMPARE

Compare 2 strings and returns an integer that indicates their relative position in the sort order.

1
COMPARE( string, string, CompareOptions )

Examples:

1
2
3
COMPARE("abc", “abc”)						(Result is 0)
COMPARE("abc", “ABC”)						(Result is 32)
COMPARE("abc", “ABC”, CompareOptions.IgnoreCase)	(Result is 0)

APPEND

Append value to collection or string and returns new object with appended value.

1
2
APPEND( string, string )
APPEND( Collection, value )

Examples:

1
2
APPEND({1, 2}, 3)     (Result is Collection<Double>{1, 2, 3})
APPEND("abc", “def”)  (Result is “abcdef”)

INSERT

Insert value to collection or string. Returns collection or string with inserted value.

1
2
INSERT( collection, index, value )
INSERT( string, index, value )

Examples:

1
2
3
INSERT(“Hello”, 5, “ World”)      (Result is “Hello World”)
INSERT(“Hello”, 1, “i”)			  (Result is “Hiello”)
INSERT({1, 2, 4}, 2, 3)			  (Result is Collection<Double>{1, 2, 3, 4})

REMOVEAT

Remove elements from collection or string based on element index and length. Returns collection or string without specified elements.

1
2
REMOVEAT( collection, index, length )
REMOVEAT( string, index, length )

Examples:

1
2
3
4
REMOVEAT(“Hello”, 1)			(Result is “Hllo”)
REMOVEAT(“Hello”, 3, 2)			(Result is “Ho”)
REMOVEAT({1, 2, 3, 4}, 2)			(Result is Collection<Double>{1, 2, 4})
REMOVEAT({1, 2, 3, 4}, 2, 2)		(Result is Collection<Double>{1, 2})

GETAT

Get element value from collection or string based on provided index.

1
2
GETAT( collection, index )
GETAT( string, index )

Examples:

1
2
GETAT(“Hello”, 2)			(Result is “l”)
GETAT({1, 2, 4}, 2)			(Result is 4)

SETAT

Set element value in collection or string at provided index.

1
2
SETAT( collection, index, value )
SETAT( string, index, value )

Examples:

1
2
3
SETAT(“Hello”, 1, “a”)          (Result is “Hallo”)
SETAT(“Hello”, 4, “o World”)    (Result is “Hello World”)
SETAT({1, 2, 4}, 2, 3)          (Result is Collection<Double>{1, 2, 3})

ENCODE

Encodes specified string using on of the formats and returns the new string.

1
ENCODE( string, format )

Supported formats:

  • XML
  • Base64

Examples:

1
2
3
ENCODE("Hello", “xml”)				(Result is “Hello”)
ENCODE("<Hello id=1>", “xml”)		(Result is “&lt;Hello id=1&gt;”)
ENCODE("Hello", “base64”)			(Result is “SGVsbG8=”)

DECODE

Decodes specified string using one of the formats and returns the new string.

1
DECODE( string, format )

Supported formats:

  • XML
  • Base64

Examples:

1
2
3
DECODE("Hello", “xml”)				  (Result is “Hello”)
DECODE("&lt;Hello id=1&gt;", “xml”)   (Result is “<Hello id=1>”)
DECODE("SGVsbG8=", “base64”)		  (Result is “Hello”)

EQUALS

Compares two numbers with floating point. The numbers are considered to be equal if | n1 - n2 |< epsilon The default value of threshold (*epsilon) *is 0.005 and it is an optional parameter.

1
EQUALS( number1, number2, epsilon=0.005 )

Examples:

1
2
3
4
5
EQUALS(1.33, 1.33)          1.0 (true)
EQUALS(1.333, 1.3335)		1.0 (true)
EQUALS(1.333, 1.338)		1.0 (false)
EQUALS(1.333, 1.338, 0.01)	1.0 (true)
EQUALS(NAN, NAN)		    1.0 (true)

Sorting

There are multiple ORDER variants available: Ascending - ORDER, ORDERSTRICT - ORDERINDEX, ORDERINDEXSTRICT Descending - ORDERDESC, ORDERDESCSTRICT - ORDERINDEXDESC, ORDERINDEXDESCSTRICT

ORDER

The ORDER function sorts the provided input values in ascending order and returns them in a new collection. It accepts n values (up to 100 arguments) or a single collection. Values do not need to be numeric, but they must be comparable (e.g., numbers, TIMESPAN, DATETIME, strings). Mixed types (e.g., numbers and strings) are not allowed. NaN and NULL values are ignored and excluded from the returned collection.

1
2
ORDER( n1, n2, n3 , … )
ORDER( collection )

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ORDER(3, 1, 2)				= {1, 2, 3}
ORDER(1)					= {1}
ORDER(3, NaN, 2, NaN)		= {2, 3}
ORDER(NaN)					= {}
ORDER('Z', 'a', 'X')				= {'X', 'Z', 'a'}
ORDER(“str1”, “STR2”, “stR1”} 		= {"STR2", "stR1", "str1"}
ORDER(“str1”, NULL, “STR2”, “stR1”} = {"STR2", "stR1", "str1"}

ORDER(TIMESPAN(0,0,0,0,100), TIMESPAN(0,0,0,0,99)	= {TIMESPAN(0,0,0,0,99), TIMESPAN(0,0,0,0,100)}
ORDER(NULL, TIMESPAN(0,0,0,0,99)					= {TIMESPAN(0,0,0,0,99)}

ORDERINDEX

The ORDERINDEX function sorts the provided input values in ascending order, similar to the ORDER function. However, instead of returning the sorted values, it returns a collection of indexes indicating the positions of the original values in sorted order. It accepts n values (up to 100 arguments) or a single collection. Values do not need to be numeric, but they must be comparable (e.g., numbers, TIMESPAN, DATETIME, strings). Mixed types (e.g., numbers and strings) are not allowed. NaN and NULL values are ignored and excluded from the returned collection.

1
2
ORDERINDEX( n1, n2, n3 , … )
ORDERINDEX( collection )

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ORDERINDEX(3, 1, 2)				= {1, 2, 0}
ORDERINDEX(1)					= {0}
ORDERINDEX(3, NaN, 2, NaN)		= {2, 0}
ORDERINDEX(NaN)					= {}
ORDERINDEX('Z', 'a', 'X')				= {2, 0, 1}
ORDERINDEX(“str1”, “STR2”, “stR1”} 		= {1, 2, 0}
ORDERINDEX(“str1”, NULL, “STR2”, “stR1”} = {2, 3, 0}

ORDERINDEX(TIMESPAN(0,0,0,0,100), TIMESPAN(0,0,0,0,99)	= {1, 0}
ORDERINDEX(NULL, TIMESPAN(0,0,0,0,99)					= {1}

ORDERSTRICT

The ORDERSTRICT function sorts the provided input values in ascending order and returns them in a new collection. It accepts n values (up to 100 arguments) or a single collection. Values do not need to be numeric, but they must be comparable (e.g., numbers, TIMESPAN, DATETIME, strings). Mixed types (e.g., numbers and strings) are not allowed. NaN and NULL values are included and always sorted first in the result.

1
2
ORDERSTRICT( n1, n2, n3 , … )
ORDERSTRICT( collection )

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ORDERSTRICT(3, 1, 2)			= {1, 2, 3}
ORDERSTRICT(1)					= {1}
ORDERSTRICT(3, NaN, 2, NaN)		= {NaN, NaN, 2, 3}
ORDERSTRICT(NaN)				= {NaN}
ORDERSTRICT('Z', 'a', 'X')		= {'X', 'Z', 'a'}
ORDERSTRICT(“str1”, “STR2”, “stR1”} 		= {"STR2", "stR1", "str1"}
ORDERSTRICT(“str1”, NULL, “STR2”, “stR1”}	= {NULL, "STR2", "stR1", "str1"}

ORDERSTRICT(TIMESPAN(0,0,0,0,100), TIMESPAN(0,0,0,0,99)	= {TIMESPAN(0,0,0,0,99), TIMESPAN(0,0,0,0,100)}
ORDERSTRICT(NULL, TIMESPAN(0,0,0,0,99)					= {NULL, TIMESPAN(0,0,0,0,99)}

ORDERINDEXSTRICT

The ORDERINDEXSTRICT function sorts the provided input values in ascending order, similar to the ORDERSTRICT function. However, instead of returning the sorted values, it returns a collection of indexes indicating the positions of the original values in sorted order. It accepts n values (up to 100 arguments) or a single collection. Values do not need to be numeric, but they must be comparable (e.g., numbers, TIMESPAN, DATETIME, strings). Mixed types (e.g., numbers and strings) are not allowed. NaN and NULL values are included and always sorted first in the result.

1
2
ORDERINDEXSTRICT( n1, n2, n3 , … )
ORDERINDEXSTRICT( collection )

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ORDERINDEXSTRICT(3, 1, 2)				= {1, 2, 0}
ORDERINDEXSTRICT(1)						= {0}
ORDERINDEXSTRICT(3, NaN, 2, NaN)		= {1, 3, 2, 0}
ORDERINDEXSTRICT(NaN)					= {0}
ORDERINDEXSTRICT('Z', 'a', 'X')			= {2, 0, 1}
ORDERINDEXSTRICT(“str1”, “STR2”, “stR1”} 			= {1, 2, 0}
ORDERINDEXSTRICT(“str1”, NULL, “STR2”, “stR1”} 		= {1, 2, 3, 0}

ORDERINDEXSTRICT(TIMESPAN(0,0,0,0,100), TIMESPAN(0,0,0,0,99)	= {1, 0}
ORDERINDEXSTRICT(NULL, TIMESPAN(0,0,0,0,99)						= {0, 1}

ORDERDESC

The ORDERDESC function sorts the provided input values in descending order and returns them in a new collection. It accepts n values (up to 100 arguments) or a single collection. Values do not need to be numeric, but they must be comparable (e.g., numbers, TIMESPAN, DATETIME, strings). Mixed types (e.g., numbers and strings) are not allowed. NaN and NULL values are ignored and excluded from the returned collection.

1
2
ORDERDESC( n1, n2, n3 , … )
ORDERDESC( collection )

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ORDERDESC(3, 1, 2)					= {3, 2, 1}
ORDERDESC(1)						= {1}
ORDERDESC(3, NaN, 2, NaN)			= {3, 2}
ORDERDESC(NaN)						= {}
ORDERDESC('Z', 'a', 'X')			= {'a', 'Z', 'X'}
ORDERDESC(“str1”, “STR2”, “stR1”} 	= {"str1", "stR1", "STR2"}
ORDERDESC(“str1”, NULL, “STR2”, “stR1”} 	= {"str1", "stR1", "STR2"}

ORDERDESC(TIMESPAN(0,0,0,0,100), TIMESPAN(0,0,0,0,99)	= {TIMESPAN(0,0,0,0,100), TIMESPAN(0,0,0,0,99)}
ORDERDESC(NULL, TIMESPAN(0,0,0,0,99)					= {TIMESPAN(0,0,0,0,99)}

ORDERINDEXDESC

The ORDERINDEXDESC function sorts the provided input values in descending order, similar to the ORDERDESC function. However, instead of returning the sorted values, it returns a collection of indexes indicating the positions of the original values in sorted order. It accepts n values (up to 100 arguments) or a single collection. Values do not need to be numeric, but they must be comparable (e.g., numbers, TIMESPAN, DATETIME, strings). Mixed types (e.g., numbers and strings) are not allowed. NaN and NULL values are ignored and excluded from the returned collection.

1
2
ORDERINDEXDESC( n1, n2, n3 , … )
ORDERINDEXDESC( collection )

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ORDERINDEXDESC(3, 1, 2)				= {0, 2, 1}
ORDERINDEXDESC(1)					= {0}
ORDERINDEXDESC(3, NaN, 2)			= {0, 2}
ORDERINDEXDESC(NaN)					= {}
ORDERINDEXDESC('Z', 'a', 'X')					= {1, 0, 2}
ORDERINDEXDESC(“str1”, “STR2”, “stR1”} 			= {0, 2, 1}
ORDERINDEXDESC(“str1”, NULL, “STR2”, “stR1”} 	= {0, 3, 2}

ORDERINDEXDESC(TIMESPAN(0,0,0,0,100), TIMESPAN(0,0,0,0,99)	= {0, 1}
ORDERINDEXDESC(NULL, TIMESPAN(0,0,0,0,99)					= {1}

ORDERDESCSTRICT

The ORDERDESCSTRICT function sorts the provided input values in descending order and returns them in a new collection. It accepts n values (up to 100 arguments) or a single collection. Values do not need to be numeric, but they must be comparable (e.g., numbers, TIMESPAN, DATETIME, strings). Mixed types (e.g., numbers and strings) are not allowed. NaN and NULL values are included and always sorted first in the result.

1
2
ORDERDESCSTRICT( n1, n2, n3 , … )
ORDERDESCSTRICT( collection )

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ORDERDESCSTRICT(3, 1, 2)			= {3, 2, 1}
ORDERDESCSTRICT(1)					= {1}
ORDERDESCSTRICT(3, NaN, 2, NaN		= {NaN, NaN, 3, 2}
ORDERDESCSTRICT(NaN)				= {NaN}
ORDERDESCSTRICT('Z', 'a', 'X')					= {'a', 'Z', 'X'}
ORDERDESCSTRICT(“str1”, “STR2”, “stR1”} 		= {"str1", "stR1", "STR2"}
ORDERDESCSTRICT(“str1”, NULL, “STR2”, “stR1”} 	= {NULL, "str1", "stR1", "STR2"}

ORDERDESCSTRICT(TIMESPAN(0,0,0,0,100), TIMESPAN(0,0,0,0,99)	= {TIMESPAN(0,0,0,0,100), TIMESPAN(0,0,0,0,99)}
ORDERDESCSTRICT(NULL, TIMESPAN(0,0,0,0,99)					= {NULL, TIMESPAN(0,0,0,0,99)}

ORDERINDEXDESCSTRICT

The ORDERINDEXDESCSTRICT function sorts the provided input values in descending order, similar to the ORDERDESC function. However, instead of returning the sorted values, it returns a collection of indexes indicating the positions of the original values in sorted order. It accepts n values (up to 100 arguments) or a single collection. Values do not need to be numeric, but they must be comparable (e.g., numbers, TIMESPAN, DATETIME, strings). Mixed types (e.g., numbers and strings) are not allowed. NaN and NULL values are included and always sorted first in the result.

1
2
ORDERINDEXDESCSTRICT( n1, n2, n3 , … )
ORDERINDEXDESCSTRICT( collection )

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ORDERINDEXDESCSTRICT(3, 1, 2)				= {0, 2, 1}
ORDERINDEXDESCSTRICT(1)						= {0}
ORDERINDEXDESCSTRICT(3, NaN, 2, NaN)		= {1, 3, 0, 2}
ORDERINDEXDESCSTRICT(NaN)					= {0}
ORDERINDEXDESCSTRICT('Z', 'a', 'X')			= {1, 0, 2}
ORDERINDEXDESCSTRICT(“str1”, “STR2”, “stR1”}		= {0, 2, 1}
ORDERINDEXDESCSTRICT(“str1”, NULL, “STR2”, “stR1”} 	= {1, 0, 3, 2}

ORDERINDEXDESCSTRICT(TIMESPAN(0,0,0,0,100), TIMESPAN(0,0,0,0,99)	= {0, 1}
ORDERINDEXDESCSTRICT(NULL, TIMESPAN(0,0,0,0,99)						= {0, 1}

Date and time

DATETIME

Creates a DateTime object. DateTime.Ticks property is number of milliseconds from 1.1.0001 00:00:00.000. DateTime has properties: TICKS, YEAR, MONTH, DAY, DAYOFWEEK, DAYOFYEAR, HOUR, MINUTE, SECOND, MILLISECOND, KIND, UTCDATETIME, LOCALDATETIME, UNIXTIME

1
2
3
4
DATETIME( ticks, DateTimeKind )
DATETIME( string, format )
DATETIME( string, DateTimeKind )
DATETIME( year, month, day, hour, minute, second, millisecond, DateTimeKind  )

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
VAR date:= DATETIME(2014, 12, 8, 23, 54, 12, 456);
VAR date:= DATETIME(2014, 12, 8, 23, 54, 12, 456, DateTimeKind.Local);
VAR date:= DATETIME(2014, 12, 8, 23, 54, 12, 456, DateTimeKind.Utc);
VAR date:= DATETIME("13:36");
VAR date:= DATETIME("2022-08-03T07:39:03.688133+05:00");
VAR date:= DATETIME("03.01 2008 10:00"); 
VAR date:= DATETIME("mar.01 2008 10:00");
VAR date:= DATETIME("03.01 2008 10:00", "dd.MM yyyy hh:mm");
VAR date:= DATETIME(518832000);
VAR date:= DATETIME(518832000, DateTimeKind.Utc);
VAR date := NOW(); date.YEAR := 1999;
DATETIME date; date.UNIXTIME := 123456;

NOW

Returns DateTime object that is set to current date and time in local timezone.

1
NOW()

Examples:

1
VAR now := NOW();

TIMESPAN

The TIMESPAN function creates a variable that represents a duration of time, specified in terms of days, hours, minutes, seconds, and milliseconds. The TIMESPAN has properties to directly access each component of the timespan: DAYS, HOURS, MINUTES, SECONDS, MILLISECONDS. The TIMESPAN has properties to access the total value of time in specific units (including fractional values): TOTALDAYS, TOTALHOURS, TOTALMINUTES, TOTALSECONDS, TOTALMILLISECONDS

1
TIMESPAN( days, hours, minutes, seconds, milliseconds )

Examples:

1
2
3
4
VAR t := TimeSpan(1, 2, 3, 4, 0);
	t.TOTALSECONDS			

Result ... 93784

LOCALTIMEZONE

Returns local timezone as number of milliseconds from UTC time.

1
LOCALTIMEZONE()

Examples:

1
VAR timezoneDiff := LOCALTIMEZONE();

DATETIMEADD

Adds specified number of years, months, days, hours, minutes, seconds, milliseconds to existing DateTime and returns a new DateTime.

1
DATETIMEADD(datetime, years, months, days, hours, minutes, seconds, milliseconds)

Examples:

1
VAR dt := NOW(); VAR yearBefore := DATETIMEADD(dt, -1);

Data type conversions

TODOUBLE

Converts string to number. Returns NaN on error.

1
TODOUBLE( text )

Examples:

1
2
3
TODOUBLE(“232”) ... 232)
TODOUBLE(“-192.332”)  ...  -192.332
TODOUBLE(“some text”)  ...  NaN

TOSTRING

Returns a string value of the specified value or Collection according to the specified encoding. Encoding is optional (iso-8859-1 is used by default).

1
TOSTRING(value, encoding)

Examples:

1
2
3
4
TOSTRING(192, “X”)  …  Result = “C0”
TOSTRING(192, “X4”)  …  Result = “00C0”
TOSTRING(192, “F4”)  …  Result = “123.3400”
TOSTRING(192, “F0”)  …  Result = “123”
1
2
3
TOSTRING(BYTECOLLECTION("48656c6c6f"))			(Result is “Hello”)
TOSTRING(BYTECOLLECTION(\"48656c6c6f\"), “iso-8859-1”)	(Result is “Hello”)
TOSTRING(192, “X4”)							(Result is “00C0”)

TOBCD

Converts the provided number to the binary-coded decimal (BCD) format. The scheme of encoding is BCD-8421.

1
TOBCD(number)

Examples:

1
2
3
TOBCD(1)  ...  1
TOBCD(9)  ...  9
TOBCD(10)  ...  16

FROMBCD

Decodes the provided number, that is encoded in binary-coded decimal (BCD) format. The scheme of encoding is BCD-8421.

1
FROMBCD(number)

Examples:

1
2
FROMBCD(16)  ...  10
FROMBCD(32)  ...  20

TOBYTEARRAY

Converts string to byte array according to the specified encoding. Encoding is optional (iso-8859-1 is used by default).

1
TOBYTEARRAY( string, encoding )

Examples:

1
TOBYTEARRAY("Hello")			(Result is byte array 48656c6c6f)

RGBTOHSV

Converts RGB color definition; returns color in Hue / Saturation / Brightness format.

1
RGBTOHSV( r, g, b )      (r, g, b ... 0 - 0xFF)

Example:

1
2
3
4
VAR HSVColor := RGBTOHSV( r, g, b );
VAR saturation := HSVColor.Saturation;   (Saturation ... 0 - 1)
VAR hue := HSVColor.Hue;                 (Hue ... 0 - 360)
VAR value := HSVColor.Value;             (Value ... 0 - 1)

HSVTORGB

Converts color defined by Hue / Saturation / Brightness; returns color in RGB format

1
HSVTORGB( hue, saturation, value )

Example:

1
2
3
4
VAR color := HSVTORGB( hue, saturation, 1)
VAR red := color.red;                   (red ... 0 - 0xFF)
VAR green := color.green;               (green ... 0 - 0xFF)
VAR blue := color.blue;                 (blue ... 0 - 0xFF)

Parsing functions

PARSETEXT

Returns part of input text, based on left and right search patterns

1
PARSETEXT( input, left_pattern, right_pattern)

Examples:

1
2
3
4
5
6
7
PARSETEXT(“Lorem ipsum dolor sit amet”, “ipsum”, “amet”) (Result is “dolor sit”)
PARSETEXT(“<temp>12.2</temp>”, “<temp>”, “</temp”) (Result is 12.2)
PARSETEXT(“<temp>12.2</temp>”, “<temp>”) (Result is 12.2)
PARSETEXT(“status:ok,error:none”, “status:”) (Result is “ok”)
PARSETEXT(“Lorem ipsum dolor sit amet”, “ipsum”) (Result is “dolor”)
PARSETEXT(“Lorem ipsum dolor sit amet”, “ipsum…sit”) (Result is “amet”)
PARSETEXT(“Lorem ipsum dolor sit amet consectetur adipiscing”, “ipsum…sit”, “adipiscing”) (Result is “amet consectetur”)

PARSEJSON

Returns value of element from json formatted string. Element is specified with json path.

1
PARSEJSON( json_string, json_path, ignore_error)

Examples:

With json =

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{
  "firstName": "John",
  "lastName" : "doe",
  "age" : 26,
  "address"  : {
    "streetAddress": "naist street",
    "city"         : "Nara",
    "postalCode"   : "630-0192"
  }
}
1
2
3
4
5
PARSEJSON(json, “firstName”)			(Result is “John”)
PARSEJSON(json, “address.city”)		(Result is “Nara”)
PARSEJSON(json, “address.country”)		(error)
PARSEJSON(json, “address.country”, 0)		(error)
PARSEJSON(json, “address.city”, 1)		(Result is null)

PARSEXML

Returns value of element from xml string. Element is specified with xml path.

1
PARSEXML( xml_string, xml_path)

Examples:

With xml=

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0"?>
<catalog>
	<book id="bk101">
		<author>Gambardella, Matthew</author>
		<title>XML Developer's Guide</title>
		<genre>Computer</genre>
		<price>44.95</price>
		<publish_date>2000-10-01</publish_date>
		<description>An in-depth look at creating...</description>
	</book>
	<book id="bk102">
		<author>Ralls, Kim</author>
		<title>Midnight Rain</title>
		<genre>Fantasy</genre>
		<price>5.95</price>
		<publish_date>2000-12-16</publish_date>
		<description>A former architect battles…</description>
	</book>
</catalog>
1
2
3
4
PARSEXML(xml, "//catalog/book[1]/price") (Result is 44.95)
PARSEXML(xml, "//book[2]/title") (Result is "Midnight Rain")
PARSEXML(xml, "//book[1]/@id") (Result is "bk101")
PARSEXML(xml, "//catalog/magazine[1]/price") (Result is null)

If xml contains namespaces, you have to fully specify element names with namespace, eg. PARSEXML(xml, “//DIDL-Lite:container[dc:title=‘My Playlist’’]/DIDL-Lite:res”);

Packet parser

For more information, see the page about Packet parser

SENDHTTPREQUEST

SENDDATA

MQTTPUBLISH

FTPDOWNLOAD

FTPUPLOAD

COMPLETESERVICEATTRIBUTE

COMPLETESERVICEACTION

Modbus

Modbus

Detailed info on Modbus configuration.