Attribute instance-path
You can add the pragma {attribute instance-path}
to a local string variable. This local string variable will be initialized with the path of the POU to which this string variable belongs. Applying this pragma presumes the use of the attribute reflection for the corresponding POU and the additional attribute noinit for the string variable.
Assume the following function block POU being equipped with the attribute 'reflection':
{attribute 'reflection'}
FUNCTION_BLOCK POU
VAR
{attribute 'instance-path'}
{attribute 'noinit'}
str: STRING;
END_VAR
In the main program PLC_PRG
an instance myPOU
of function block POU is called:
PROGRAM PLC_PRG
VAR
myPOU:POU;
myString: STRING;
END_VAR
myPOU();
myString:=myPOU.str;
After initialization of instance myPOU, the string variable str
gets assigned the path of instance myPOU, for example: PLC.Application.PLC_PRG.myPOU. This path will be assigned to variable myString within the main program.