- Home
- Function/Function Block Reference
- IEC 61131-3 Functions and Function Blocks
- Data Type Conversion
- TO_USINT
TO_USINT
Type | Function | ||||||||||||||||||||||||||||||||||
Description | The overloaded function TO_USINT converts an input value of various data types into an output value of the data type USINT (see description of the input for the supported data types). | ||||||||||||||||||||||||||||||||||
Parameters | Input
![]()
![]()
|
||||||||||||||||||||||||||||||||||
Conversion rules | ![]() The conversion is done by copying the input value bitwise to the output value, i.e., a binary transfer from the input data type to the output data type is performed. If the input data type is bigger than the USINT output (> 8 bits), only the bits 0 to 7 of the input value are copied to the output value. ![]() The data type conversion is done as follows:
Example:
![]() The type conversion is divided into two steps. First the floating point value is rounded to the next higher absolute integer according to standard rounding rules (for example, 2.5 is rounded to 3 and -2.5 is rounded to -3). In the second step the rounded input value is converted to the least significant bits of the output value.
![]()
|
||||||||||||||||||||||||||||||||||
Error behavior | ![]() The following table shows the errors which may occur while executing the function and the value returned by the function in the corresponding error case.
If any of the listed string errors occurs, an error is written to the Online log in the MESSAGES window.
Note for large real values: Sample: 3.6000000E+7 => 3.600000E+7 => SINT: 0 3.6000001E+7 => 3.600000E+7 => SINT: 0 3.6000002E+7 => 3.600000E+7 => SINT: 0 3.6000003E+7 => 3.600004E+7 => SINT: 4 3.6000004E+7 => 3.600004E+7 => SINT: 4 ... The values 3.600001E+7, 3.600002E+7, 3.600003E+7 have no representation in REAL and will be set to the next possible REAL value. This results in gaps. The larger the number is, the larger the gap will be, until always 0 will be shown as result. |
||||||||||||||||||||||||||||||||||
Examples | ![]() out := TO_USINT(16#7F); (* results in 127 *) out := TO_USINT(16#FFFF); (* results in 255 *) out := TO_USINT(16#AFFFFFF0); (* results in 240 *) out := TO_USINT(INT#127); (* results in 127 *) out := TO_USINT(INT#32767); (* results in 255 *) out := TO_USINT(INT#-32768); (* results in 0 *) out := TO_USINT(SINT#-128); (* results in 128 *) out := TO_USINT(REAL#2.55E+002); (* results in 255 *) out := TO_USINT(REAL#2.56E+002); (* results in 0 *) out := TO_USINT('123'); (* results in 123 *) |
||||||||||||||||||||||||||||||||||
Additional information | ![]() The POU is only executed if TRUE is applied to the EN input. If EN = FALSE, the POU is not executed and ENO = FALSE indicates the inactivity. If any of the errors listed under "Error behavior" occurs while executing the function, ENO is set to FALSE.
|