math
Description
The math block performs simple mathematical operations on numeric values provided to its input. Depending on the operation parameter, it can calculate an average, sum, minimum, maximum, or difference.
The block has one output. Multiple signal sources can be connected to the input, but the required number of connections depends on the selected operating mode.
The block accepts only numeric values. Boolean values, text values, dates, and other values that cannot be read as numbers do not take part in calculations.
Configuration parameters
| Parameter name | Value |
|---|---|
Operation mode (operation) |
Required parameter specifying the type of calculation. Allowed values are: avg, diff_smaller_than_bigger, diff_tags, max, min, sum. |
Block duplicated value (filter_duplicated_values) |
Required boolean value true or false. When set to true, the block does not emit another output value identical to the last emitted one. When set to false, the result is sent after every recalculation, even if it is the same as the previous one. |
Meaning of the operation parameter:
avg: arithmetic mean of all successfully read numeric valuesdiff_smaller_than_bigger: difference between the larger and the smaller of two input values, always non-negativediff_tags: differencetag1 - tag2max: largest successfully read numeric valuemin: smallest successfully read numeric valuesum: sum of all successfully read numeric values
Input handling
The block recalculates the result after every input change. For the input where the new value has just arrived, this new value is used. For all remaining connections, their last remembered values are used.
Only numeric inputs of integer, floating-point, temperature, or percentage type are supported. Non-numeric values are ignored or cause no result to be produced, depending on the selected mode:
- in
avg,max,min, andsummodes, each non-numeric value is simply skipped - in
diff_smaller_than_biggeranddiff_tagsmodes, both values must be numeric; if either of them cannot be read as a number, the result is not produced
Connection requirements:
- for
avg,max,min, andsum, at least one block must be connected to the input; more than two connections are allowed - for
diff_smaller_than_bigger, exactly two input connections are required - for
diff_tags, exactly two input connections are required, and they must be exactly thetag1andtag2lines
Inputs labeled using the tag block are meaningful only in diff_tags mode.
| Input number and name | Input description |
|---|---|
tag1: First difference operand. |
Used only in diff_tags mode. The value from this input is used as the left side of the operation tag1 - tag2. |
tag2: Second difference operand. |
Used only in diff_tags mode. The value from this input is subtracted from tag1. |
Additional operating rules:
avgcalculates the average only from inputs whose values can be read as numericsumadds only valid numeric valuesmaxandminconsider only valid numeric values- if there is not a single valid numeric value in
avg,sum,max, orminmode, the output becomesnull - if one of the required numeric values cannot be read in
diff_smaller_than_biggerordiff_tagsmode, the output becomesnull
Precision and result type
The block performs calculations using the internal numeric representation with precision up to 3 decimal places.
Precision rules:
sum,max,min,diff_smaller_than_bigger, anddiff_tagsreturn an exact result within this precisionavgdivides the sum of values by the number of valid inputs using integer division on the internal representation, so the result is truncated to at most 3 decimal places; the block does not apply any additional rounding
Result type and unit:
- the output is returned as a regular numeric value of type
integerordouble - if the result has no fractional part, the block returns an integer
- if the result has a fractional part, the block returns a floating-point value
- input units such as temperature or percentage are not preserved at the output
Block outputs
The block has one output.
The output carries the result of the calculation selected by the operation parameter. If the result cannot be determined according to the rules of the selected mode, the output becomes null.
Block status description
The description shown below the block contains the textual representation of the last calculated result.
Examples:
2518.50
If the last result cannot be represented as text, the description becomes Unknown value.. This happens, among other cases, when the current result is null.
Errors returned by the block
The block can show the following error messages:
| Error code | Error description |
|---|---|
Failed read operation. |
The operation parameter is missing in the configuration or cannot be read as text. |
Invalid operation. |
The operation parameter has a value outside the supported list. |
Missing filter_duplicated_values configuration. |
The filter_duplicated_values parameter is missing in the configuration. |
Input disconnected. |
No other block is connected to the block input. |
Diff requires two connections. |
diff_smaller_than_bigger mode was selected, but there are not exactly two connected input sources. |
Tag1 and tag2 required. |
diff_tags mode was selected, but the required tag1 and tag2 lines are not both connected, or one of them is no longer available. |
Usage examples
- If
operation = sumand the available input values are2,3.5, and4, the output becomes9.5. - If
operation = avgand the valid input values are1,2, and2, the output becomes1.666. - If
operation = maxand the block receives21,18, and the textopen, the text value is ignored and the output becomes21. - If
operation = diff_smaller_than_biggerand the two input values are7and10, the output becomes3. - If
operation = diff_tags,tag1 = 24.5, andtag2 = 20, the output becomes4.5. - If
operation = min, but all inputs have non-numeric values, the output becomesnulland the block description changes toUnknown value..