Материал: m912201e

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

284 Data Types

Defined Data Types

END_TYPE

Direct declaration of a variable with a subrange type:

VAR

i : INT (-4095..4095);

ui : UINT (0..10000);

END_VAR

If a constant is assigned to a subrange type (in the declaration or in the implementation) that does not fall into this range (e.g. 1:=5000), an error message is issued.

In order to check for observance of range boundaries at runtime, the functions

CheckRangeSigned or CheckRangeUnsigned must be introduced. In these, boundary violations can be captured by the appropriate method and means (e.g. the value can be cut out or an error flag can be set.). They are implicitly called as soon as a variable is written as belonging to a subrange type constructed from either a signed or an unsigned type.

Example: In the case of a variable belonging to a signed subrange type (like i, above), the function CheckRangeSigned is called; it could be programmed as follows to trim a value to the permissible range:

FUNCTION CheckRangeSigned : DINT

VAR_INPUT

value, lower, upper: DINT; END_VAR

IF (value < lower) THEN

CheckRangeSigned := lower;

ELSIF(value > upper) THEN

CheckRangeSigned := upper;

ELSE

CheckRangeSigned := value;

END_IF

In calling up the function automatically, the function name CheckRangeSigned is obligatory, as is the interface specification: return value and three parameters of type DINT

When called, the function is parameterized as follows:

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

Data Types 285

Defined Data Types

-value: the value to be assigned to the range type

-lower: the lower boundary of the range

-upper: the upper boundary of the range

-Return value: this is the value that is actually assigned to the range type An assignment i:=10*y implicitly produces the following in this example:

i := CheckRangeSigned(10*y, -4095, 4095);

Even if y for example has the value 1000, then i still has only the value 4095 after this assignment.

The same applies to the function CheckRangeUnsigned: function name and interface must be correct.

FUNCTION CheckRangeUnsigned : UDINT

VAR_INPUT

value, lower, upper: UDINT; END_VAR

Note:

If neither of the functions CheckRangeSigned or CheckRangeUnsigned is present, no type checking of subrange types occurs during runtime! The variable i could then take on any value between –32768 and 32767 at any time!

Attention:

If neither of the functions CheckRangeSigned or CheckRangeUnsigned is present like described above, there can result an endless loop if a subrange type is used in a FOR loop. This will happen when the range given for the FOR loop is as big or bigger than the range of the subrange type !

Example:

VAR

ui : UINT (0..10000); END_VAR

FOR ui:=0 TO 10000 DO

...

END_FOR

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

286 Data Types

Defined Data Types

The FOR loop will never be finished, because ui cannot get bigger than 10000.

Also take care of the definition of the CheckRange functions when you define the incremental value of a FOR loop !

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

The IEC Operators

287

The IEC Operators

 

 

 

12The IEC Operators

12.1 The IEC Operators

WAGO-I/O-PRO 32 supports all IEC operators. In contrast with the standard library functions (see appendix D, Standard library), these operators are recognized implicitly throughout the project. Operators are used like functions in POU. The following categories of operators are supported:

12.2 Arithmetic Operators

12.2.1ADD

Addition of variables of the types: BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT and REAL.

Two TIME variables can also be added together resulting in another time (e.g., t#45s + t#50s = t#1m35s)

Example in IL:

LD 7

ADD 2,4,7

ST Var 1

Example in ST:

var1 := 7+2+4+7;

Example in FBD:

12.2.2MUL

Multiplication of variables of the types: BYTE, WORD, DWORD, SINT,

USINT, INT, UINT, DINT, UDINT and REAL.

Example in IL:

LD 7

MUL 2,4,7

ST Var 1

Example in ST:

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

288 The IEC Operators

Arithmetic Operators

var1 := 7*2*4*7;

Example in FBD:

12.2.3SUB

Subtraction of one variable from another of the types: BYTE, WORD,

DWORD, SINT, USINT, INT, UINT, DINT, UDINT and REAL.

A TIME variable may also be subtracted from another TIME variable resulting in third TIME type variable. Note that negative TIME values are undefined.

Example in IL:

LD 7

SUB 8

ST Var 1

Example in ST:

var1 := 7-2;

Example in FBD:

12.2.4DIV

Division of one variable by another of the types: BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT and REAL.

Example in IL:

LD 8

DIV 2

ST

Var1 (* Result is 4 *)

Example in ST:

var1 := 8/2;

Example in FBD:

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