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

308 The IEC Operators

Type Conversion Functions

Example in IL:

LD 2

INT_TO_REAL

MUL 3.5

Example in FBD:

12.9.4REAL_TO Conversions

Converting from the variable type REAL to a different type:

The value will be rounded up or down to the nearest whole number and converted into the new variable type. Exceptions to this are the variable types STRING, BOOL and REAL.

Please regard at a conversion to type STRING that the total number of digits is limited to 16. If the (L)REAL-number has more digits, then the sixteenth will be rounded. If the length of the STRING is defined to short, it will be cut beginning from the right end.

When you perform a type conversion from a larger to a smaller type, you risk losing some information.

Example in ST:

i := REAL_TO_INT(1.5); j := REAL_TO_INT(1.4); i := REAL_TO_INT(-1.5); j := REAL_TO_INT(-1.4);

Example in IL:

LD 2.7

REAL_TO_INT

GE %MW8

Example in FBD:

(* Result is 2 *) (* Result is 1 *) (* result is -2 *) (* result is -1 *)

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

The IEC Operators 309

Type Conversion Functions

12.9.5TIME_TO/TIME_OF_DAY Conversions

Converting from the variable type TIME or TIME_OF_DAY to a different type:

The time will be stored internally in a DWORD in milliseconds (beginning with 12:00 A.M. for the TIME_OF_DAY variable). This value will then be converted.

When you perform a type conversion from a larger to a smaller type, you risk losing some information

For the STRING type variable, the result is a time constant.

Examples in IL:

LD T#12ms

TIME_TO_STRING

ST

str (*Result is 'T#12ms' *)

LD T#300000ms

TIME_TO_DWORD

ST

dw

(*Result is 300000 *)

LD TOD#00:00:00.012

TOD_TO_SINT

ST si (*Result is 12 *)

Examples in St:

str :=TIME_TO_STRING(T#12ms);

(* Result is

T#12ms *)

 

dw:=TIME_TO_DWORD(T#5m);

(* Result is

300000 *)

 

si:=TOD_TO_SINT(TOD#00:00:00.012);

(* Result is 12

*)

 

Examples in FBD:

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

310 The IEC Operators

Type Conversion Functions

12.9.6 DATE_TO/DT_TO

Conversions

Converting from the variable type DATE or DATE_AND_TIME to a different type:

The date will be stored internally in a DWORD in seconds since Jan. 1, 1970. This value will then be converted.

When you perform a type conversion from a larger to a smaller type, you risk losing some information

For STRING type variables, the result is the date constant.

Examples in St:

b :=DATE_TO_BOOL(D#1970-01-01);

(* Result is

FALSE *)

 

i :=DATE_TO_INT(D#1970-01-15);

(* Result is

29952 *)

 

byt :=DT_TO_BYTE(DT#1970-01-15-05:05:05);

(* Result is

129 *)

 

str:=DT_TO_STRING(DT#1998-02-13-14:20);

(* Result is

'DT#1998-02-13-14:20' *)

 

12.9.7STRING_TO Conversions

Converting from the variable type STRING to a different type:

The operand from the STRING type variable must contain a value that is valid in the target variable type, otherwise the result will be 0.

Examples in St:

b :=STRING_TO_BOOL('TRUE');

(* Result is TRUE *)

w :=STRING_TO_WORD('abc34');

(* Result is 0 *)

t :=STRING_TO_TIME('T#127ms');

(* Result is T#127ms

*)

 

12.9.8TRUNC

Converting from REAL to INT. The whole number portion of the value will be used.

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

Соседние файлы в папке 759-332