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

STRING_TO Conversions<br />

Converting from the variable type STRING to a different type:<br />

The operand from the STRING type variable must contain a value that is valid in the target variable<br />

type, otherwise the result will be 0.<br />

Examples in St:<br />

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

w :=STRING_TO_WORD('abc34'); (* Result is 0 *)<br />

t :=STRING_TO_TIME('T#127ms'); (* Result is T#127ms *)<br />

TRUNC<br />

Converting from REAL to INT. The whole number portion of the value will be used.<br />

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

Examples in ST:<br />

i:=TRUNC(1.9); (* Result is 1 *)<br />

i:=TRUNC(-1.4); (* result is -1 *).<br />

Example in IL:<br />

LD 2.7<br />

TRUNC<br />

GE<br />

%MW8<br />

10.9 Numeric Operators...<br />

ABS<br />

Returns the absolute value of a number. ABS(-2) equals 2.<br />

The following type combinations for input and output variables are possible:<br />

IN<br />

INT<br />

REAL<br />

BYTE<br />

OUT<br />

INT, REAL, WORD, DWORD, DINT<br />

REAL<br />

INT, REAL, BYTE, WORD, DWORD, DINT<br />

WORD INT, REAL, WORD, DWORD, DINT<br />

DWORD REAL, DWORD, DINT<br />

SINT REAL<br />

USINT<br />

UINT<br />

DINT<br />

UDINT<br />

REAL<br />

INT, REAL, WORD, DWORD, DINT, UDINT, UINT<br />

REAL, DWORD, DINT<br />

REAL, DWORD, DINT, UDINT<br />

CoDeSys V2.3 10-19

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

Saved successfully!

Ooh no, something went wrong!