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 />

10.8 Type Conversions...<br />

Its is forbidden to implicitly convert from a "larger" type to a "smaller" type (for example from INT to<br />

BYTE or from DINT to WORD). Special type conversions are required if one wants to do this. One can<br />

basically convert from any elementary type to any other elementary type.<br />

Syntax:<br />

_TO_<br />

Please regard that at ...TO_STRING conversions the string is generated left-justified. If it is defined to<br />

short, it will be cut from the right side.<br />

BOOL_TO Conversions<br />

Conversion from type BOOL to any other type:<br />

For number types the result is 1, when the operand is TRUE, and 0, when the operand is FALSE.<br />

For the STRING type the result is ‚TRUE' or ‚FALSE'.<br />

Examples in AWL:<br />

LD TRUE<br />

BOOL_TO_INT<br />

ST i<br />

LD TRUE<br />

BOOL_TO_STRING<br />

ST str<br />

LD TRUE<br />

BOOL_TO_TIME<br />

ST t<br />

LD TRUE<br />

BOOL_TO_TOD<br />

ST<br />

LD FALSE<br />

BOOL_TO_DATE<br />

ST dat<br />

LD TRUE<br />

BOOL_TO_DT<br />

ST dandt<br />

(*Result is 1 *)<br />

(*Result is 'TRUE' *)<br />

(*Result is T#1ms *)<br />

(*Result is TOD#00:00:00.001 *)<br />

(*Result is D#1970-01-01 *)<br />

(*Result is DT#1970-01-01-00:00:01 *)<br />

Examples in St:<br />

i:=BOOL_TO_INT(TRUE); (* Result is 1 *)<br />

str:=BOOL_TO_STRING(TRUE); (* Result is "TRUE" *)<br />

t:=BOOL_TO_TIME(TRUE); (* Result is T#1ms *)<br />

tof:=BOOL_TO_TOD(TRUE); (* Result is TOD#00:00:00.001 *)<br />

dat:=BOOL_TO_DATE(FALSE); (* Result is D#1970 *)<br />

dandt:=BOOL_TO_DT(TRUE);<br />

(* Result is<br />

DT#1970-01-01-00:00:01 *)<br />

Examples in FUP:<br />

(*Result is 1 *)<br />

CoDeSys V2.3 10-15

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

Saved successfully!

Ooh no, something went wrong!