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

800

Basics

Association

Mu := Se + 2;

Multi-line algorithm

Each line is divided by semicolon

Last := Current;
Current := 0;

Returned value

(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);
END

Switch

doc_tap_TestsExprAgainst;

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

Example:

300
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
loop

Example with condition at the end:

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.

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 #

# comment

Numeric literals

doc_tap_HexaNo;

doc_tap_Expr_HexNo;

0x0A = 10

0xA0A0   (41120)
0xa0a0   (41120)

Binary numbers

0b1010 = 10

0b10101010   (170)

doc_tap_MathsExp;

+, -, *, /

(20.5 + 9.5) / 2    (15)

doc_tap_Logic_Exp;

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

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

doc_tap_Funkcie;

LINEAR

doc_tap_linearHodnota;

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

doc_tap_expressions_linear_examples_bounds;

Examples

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%)
800

doc_tap_expressions_linear_parameters;

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.

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).

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

doc_tap_MathematicalOperations;

MIN

MIN(value1, value2)

doc_tap_return_mensiu;

MAX

MAX(value1, value)

doc_tap_return_vacsiu;

AVG

The AVG function calculates average (mean) value of the provided numbers. The functions expects from 1 to 100 arguments.

AVG( n1, n2, n3, …)

Examples:

AVG(40, 80)  		= 60
AVG(2, 2, 6) 		= 3.3333
AVG(80, NAN)		= 80
AVG(NAN, NAN)		= NaN

ROUND

ROUND(value1)    

doc_tap_return_round;

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.

ABS(number)

Examples:

ABS(100)  ...   100
ABS(-100)   ...   100

DEWPOINT

DEWPOINT(temperature, relativeHumidity)
doc_tap_return_DewP;
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.

POWER(number, power)

Examples:

MOD

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

MOD(number, divisor)

Arguments:

Examples:

CEIL

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

CEIL(number, significance)

Arguments:

Examples:

FLOOR

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

FLOOR(number, significance)

Arguments:

Examples:

RAND

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

RAND()

Examples:

RANDINT

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

RANDINT(bottom, top)

Examples:

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.

SIGN(number)

Examples:

SQRT

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

SQRT(number)

Examples:

LOG

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

LOG(number, base)

Arguments:

Examples:

LN

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

LN(number)

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

Examples:

doc_tap_BitOp;

GETBIT

Returns a value of a bit in the specified position.

GETBIT(number, bit_position)

Arguments:

Examples:

GETBITS

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

GETBITS(number, start_bit, number_of_bits)

Examples:

GETBYTE

Returns a value of a byte in the specified number.

GETBYTE( number, byte_position )

Arguments:

Examples:

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.

SETBYTE( number, byte_position, new_value )

Examples:

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.

SETBIT(number, bit_position, new_value)

Arguments:

Examples:

SETBITS

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

SETBITS(number, start_bit, number_of_bits, new_value)

Examples:

<<   (LEFT BIT SHIFT)

8 << 2   (32)

Excel: BITLSHIFT(number, shift_amount)

>> (RIGHT BIT SHIFT)

32 >> 2   (8)

Excel: BITRSHIFT(number, shift_amount)

& (BITWISE AND)

3 & 1   (1)

Excel: BITAND(number1, number2)

| (BITWISE OR)

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.

LENGTH( object )

Examples:

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<UInt8> from specified hexadecimal values

BYTECOLLECTION( bytes )

Examples:

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.

INDEXOF( string/collection, element )

Examples:

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)

COPY( string/collection, startIndex, length)

Examples:

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.

REPLACE( string/collection, oldValue, newValue)

Examples:

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.

SPLIT( string, string )
SPLIT( string, char )
SPLIT( string, Collection<string> )
SPLIT( string, Collection<char> )

Examples:

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.

COMPARE( string, string, CompareOptions )

Examples:

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.

APPEND( string, string )
APPEND( Collection, value )

Examples:

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.

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

Examples:

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.

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

Examples:

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.

GETAT( collection, index )
GETAT( string, index )

Examples:

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})

SETAT

Set element value in collection or string at provided index.

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

Examples:

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})

ENCODE

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

ENCODE( string, format )

Supported formats:

Examples:

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.

DECODE( string, format )

Supported formats:

Examples:

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.

EQUALS( number1, number2, epsilon=0.005 )

Examples:

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)

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

DATETIME( ticks, DateTimeKind )
DATETIME( string, format )
DATETIME( string, DateTimeKind )
DATETIME( year, month, day, hour, minute, second, millisecond, DateTimeKind  )

Examples:

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.

NOW()

Examples:

VAR now := NOW();

LOCALTIMEZONE

Returns local timezone as number of milliseconds from UTC time.

LOCALTIMEZONE()

Examples:

VAR timezoneDiff := LOCALTIMEZONE();

DATEADD

Add specified number of years, months, days, hours, minutes, seconds, milliseconds to existing DateTime and return new DateTime.

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

Examples:

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

Data type conversions

TODOUBLE

Converts string to number. Returns NaN on error.

TODOUBLE( text )

Examples:

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

TOSTRING

doc_tap_tostring_description;

TOSTRING(value, encoding)

Examples:

TOSTRING(192, “X”)  …  Result = “C0”
TOSTRING(192, “X4”)  …  Result = “00C0”
TOSTRING(192, “F4”)  …  Result = “123.3400”
TOSTRING(192, “F0”)  …  Result = “123”
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.

TOBCD(number)

Examples:

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.

FROMBCD(number)

Examples:

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).

TOBYTEARRAY( string, encoding )

Examples:

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

RGBTOHSV

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

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

Example:

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

HSVTORGB( hue, saturation, value )

Example:

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

PARSETEXT( input, left_pattern, right_pattern)

Examples:

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.

PARSEJSON( json_string, json_path, ignore_error)

Examples:

With json = { "firstName": "John",
  "lastName" : "doe",
  "age" : 26,
  "address"  : {
    "streetAddress": "naist street",
    "city"         : "Nara",
    "postalCode"   : "630-0192"
  }
}

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.

PARSEXML( xml_string, xml_path)

Examples:

With xml= <?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>

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

doc_tap_script_moreinfo_pp;

SENDHTTPREQUEST

SENDDATA

MQTTPUBLISH

FTPDOWNLOAD

FTPUPLOAD

COMPLETESERVICEATTRIBUTE

COMPLETESERVICEACTION

Modbus

Modbus

doc_tap_follow_link_Modbus;