plcstiec61131-3

Is mixing types allowed in ST (Structured Text)


I wonder if it is allowed by the standard (IEC 1131-3) to mix different data types in an expression.

Example

VAR A : BOOL;
    B : INT;

(* ... *)

IF (B AND C) THEN
  ...
END_IF

Solution

  • You must use the explicit type conversion functions when converting "down" in types. "up" conversion is done implicitly.

    VAR A : BOOL;
        B : INT;
    (* ... *)
    IF (INT_TO_BOOL(B) AND C) THEN
      ...
    END_IF
    

    There are all forms of these type conversion in the form of TYPEA_TO_TYPEB()