Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
10
Добавлен:
11.10.2020
Размер:
3.39 Mб
Скачать

304 The IEC Operators

Calling Operator

man_fun1

12.7.2Content Operator

A pointer can be dereferenced by adding the content operator "^" after the pointer identifier.

Example in ST:

pt:POINTER TO INT; var_int1:INT; var_int2:INT;

pt := ADR(var_int1); var_int2:=pt^;

12.8 Calling Operator

12.8.1CAL

Calling a function block or a program

Use CAL in IL to call up a function block instance. The variables that will serve as the input variables are placed in parentheses right after the name of the function block instance.

Example: Calling up the instance Inst from a function block where input variables Par1 and Par2 are 0 and TRUE respectively.

CAL INST(PAR1 := 0, PAR2 := TRUE)

12.9 Type Conversion Functions

Its is forbidden to implicitly convert from a "larger" type to a "smaller" type (for example from INT to BYTE or from DINT to WORD). Special type conversions are required if one wants to do this. One can basically convert from any elementary type to any other elementary type.

Syntax:

<elem.Typ1>_TO_<elem.Typ2>

Please regard that at ...TO_STRING conversions the string is generated leftjustified. If it is defined to short, it will be cut from the right side.

12.9.1BOOL_TO Conversions

Conversion from type BOOL to any other type:

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32

The IEC Operators 305

Type Conversion Functions

For number types the result is 1, when the operand is TRUE, and 0, when the operand is FALSE.

For the STRING type the result is ‚TRUE' or ‚FALSE'.

Examples in AWL:

LD

TRUE

 

 

BOOL_TO_INT

 

 

ST

i

(*Result is 1 *)

 

LD

TRUE

 

 

BOOL_TO_STRING

 

ST

str

(*Result is 'TRUE' *)

LD

TRUE

 

 

BOOL_TO_TIME

 

ST

t

(*Result is T#1ms *)

LD

TRUE

 

 

BOOL_TO_TOD

 

 

ST

tof

(*Result is TOD#00:00:00.001 *)

LD

FALSE

 

 

BOOL_TO_DATE

 

ST

dat

(*Result is D#1970-01-01 *)

LD

TRUE

 

 

BOOL_TO_DT

 

 

ST

dandt (*Result is DT#1970-01-01-00:00:01 *)

Examples in St:

 

 

i:=BOOL_TO_INT(TRUE);

(* Result is 1 *)

str:=BOOL_TO_STRING(TRUE);

(* Result is "TRUE" *)

t:=BOOL_TO_TIME(TRUE);

(* Result is T#1ms *)

tof:=BOOL_TO_TOD(TRUE);

(* Result is

TOD#00:00:00.001 *)

 

dat:=BOOL_TO_DATE(FALSE);

(* Result is D#1970 *)

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32

306 The IEC Operators

Type Conversion Functions

dandt:=BOOL_TO_DT(TRUE);

(* Result is DT#1970-01-01-

00:00:01 *)

 

Examples in FUP:

(*Result is 1 *)

(*Result is 'TRUE' *)

(*Result is T#1ms *)

(*Result is TOD#00:00:00.001 *)

(*Result is D#1970-01-01 *)

(*Result is DT#1970-01-01- 00:00:01 *)

12.9.2TO_BOOL Conversions

Conversion from another variable type to BOOL:

The result is TRUE when the operand is not equal to 0. The result is FALSE when the operand is equal to 0.

The result is true for STRING type variables when the operand is "TRUE", otherwise the result is FALSE.

Examples in AWL:

LD

213

 

BYTE_TO_BOOL

ST

b

(*Result is TRUE *)

LD

0

 

INT_TO_BOOL

ST

b

(*Result is FALSE *)

LD T#5ms

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32

The IEC Operators 307

Type Conversion Functions

TIME_TO_BOOL

ST

b

(*Result is TRUE *)

LD

'TRUE'

STRING_TO_BOOL

ST

b

(*Result is TRUE *)

Examples in FUP:

(*Result is TRUE *)

(*Result is FALSE *)

(*Result is TRUE *)

(*Result is TRUE *)

Examples in St:

 

b := BYTE_TO_BOOL(2#11010101);

(* Result is TRUE *)

b := INT_TO_BOOL(0);

(* Result is FALSE *)

b := TIME_TO_BOOL(T#5ms);

(* Result is TRUE *)

b := STRING_TO_BOOL('TRUE');

(* Result is TRUE *)

12.9.3Conversion between Integral Number Types

Conversion from an integral number type to another number type:

When you perform a type conversion from a larger to a smaller type, you risk losing some information. If the number you are converting exceeds the range limit, the first bytes for the number will be ignored.

Example in ST:

si := INT_TO_SINT(4223); (* Result is 127 *)

If you save the integer 4223 (16#107f represented hexadecimally) as a SINT variable, it will appear as 127 (16#7f represented hexadecimally).

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32