Type
| Function |
Description
| The overloaded function TO_DWORD converts an input value of various data types into an output value of the data type DWORD (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, LWORD
- Integers: SINT, INT, DINT, LINT, USINT, UINT, UDINT, ULINT
- Floating point numbers: REAL
- 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 REAL values complies with the IEC 60559 standard. Here, the basic single width floating format is defined. This bit order is copied unchanged to the output DWORD.
-
REAL input value:: The REAL to DWORD conversion complies with the latest standardization by the IEC 61131-3, 3rd edition. The floating point value is stored according to the IEEE 754 standard.
-
Input size > output size: If the input data type has a bigger size than the DWORD output, only the bits 0 to 31 of the input value are considered.
-
Input size < output size: If the input data type is smaller than the DWORD output, the "unused" bits of the DWORD are set to FALSE (e.g. bits 8 to 31 for BYTE_TO_DWORD or SINT_TO_DWORD).
- 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_DWORD function, this applies to BOOL, BYTE and WORD 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) |
- If the input value is out of the range for the output data type, the overflow value is returned and the runtime error 'Format string failure' occurs (see the note below).
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 |
Overflow: input byte size too large | Overflow value |
REAL: NaN
Note: ENO stays true in the error case. | Byte representation |
REAL: Inf+
Note: ENO stays true in the error case. | Byte representation |
REAL: Inf-
Note: ENO stays true in the error case. | Byte representation |
String no valid bit literal or int number literal (with whitespaces) | 0x00 |
String: bit literal overflow | Overflow value |
|
Examples
| Examples in ST
out := TO_DWORD(LINT#4294967295); (* results in 16#FFFFFFFF *)
out := TO_DWORD(LINT#4294967296); (* results in 16#00000000 *)
out := TO_DWORD(INT#-1); (* results in 16#0000FFFF *)
out := TO_DWORD(SINT#-16); (* results in 16#000000F0 *)
out := TO_DWORD(LWORD#16#00000000ABABCD00); (* results in 16#ABABCD00 *)
out := TO_DWORD('LWORD#16#00000000A0A0CA0D'); (* results in 16#A0A0CA0D *)
|
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 REAL that is not a real number (NaN) or a positive (Inf+) or negative infinity (Inf-) value. |
|