Introduction
According to IEC, the data type of the result variable does not influence the data type of the result expression and the expression data type is converted to the result data type.
Example:
i_DINT := REAL1+REAL2;
Equivalent using explicit type conversion:
e_DINT := REAL_TO_DINT(REAL1+REAL2);
Control Expert Differences
Control Expert has these exceptions to the IEC Recommendations:
If the result variable data type of an assignment is bigger than the result expression type, the parameters of the result expression are converted to the output parameter type to avoid an expression overflow.
Example:
i_DINT := INT1 + INT2;
Equivalent using explicit type conversion:
e_DINT := INT_TO_DINT(INT1) + INT_TO_DINT(INT2);
Control Expert uses implicit type conversion for generic functions, the data type of the result variable has an influence on the data type of the result expression (generic function).
Example:
i_DINT := ADD (IN1 := INT1, IN2 := INT2);
Equivalent using explicit type conversion:
e_DINT := ADD (IN1 := INT_TO_DINT(INT1), IN2 := INT_TO_DINT(INT2));
Generic output parameters of function blocks have no influence on the data type of the result expression.
Type conversions of non-matching input parameters are executed before the FFB-body is called and type conversions of output parameters are executed after the call. Implicit type conversions are, in contrast to explicit type conversions, only executed when the FFB-body is called.
Example:
SAH_0 (IN := BYTE1, CLK := BOOL1, PV :=
WORD1, OUT => i_DINT );
The next 3 lines are needed to get an equivalent result, using explicit type conversion:
word_tmp := DINT_TO_WORD(e_DINT);
SAH_0 (IN := BYTE_TO_WORD(BYTE1), CLK
:= BOOL1, PV := WORD1, OUT => _word_tmp);
e_DINT := WORD_TO_DINT(word_tmp);
The implicit type conversion rules are only applicable to typed constants. Control Expert treats untyped constants (literal values) initially as DINT constants.
Examples:
i_INT := 5 / 6 * 5.52;
Equivalent using explicit type conversion:
e_INT := REAL_TO_INT(DINT_TO_REAL(5)
/ DINT_TO_REAL(6) * 5.52);
i_BOOL := (65535 < INT1) = (BYTE1 = 255);
Equivalent using explicit type conversion:
e_BOOL
:= (65535 < INT_TO_DINT(INT1)) = (BYTE_TO_DINT(BYTE1) = 255);
Control Expert supports implicit type conversion inside expressions.
Examples:
i_INT := BYTE1 = DINT1;
Equivalent using explicit type conversion:
e_INT := BOOL_TO_INT(BYTE_TO_DINT(BYTE1)
= DINT1);
i_WORD := BYTE1
= (REAL1 > DINT1 );
Equivalent using explicit type conversion:
e_WORD := BOOL_TO_WORD(BYTE1
= BOOL_TO_BYTE((REAL1 > DINT_TO_REAL(DINT1))));
i_REAL := WORD1 OR BYTE1 AND (100000 +
5);
Equivalent using explicit type conversion:
e_REAL:= DINT_TO_REAL(WORD_TO_DINT(WORD1)
OR (BYTE_TO_DINT(BYTE1) AND (100000 + 5)));