Reference programming tm:= TOD_TO_TIME(TOD#14:01:05.123); (* Result is T#841m5s123ms *) udi:= TOD_TO_UDINT(TOD#14:01:05.123); (* Result is 16#03020963 *) 7.2.9.8 DT_TO conversions Converting from the variable type DATE_AND_TIME to a different type: The type will be stored internally in a DWORD in seconds since Jan. 1, 1970. This value will then be converted. When you perform a type conversion from a larger to a smaller type, you risk losing some information . For STRING type variables, the result is the DATE_AND_TIME constant. Examples in ST:
byt :=DT_TO_BYTE(DT#1970-01-15-05:05:05); (* Result is 129 *) str:=DT_TO_STRING(DT#1998-02-13-14:20); (* Result is 'DT#1998-02-13-14:20' *) vtod:=DT_TO_TOD(DT#1998-02-13-14:20); (* Result is TOD#14:20 *) vdate:=DT_TO_DATE(DT#1998-02-13-14:20); (* Result is D#1998-02-13 *) vdw:=DT_TO_DWORD(DT#1998-02-13-14:20); (* Result is 16#34E45690 *) 7.2.9.9 REAL_TO-/LREAL_TO conversions Converting from the variable type REAL or LREAL to a different type: The value will be rounded up or down to the nearest whole number and converted into the new variable type. Exceptions to this are the variable types STRING, BOOL, REAL and LREAL.
When you perform a type conversion from a larger to a smaller type, you risk losing some information. Please regard at a conversion to type STRING that the total number of digits is limited to 16. If the (L)REAL- number has more digits, then the sixteenth will be rounded. If the length of the STRING is defined to short, it will be cut beginning from the right end. Example in ST: i := REAL_TO_INT(1.5); (* Result is 2 *) j := REAL_TO_INT(1.4); (* Result is 1 *) k := LREAL_TO_STRING(); (* Result is '1.4' *) Example in IL: LD 2.7 REAL_TO_INT GE %MW8 7.2.9.10 Conversion between integral number types Conversion from an integral number type to another number type:
When you perform a type conversion from a larger to a smaller type, you risk losing some information. If the number you are converting exceeds the range limit, the first bytes for the number will be ignored. Example in ST: si := INT_TO_SINT(4223); (* Result is 127 *) If you save the integer 4223 (16#107f in hexadecimals represented) as a SINT variable, it will appear as 127 (16#7f in hexadecimals represented). TX1200 212 Version: 1.3