Материал: m912201e

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам

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

The IEC Operators

311

Numeric Functions

 

 

 

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

Examples in ST:

i:=TRUNC(1.9); (* Result is 1 *)

i:=TRUNC(-1.4); (* result is -1 *).

Example in IL:

LD 2.7

TRUNC

GE %MW8

12.10Numeric Functions

12.10.1ABS

Returns the absolute value of a number. ABS(-2) equals 2.

The following type combinations for input and output variables are possible:

IN

 

OUT

INT

 

INT, REAL, WORD, DWORD, DINT

 

 

 

REAL

 

REAL

 

 

 

BYTE

 

INT, REAL, BYTE, WORD, DWORD, DINT

 

 

 

WORD

 

INT, REAL, WORD, DWORD, DINT

 

 

 

DWORD

 

REAL, DWORD, DINT

 

 

 

SINT

 

REAL

 

 

 

USINT

 

REAL

 

 

 

UINT

 

INT, REAL, WORD, DWORD, DINT, UDINT, UINT

 

 

 

DINT

 

REAL, DWORD, DINT

 

 

 

UDINT

 

REAL, DWORD, DINT, UDINT

 

 

Example in IL:

 

LD

2

 

ABS

 

 

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

312 The IEC Operators

Numeric Functions

ST

i

(*Result is 2 *)

Example in ST:

i:=ABS(-2);

Example in FBD:

12.10.2SQRT

Returns the square root of a number.

IN can be type BYTE, WORD, DWORD, INT, DINT, REAL, SINT, USINT, UINT, UDINT, OUT must be type REAL.

Example in IL:

LD 16

SQRT

ST

q

(*Result is 4 *)

Example in ST:

q:=SQRT(16);

Example in FBD:

12.10.3LN

Returns the natural logarithm of a number.

IN can be type BYTE, WORD, DWORD, INT, DINT, REAL, SINT, USINT, UINT, UDINT, OUT must be type REAL.

Example in IL:

LD 45

LN

ST

q

(*Result is 3.80666 *)

Example in ST:

q:=LN(45);

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

The IEC Operators

313

Numeric Functions

 

 

 

Example in FBD:

12.10.4LOG

Returns the logarithm of a number in base 10.

IN can be type BYTE, WORD, DWORD, INT, DINT, REAL, SINT, USINT, UINT, UDINT, OUT must be type REAL.

Example in IL:

LD 314.5

LOG

ST

q

(*Result is 2.49762 *)

Example in ST:

q:=LOG(314.5);

Example in FBD:

12.10.5EXP

Returns the exponential function.

IN can be type BYTE, WORD, DWORD, INT, DINT, REAL, SINT, USINT, UINT, UDINT, OUT must be type REAL.

Example in IL:

LD 2

EXP

ST

q

(* result is 7.389056099 *)

Example in ST:

q:=EXP(2);

Example in FBD:

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