Výrazy
Výrazy se používají v Smart Rules „Rovnice“ a „Vzorec“.
Na zařízeních Modbus lze použít další funkce pro čtení/zápis hodnot z/do registrů Modbus.
Matematické výrazy
+, -, *, /
(20.5 + 9.5) / 2 (15)
Logické výrazy
AND, OR, !, =, !=, >, <
(!IsRaining OR (Wind>30)) MultiValueSwitchState != 2 (Not equal to 2)
Funkce
IF
IF(logical_expression, value_if_true, value_if_false)
Vrací jednu hodnotu, pokud je logický výraz „PRAVDA“, a druhou, pokud je „NEPRAVDA“.
LINEAR
Vrátí lineárně upravenou hodnotu - lineární interpolaci.
LINEAR(input, value1_input, value1_output, value2_input, value2_output)
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%)
SWITCH
SWITCH(expression, case1, value1, [case2, ...], [value2, ...], default_value)
Testuje výraz proti seznamu případů a vrací odpovídající hodnotu prvního porovnávacího případu s výchozí hodnotou, pokud není splněno nic jiného.
Example
Configuration
ReadState ... SWITCH(MODBUSR(H, 168, UInt16), 0, 0, 0x02, 1, 0x04, 2, 0x08, 3, 0x10, 4, 0x40, 5, 0x800, 6, 0)
WriteState ... MODBUSWNE(H, 168, UInt16, SWITCH(Mu, 0, 0, 1, 0x02, 2, 0x04, 3, 0x08, 4, 0x10, 5, 0x40, 6, 0x800, 0)Result
MIN
MIN(value1, value2)
Vrací menší z obou hodnot.
MAX
MAX(value1, value)
Vrací větší z obou hodnot.
ROUND
ROUND(value1)
Vrátí zaokrouhlenou hodnotu.
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)
Core 2018.1.9623
DEWPOINT
DEWPOINT(temperature, relativeHumidity)Vrátí teplotu rosného bodu vzhledem k aktuální teplotě a relativní vlhkosti. Rosný bod se počítá podle této rovnice: http://bmcnoldy.rsmas.miami.edu/Humidity.html.
Example 1: DEWPOINT(20, 50) (Result is ~9.26)
Example 2: DEWPOINT(0, 100) (Result is 0)
Core 2018.1.9623
POWER
Core 2021.1
The POWER function calculates a given number, raised to a supplied power.
POWER(number, power)
Examples:
POWER(2,3) … 2^3 = 8
POWER(10, -3) … 0,001
POWER(25, 0) … 1
MOD
Core 2021.1
The MOD function returns the remainder of a division between two supplied numbers.
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
Core 2021.1
The CEIL function rounds a supplied number away from zero, to the nearest multiple of a given number.
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
Core 2021.1
The FLOOR function rounds a supplied number towards zero to the nearest multiple of a specified significance.
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
Core 2021.1
The Rand function generates a random real number between 0 and 1.
RAND()
Examples:
RAND()
RANDINT
Core 2021.1
The RANDINT function generates a random integer between two supplied integers.
RANDINT(bottom, top)
Examples:
RANDINT(1,5)
RANDINT(-2,2)
SIGN
Core 2021.1
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:
SIGN(100) … 1
SIGN(0) … 0
SIGN(-100) … -1
SQRT
Core 2021.1
The SQRT function calculates the positive square root of a supplied number.
SQRT(number)
Examples:
SQRT(25) … 5
LOG
Core 2021.1
The LOG function calculates the logarithm of a given number, to a supplied base.
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
Core 2021.1
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:
LN(100) … 4,60517
Bitové operace
<< (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/
Hexadecimální čísla
Výrazy mohou také interpretovat hexadecimální čísla. Je vyžadována předpona 0x a zbytek nerozlišuje velká a malá písmena.
0x0A (10)
0xA0A0 (41120)
0xa0a0 (41120)
Modbus
Klepnutím na tento odkaz najdete další informace o konfiguraci Modbus