You can use unit conversions in all IEC editors. If you create a conversion for each new conversion, a function block is created automatically.
The function block includes 2 methods:
|
Method |
Description |
|---|---|
|
Convert |
Calculation of the input value according to the conversion formula. |
|
Reverse |
Reverse calculation back to the input value. |
You can call these methods in all IEC editors.
In this example, Conv_4_20 is the name of the conversion.
VAR
rValue : REAL;
rConvertedValue : REAL;
END_VAR
rConvertedValue := Conv_4_20.convert(rValue);
Reverse calculation back to the input value.
rValue := Conv_4_20.reverse(rConvertedValue);
In the CFC editor, enter the instance name of the conversion above the element. In the element, the method is defined.
Example in CFC method Convert:
Example in CFC method Reverse: