24.01.2015 Views

PLC Programming

  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Type Conversions...<br />

TIME_TO/TIME_OF_DAY Conversions<br />

Converting from the variable type TIME or TIME_OF_DAY to a different type:<br />

The time will be stored internally in a DWORD in milliseconds (beginning with 12:00 A.M. for the<br />

TIME_OF_DAY variable). This value will then be converted.<br />

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

For the STRING type variable, the result is a time constant.<br />

Examples in IL:<br />

LD T#12ms<br />

TIME_TO_STRING<br />

ST str<br />

LD T#300000ms<br />

TIME_TO_DWORD<br />

ST dw<br />

LD TOD#00:00:00.012<br />

TOD_TO_SINT<br />

ST si<br />

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

(*Result is 300000 *)<br />

(*Result is 12 *)<br />

Examples in St:<br />

str :=TIME_TO_STRING(T#12ms); (* Result is T#12ms *)<br />

dw:=TIME_TO_DWORD(T#5m); (* Result is 300000 *)<br />

si:=TOD_TO_SINT(TOD#00:00:00.012); (* Result is 12 *)<br />

Examples in FBD:<br />

DATE_TO/DT_TO<br />

Conversions<br />

Converting from the variable type DATE or DATE_AND_TIME to a different type:<br />

The date will be stored internally in a DWORD in seconds since Jan. 1, 1970. This value will then be<br />

converted.<br />

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

For STRING type variables, the result is the date constant.<br />

Examples in St:<br />

b :=DATE_TO_BOOL(D#1970-01-01); (* Result is FALSE *)<br />

i :=DATE_TO_INT(D#1970-01-15); (* Result is 29952 *)<br />

byt :=DT_TO_BYTE(DT#1970-01-15-05:05:05); (* Result is 129 *)<br />

str:=DT_TO_STRING(DT#1998-02-13-14:20);<br />

(* Result is<br />

'DT#1998-02-13-14:20' *)<br />

10-18 CoDeSys V2.3

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

Saved successfully!

Ooh no, something went wrong!