Attribute 'instance-path'

The 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 application of the attribute 'reflection' to the corresponding POU, as well as application of the additional attribute 'no_init' to the STRING variable itself.

Syntax: {attribute 'instance-path'}

Insertion location: 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 FB_Sample 
VAR 
    {attribute 'instance-path'} 
    {attribute 'noinit'} 
    sPath : STRING; 
END_VAR 

An instance fbSample of the function block FB_Sample is defined within the MAIN program:

PROGRAM MAIN 
VAR 
    fbSample : FB_Sample; 
    sMyPath : STRING; 
END_VAR 
fbSample(); 
sMyPath := fbSample.sPath; 

Once the instance fbSample has been initialized, the string variable sPath is assigned the path of the instance fbSample, e.g. "<project>.MAIN.fbSample". In the main program this path is assigned to the variable sMyPath.

Attribute 'instance-path' 1:

You can define the length of a string as required (exceeding 255 characters, if necessary). Note, however, that the string is truncated (from the rear) if it is assigned to a variable whose data type is smaller.

See also: