24.01.2015 Views

PLC Programming

  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

IEC Operators and additional norm extending functions<br />

b := INT_TO_BOOL(0); (* Result is FALSE *)<br />

b := TIME_TO_BOOL(T#5ms); (* Result is TRUE *)<br />

b := STRING_TO_BOOL('TRUE'); (* Result is TRUE *)<br />

Conversion between Integral Number Types<br />

Conversion from an integral number type to another number type:<br />

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

If the number you are converting exceeds the range limit, the first bytes for the number will be ignored.<br />

Example in ST:<br />

si := INT_TO_SINT(4223); (* Result is 127 *)<br />

If you save the integer 4223 (16#107f represented hexadecimally) as a SINT variable, it will appear as<br />

127 (16#7f represented hexadecimally).<br />

Example in IL:<br />

LD 2<br />

INT_TO_REAL<br />

MUL 3.5<br />

Example in FBD:<br />

REAL_TO-/ LREAL_TO Conversions<br />

Converting from the variable type REAL or LREAL to a different type:<br />

The value will be rounded up or down to the nearest whole number and converted into the new<br />

variable type. Exceptions to this are the variable types STRING, BOOL, REAL and LREAL.<br />

Please regard at a conversion to type STRING that the total number of digits is limited to 16. If the<br />

(L)REAL-number has more digits, then the sixteenth will be rounded. If the length of the STRING is<br />

defined to short, it will be cut beginning from the right end.<br />

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

Example in ST:<br />

i := REAL_TO_INT(1.5); (* Result is 2 *)<br />

j := REAL_TO_INT(1.4); (* Result is 1 *)<br />

i := REAL_TO_INT(-1.5); (* result is -2 *)<br />

j := REAL_TO_INT(-1.4); (* result is -1 *)<br />

Example in IL:<br />

LD 2.7<br />

REAL_TO_INT<br />

GE<br />

%MW8<br />

Example in FBD:<br />

CoDeSys V2.3 10-17

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!