TO_STRING block
Short summary
Name |
TO_STRING |
→POU type |
|
Category |
|
Conform to →IEC-standard |
currently restricted and more possible than defined in IEC-standard; see " Explicit conversion according to IEC-standard" |
Graphical interface |
|
Available since |
version 1.90.0 (for logi.CAD 3) |
Functionality
The blocks serves for explicitly converting the value connected to input IN into a value of data type STRING.
If the connected value is within the range of values overlapping for the data type of the input and for the result value STRING, the blocks returns this value. The format depends on the data type of the input:
Data type of input |
Format of return value |
String length |
BOOL |
TRUE or FALSE |
|
BYTE, WORD, DWORD, LWORDUSINT, UINT, UDINT, ULINTSINT, INT, DINT, LINT |
decimal value |
|
REAL, LREAL |
floating point or exponential value |
maximum length 25 (e.g. '-1.1234567890123456e+1234') |
CHAR, STRING |
as the input value |
as the input value |
TIME T#[-][d][h][m][s][ms][us] |
T#-xxxxxxxdxxhxxmxxsxxxmsxxxus Duration units (such as d) are skipped, if they are 0. |
length 30 |
TIME_OF_DAY TOD#[[-]xxxxd]hh:mm:ss[.us] |
T#-xxxxxxxdHH:MM:SS.mmmuuu The duration unit d is skipped, if it is < 1. |
length 26 |
DATE, if the value is within the possible range DATE#YYYY-MM-DD |
DATE#YYYY-MM-DD |
length 15 |
DATE, if the value is not within the possible range DATE#[-]xxxxd |
T#-xxxxxxxd |
length 11 |
DATE_AND_TIME, if the value is within the possible range DT#YYYY-MM-DD-hh:mm:ss[.us] |
DT#YYYY-MM-DD-HH:MM:SS.mmmuuu |
length 29 |
DATE_AND_TIME, if the value is not within the possible range DT#[-]xxxxd-hh:mm:ss[.us] |
DT#-xxxxxxxd-HH:MM:SS.mmmuuu |
length 28 |
Note: The format YYYY-MM-DD is only possible within the range 1970-01-01 to 2038-01-19 (0 - 24.855 days, 0 - 2.147.483.647 seconds).
Explicit conversion according to IEC-standard
The IEC-standard defines an explicit conversion of the following data types to STRING:
WSTRING, CHAR
The data type WSTRING is currently not supported in logi.CAD 3.
Inputs, return value
|
Identifier |
Description |
|
Inputs: |
IN |
REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT, LINT, TIME, BOOL, BYTE, WORD, DWORD, LWORD, STRING, CHAR, DATE_AND_TIME, DATE or TIME_OF_DAY |
value to be converted |
Return value: |
– |
STRING |
|
Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.
See:
"Blocks for safe logic" whether this block is supported for developing safety-relevant applications.
"Highlighting safe logic in the FBD-editor" for the effects when using the block as a block for safe logic .
Internal error diagnostic for block
The block checks the data type of the value connected to input IN and the return value respectively, before the block is executed. If the return value cannot be mapped in the available memory (the return value is too large), the output ENO of the block is set to value FALSE (or an equivalent). When you are using nested blocks with STRING values, observe that the memory for STRING values is restricted (see "In case of nested string blocks: How can the return value be entirely mapped ?" for details and examples).
Example for usage within ST-editor
The calculated values are evaluated by using the Assert block .
FUNCTION_BLOCK ExampleToString
VAR
result : STRING[
5
];
END_VAR
result := TO_STRING(IN := SINT#
12
);
Assert(result = STRING#
'12'
);
END_FUNCTION_BLOCK
When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.