Type
| Function |
Description
| The overloaded function TO_LWORD converts an input value of various data types into an output value of the data type LWORD (see description of the input for the supported data types). |
Parameters
| Input
IN
Data type: | The function is available for the following input data types:
- BOOL, BYTE, WORD, DWORD
- Integers: SINT, INT, DINT, LINT, USINT, UINT, UDINT, ULINT
- Floating point numbers: LREAL
- STRING
|
Output
OUT
|
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.The bit order/bit meaning of LREAL values complies with the IEC 60559 standard. Here, the basic double width floating format is defined. This bit order is copied unchanged to the output LWORD.
- LREAL input value:
The LREAL_TO_LWORD conversion complies with the latest standardization by the IEC 61131-3, 3rd edition.
- If the input data type is smaller than the LWORD output, the "unused" bits of the LWORD are set to FALSE (e.g. bits 8 to 63 for BYTE_TO_LWORD or SINT_TO_LWORD).
- If the range and precision of the input data type can be mapped to the range and precision of the output type, an implicit type conversion can be performed instead of using this function.
For the TO_LWORD function, this applies to BOOL, BYTE, WORD and DWORD inputs.
STRING conversion
- The string value has to be a valid bit literal of the output data type, otherwise the function returns the value 0x00 and the runtime error 'Format string failure' occurs.
- Additional characters except than whitespaces after or before the string value are not permitted. The function returns the value 0 and generates a 'Format String Failure' if the string value contains unallowed characters.
- All leading and trailing whitespaces in the input string are ignored in the return value.ASCII codes regarded as whitespaces:
Character | Value |
Horizontal tab | 9 (09h) |
Line feed | 10 (0Ah) |
Vertical tab | 11 (0Bh) |
Form feed | 12 (0Ch) |
Carriage return | 13 (0Dh) |
Blank | 32 (20h) |
Note
Controller stop on string error: The controller can be automatically stopped when a string error occurs. This allows you to locate the error in your project. To enable the automatic stop of the controller in case of a string error, activate the button in the Cockpit toolbar of the controller. |
|
Error behavior
| 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. As described, the value returned by the function in the error case depends on the value of the input (for example, if the input value is no valid bit literal, the function returns the value 0x00).
Error case | Output value |
LREAL: NaN
Note: ENO stays true in the error case. | Byte representation |
LREAL: inf+
Note: ENO stays true in the error case. | Byte representation |
LREAL: Inf-
Note: ENO stays true in the error case. | Byte representation |
String no valid bit literal or int number literal (with whitespaces) | 0x00 |
|
Examples
| Examples in ST
out := TO_LWORD(LINT#9223372036854775807); (* results in 16#7FFFFFFFFFFFFFFF *)
out := TO_LWORD(INT#-1); (* results in 16#000000000000FFFF *)
out := TO_LWORD(SINT#-16); (* results in 16#00000000000000F0 *)
out := TO_LWORD(DINT#-2147483648); (* results in 16#0000000080000000 *)
out := TO_LWORD(DINT#2147483647); (* results in 16#000000007FFFFFFF *)
out := TO_LWORD(DWORD#16#FFFFABCD); (* results in 16#00000000FFFFABCD *)
out := TO_LWORD('DWORD#16#0FAAABEF'); (* results in 16#000000000FAAABEF *)
|
Additional information
| EN/ENO behavior
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.
Note
ENO stays TRUE for an input value of data type LREAL that is not a real number (NaN) or a positive (inf+) or negative infinity (Inf-) value. |
|