Attribute: instance-path
The pragma can be applied to a local string variable. It has the effect that this local string variable in sequence with the device tree path of the POU which it belongs to is initialized. 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'}
Insert location: The line above the line with the declaration of the STRING
variable.
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
.
Important
You can define the length of a string however you want (even >255). However, you have to 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.