Real_to-/ lreal_to conversions, Time_to/time_of_day conversions, L-force | plc designer – Lenze PLC Designer PLC Designer (R3-1) User Manual

Page 1070

Advertising
background image

L-force | PLC Designer

Programming Reference

1068

DMS 4.1 EN 03/2011 TD29

REAL_TO-/ LREAL_TO Conversions
IEC Operator: 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.

Note: If a REAL or LREAL is converted to SINT, USINT, INT, UINT, DINT, UDINT, LINT or
ULINT and the value of the real number is out of the value range of that integer, the
result will be undefined and will depend on the target system. Even an exception is
possible in this case! In order to get target-independant code, handle any range
exceedance by the application. If the real/lreal number is within the integrer value
range, the conversion will work on all systems in the same way.

Notice 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.

Note: When you perform a type conversion from a larger to a smaller type, you risk
losing some information.

Example in ST:

i := REAL_TO_INT(1.5); (* Result is 2 *)
j := REAL_TO_INT(1.4); (* Result is 1 *)
i := REAL_TO_INT(-1.5); (* Result is -2 *)
j := REAL_TO_INT(-1.4); (* Result is -1 *)

Example in IL:

Example in FBD:

TIME_TO/TIME_OF_DAY Conversions
IEC Operator: Converting from the variable type TIME or TIME_OF_DAY to a different
type.
Syntax for the conversion operator:
<time data type>_TO_<data type>
The time will be stored internally in a DWORD in milliseconds (beginning with 12:00
A.M. for the TIME_OF_DAY variable). This value will then be converted.

Advertising