Attribute 'TcInitSymbol'
Using the pragma, you define whether a variable is used as an Init symbol. After the build process, the variables selected via this attribute are available in the tab “Symbol Initialization” of the PLC instance. In the "Value" column you can enter the desired values that are to be assigned to the variables before the start of the code execution. The values are copied into the variable value before the start of the code execution and overwrite the initial values that may have been specified during the variable declaration (e.g. nVar : INT := 123;
).
From TC3.1 Build 4024.4, the initial value specified during the declaration is adopted into the table as initial value. See below for more information on this.
Syntax: {attribute 'TcInitSymbol'}
Insertion location: Line above the declaration line of the variables
Sample:
PROGRAM MAIN
VAR
{attribute 'TcInitSymbol'}
nSample : INT := 123; //My variable comment
nAnotherVariable : INT;
END_VAR
This declaration leads to the following display on the Symbol initialization tab of the PLC instance:
Column filling:
The entries in the following columns are adopted from the variable declaration inside the PLC editor (refer also to the sample above):
- Name (= declaration path + symbol name)
- Value: Initial value of the variable declaration is only adopted into the table during the initial addition of the variables to the table; see below for more information.
- Type
- Comment
Initial entry in the table column "Value":
Scenario: A variable is declared with the attribute 'TcInitSymbol'. When this declaration is compiled for the first time, the variable is added to the symbol initialization table.
From TC3.1 Build 4024.4, the initial value of the variable declaration (123 in the above sample) is adopted into the table column "Value" during this addition of the variable to the table. With earlier TC3.1 versions, a zero initialization was used, so that the "Value" column was filled with the value 0.
Once the variable has been added to the symbol initialization table, you can enter the desired Init value in the table by changing the initial automatic entry. The variable nVar from the above sample is therefore initially added to the table with the value 123. If you subsequently change the table value to 456, the variable nVar is assigned the value 456 before the start of the code execution. The initial value of the variable declaration (123) is thus overwritten by the entry in the table (456).
Filling the table column "Unit":
The "Unit" column is used for OTCID data types and is automatically filled for these data types with the name of the TcCOM object, which belongs to the OTCID value in the "Value" column.
Sample:
PROGRAM MAIN
VAR
{attribute 'TcInitSymbol'}
sampleVar : OTCID; //sample comment
END_VAR
This declaration leads to the following display on the Symbol initialization tab of the PLC instance:
In order to provide a variable with a value, a selection menu can be opened that offers a choice of the possible values.
If in this case, for example, the value pair "08500010 'PlcAuxTask'" is selected, the ID (08500010) is entered in the "Value" column and the name (PlcAuxTask) is entered in the "Unit" column.
The value pair "Value" and "Unit" corresponds to the value pair that is shown on the Parameter (Init) tab.