Attribute instance-path
Le pragma {attribute instance-path}
peut être attribué à une variable locale de type chaîne. Celle-ci sera initialisée avec le chemin de l'arborescence du POU auquel elle appartient. Pour appliquer ce pragma, vous devez obligatoirement attribuer le pragma attribute reflection au POU correspondant et le pragma attribute noinit à la variable de type chaîne.
Supposons que le bloc fonction POU suivant inclue l'attribut 'reflection' :
{attribute 'reflection'}
FUNCTION_BLOCK POU
VAR
{attribute 'instance-path'}
{attribute 'noinit'}
str: STRING;
END_VAR
Une instance myPOU
du bloc fonction POU est appelée dans le programme principal PLC_PRG
:
PROGRAM PLC_PRG
VAR
myPOU:POU;
myString: STRING;
END_VAR
myPOU();
myString:=myPOU.str;
Après initialisation de l'instance myPOU, la variable str
de type chaîne se voit attribuer le chemin de l'instance myPOU (PLC.Application.PLC_PRG.myPOU, par exemple). Ce chemin sera attribué à la variable myString dans le programme principal.