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
Declaration of the enumeration color
:
{attribute 'to_string'} TYPE color : ( red := 0, blue := 1, green := 2 ); END_TYPE
Conversion 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, str_show_color
gets the value 'blue'
instead of '1'
as the conversion result.
See also