Type
| Function |
Description
| The overloaded function TO_TIME converts an input value of various data types into an output value of the data type TIME (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:
- SINT, INT, DINT, LINT, USINT, UINT, UDINT, ULINT
- STRING, WSTRING
- LTIME
|
Output
OUT
|
Conversion rules
| ANY_INT conversion
The time conversion is based on milliseconds. A value of 1 corresponds to a time of 1 millisecond. If the input value is outside the permissible range of the TIME output value, an overflow occurs.
Examples in ST: out := TO_TIME(DINT#360000); (* results in T#6m *) out := TO_TIME(ULINT#2147483650); (* results in T#-24d20h31m23.646s *)
LTIME conversion
- If the result value is too short to hold the converted time, the time will be cut off.
- If the LTIME input value is outside the permissible range of the TIME output value, an overflow occurs.
Examples in ST: out := TO_TIME(LTIME#30h); (* results in T#1d6h *) out := TO_TIME(LTIME#-24d20h31m24s); (* results in T#24d20h31m23.296s*) out := TO_TIME(LTIME#23d17h2m47.295501s); (* results in T#23d17h2m47.295s *); digits less than 1 ms are cut off
ANY_STRING conversion
- The connected string must correspond to a valid time literal. The time literal has to be specified in the format: Time_prefix#valuewith Time_prefix = T, t, TIME or time. The value must be a valid TIME value with unit specifier (for example, ms).Examples: T#23s, t#5d10h
- Additional characters after or before the time literal are not permitted.
- 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 STRING value does not contain a valid time prefix or an empty string, the runtime error 'Format string failure' is written to the MESSAGES window and the function returns the value T#0. Program execution is not interrupted, and the controller remains in RUN state (see the note below).Example: out := TO_TIME('aaT#3daa'); (* results in T#0 *)
- If the input value exceeds the range of the TIME 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 a non-literal string, the function returns the value 0).
Error case | Output value |
Overflow value | Overflow value |
Non-literal string | 0 |
|
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.
|