You can define a conversion rule when you want to adjust data for another system of units. This data is executed for a specific order of magnitude and unit of measure.
You define conversion rules in a Unit Conversion object. (Undefined variable: docInfo_EN.FreieVariable_4) automatically implements each conversion rule as a function block <name>_Impl and instances it as <name>. Each conversion rule has the Convert and Reverse methods. As a result, you can use a function block as usual. Locations where you access a variable, you can link the variable to a conversion rule. The Input Assistant provides conversion rules in the Function Blocks and Instance Calls categories. After execution, the result is a converted value according to the conversion rule.
In a visualization, an IEC variable that is configured in an element property can also be linked to a conversion rules.
-
Double-click a Unit Conversion object in the device tree.
The corresponding editor opens. It contains a table with already defined conversion rules. You edit a rule in Type setting and a respective condition in Condition Setting.
-
Double-click the Add new entry field and type a name.
(Undefined variable: docInfo_EN.FreieVariable_4) implements the
<name>_Implfunction block and instances it as<name>. -
Double-click the Type field and click a type from the list box.
Input fields are displayed below the table for editing the conversion rule. The input fields vary according to selected type.
-
Change the conversion rule in the input fields.
The changes are displayed in the Setting category of the table.
-
Double-click the Condition field and click a condition type from the list box.
Input fields are displayed below the Condition Setting category of the table to edit the condition. The input fields vary according to selected type.
-
Edit the condition.
The changes are displayed in the Condition Setting category of the table.
You can define which conversion rule is applied to a specific language or condition.
-
Double-click a Unit Conversion object in the device tree.
The corresponding editor opens. It contains a table with predefined conversion rules.
-
Click the Add new entry field and type a name.
Example:
Conv_A_LanguageDependent -
Double-click the Type field and click Switchable Conversion. Double-click the Condition field and click Language.
Below the main table, the Switchable Conversion table is displayed with Condition Setting.
-
In the Switchable Conversion table, double-click a predefined conversion rule from the list box in the Switchable conversion name column, for example
Conv_AInInch.In Condition Setting, type in a value in the For condition 'Language' input field, for example
en.(Undefined variable: docInfo_EN.FreieVariable_4) executes the
Conv_AInInchconversion rule only if the language set in the Visualization Manager is en . -
In the Switchable Conversion table, double-click a predefined conversion rule from the list box in the Switchable conversion name column, for example
Conv_AInMM.In Condition Setting, click a value in the For condition 'Language' input field, for example
de.(Undefined variable: docInfo_EN.FreieVariable_4) executes the
Conv_AInMMconversion rule only if the language set in the Visualization Manager is de. -
Apply the
Conv_A_LanguageDependentconversion rule in the application or visualization.If the set language in the visualization is English, then the application visualization apply the
Conv_AInInchconversion rule. If the set language in the visualization is German, then the application visualization apply theConv_AInMMconversion rule. The current visualization language is located in theVisuElems.CurrentLanguagevariable.
Add a conversion rule to objects that access IEC variables.
-
In the device tree, double-click an object that accesses IEC variables in order to link an IEC variable to a conversion rule at that location.
-
Declare a variable for the conversion result of the IEC variable.
Code for example in ST:
rConvertedA : REAL; -
Apply the reverse conversion rule with the
Convertmethod and then assign the result to the variable. Use the Input Assistant.ST sample code to link the IEC variable to the conversion rule:
rConvertedA := ConvRule_A.Convert(rA);
-
In the device tree, double-click an object that accesses an IEC variable.
-
Declare a variable for the result of the conversion rule.
Code for example in ST:
rReverseA: REAL; -
Apply the reverse conversion rule with the
Reversemethod and then assign the result to the variable.rReverseA := ConvRule_A.Reverse(rConvertedA);
Requirement: The conversion rule is Conv_XtoY.
Example 17. Call in the ST implementation language
PROGRAM A_PRG
VAR
rA : REAL;
rConvertedA : REAL;
rReverseToA : REAL;
END_VAR
rConvertedA := Conv_XtoY.Convert(rA);
rReverseToA := Conv_XtoY.Reverse(rConvertedA);
Example 18. Call in the CFC implementation language
In the CFC editor, define the instance name of the conversion rule via the block. Select the method in the block.