Attribute: to_string
The pragma affects how the result of converting an enumeration component with the TO_STRING operator is output. If the enumeration declaration has the pragma, then the name of the enumeration component appears as a string instead of the numeric value.
Syntax:
{attribute 'to_string'}
Insert location: First line above the declaration part of the enumeration.
Example 290. example
Declaration of the enumeration color:
{attribute 'to_string'}
TYPE COLOR:
(
red := 0,
blue := 1,
green := 2
);
END_TYPEConversion with TO_STRING:
PROGRAM PLC_PRG
VAR
i_color: COLOR;
s_show_color: STRING;
END_VAR
i_color := 1;
s_show_color := TO_STRING(i_color);In this case, s_show_color gets the value 'blue' instead of 1 as the conversion result.