Attribute ‘instance-path’ΒΆ

This pragma can be applied to a local STRING variable and causes this local STRING variable to be initialized in sequence with the device tree path of the POU to which it belongs. This can be useful for error messages. The application of the pragma requires the application of the attribute 'reflection' to the associated POU, as well as the application of the additional attribute 'noinit' to the STRING variable.

Syntax:

{attribute 'instance-path'}

Insertion position: the line above the line with the declaration of the STRING variable.

Example

The following function block contains the attributes 'reflection', 'instance-path' and 'noinit'.

{attribute 'reflection'}
FUNCTION_BLOCK POU
VAR
 {attribute 'instance-path'}
 {attribute 'noinit'}
 str: STRING;
END_VAR

An instance myPOU of the function block POU is defined within the main program PLC_PRG:

PROGRAM PLC_PRG
VAR
 myPOU:POU;
 myString: STRING;
END_VAR
myPOU();
myString:=myPOU.str;

Following the initialization of the instance myPOU, the path of the instance myPOU is assigned to the string variable str, in the example PLCWinNT.Application.PLC_PRG.myPOU. This path is assigned in the main program to the variable myString.

Hint

You can define the length of a string to be whatever you like (even >255), but you must consider that the string will be truncated at the end if it is assigned to a variable whose data type is too small for it.

See also