Attribute instance-path

Overview

You can add the pragma {attribute instance-path} to a local string variable. This local string variable will be initialized with the Applications tree 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.

Syntax

{attribute 'instance-path'}

Example

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.

NOTE: The length of a string variable may be arbitrarily defined (even >255). However, the string will be cut (from its back end) if it gets assigned to a string variable of a shorter length.