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

Appendix A: - IEC Operators and additional norm extending functions

10.6Address Operators...

Attention: After an Online Change there might be changes concerning the data on certain addresses. Please regard this in case of using pointers on addresses.

ADR

Address Function not prescribed by the standard IEC61131-3.

ADR returns the address of its argument in a DWORD. This address can be sent to manufacturing functions to be treated as a pointer or it can be assigned to a pointer within the project.

dwVar:=ADR(bVAR);

Example in IL:

LD bVar ADR

ST dwVar man_fun1

BITADR

Adress function, not prescribed by the standard IEC61131-3.

BITADR returns the bit offset within the segment in a DWORD. Regard that the offset value depends on whether the option byte addressing in the target settings is activated or not.

VAR

var1 AT %IX2.3:BOOL; bitoffset: DWORD;

END_VAR

Example in ST:

bitoffset:=BITADR(var1); (* Result if byte addressing=TRUE: 19, if byte addressing=FALSE: 35 *)

Example in IL:

LD Var1

BITADR

ST Var2

Content 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^;

CoDeSys V2.3

10-13

Appendix A: - IEC Operators and additional norm extending functions

10.7Calling Operators...

CAL

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)

10.8Type Conversions...

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 left-justified. If it is defined to short, it will be cut from the right side.

BOOL_TO Conversions

Conversion from type BOOL to any other type:

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

(*Result is 1 *)

BOOL_TO_INT

 

ST i

 

LD TRUE

(*Result is 'TRUE' *)

BOOL_TO_STRING

 

ST str

 

LD TRUE

(*Result is T#1ms *)

BOOL_TO_TIME

 

ST t

 

LD TRUE

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

BOOL_TO_TOD

 

ST

 

LD FALSE

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

BOOL_TO_DATE

 

ST dat

 

LD TRUE

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

BOOL_TO_DT

 

ST dandt

 

10-14

CoDeSys V2.3

Appendix A: - IEC Operators and additional norm extending functions

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 *)

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 *)

TO_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

(*Result is TRUE *)

BYTE_TO_BOOL

 

ST b

 

LD 0

(*Result is FALSE *)

INT_TO_BOOL

 

ST b

 

LD T#5ms

(*Result is TRUE *)

TIME_TO_BOOL

 

ST b

 

LD 'TRUE'

(*Result is TRUE *)

STRING_TO_BOOL

 

ST b

 

CoDeSys V2.3

10-15

Appendix A: - IEC Operators and additional norm extending functions

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 *)

Conversion 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).

Example in IL:

LD 2

INT_TO_REAL

MUL

Example in FBD:

REAL_TO-/ LREAL_TO Conversions

Converting from the variable type REAL or LREAL 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, REAL and LREAL.

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); (* Result is 2 *)

10-16

CoDeSys V2.3

Appendix A: - IEC Operators and additional norm extending functions

j := REAL_TO_INT(1.4); (* Result is 1 *)

i := REAL_TO_INT(-1.5); (* Result is -2 *) j := REAL_TO_INT(-1.4); (* Result is -1 *)

Example in IL:

LD 2.7

REAL_TO_INT

GE %MW8

Example in FBD:

TIME_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

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

TIME_TO_STRING

 

 

ST str

 

 

LD T#300000ms

(*Result is 300000 *)

TIME_TO_DWORD

 

 

ST dw

 

 

LD TOD#00:00:00.012

(*Result is 12 *)

TOD_TO_SINT

 

 

ST si

 

 

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:

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.

CoDeSys V2.3

10-17

Appendix A: - IEC Operators and additional norm extending functions

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 IL:

 

 

LD D#1970-01-01

(* Result is FALSE *)

DATE_TO_BOOL

 

 

ST b

 

 

LD D#1970-01-15

(* Result is 29952 *)

DATE_TO_INT

 

 

ST i

 

 

LD DT#1970-01-15-05:05:05

(* Result is 129 *)

DT_TO_BYTE

 

 

ST byt

 

 

LD DT#1998-02-13-14:20

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

DT_TO STRING

 

 

ST str

 

 

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' *)

Examples in FBD:

STRING_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 IL:

 

LD 'TRUE'

(* Result is TRUE *)

STRING_TO_BOOL

 

ST b

 

LD 'abc34'

(* Result is 0 *)

STRING_TO_WORD

 

ST w

 

10-18

CoDeSys V2.3

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