Declaring Variables/FB Instances
This topic contains the following sections:
- Where can you declare variables/FB instances
- Declaring variables/FB instances in a variables table or Data List
- Declaring variables/FB instances while editing code
Where can you declare variables/FB instances
Variables and FB instances can be created and declared as follows:
- In the variables table of a POU. Double-click the POU in the COMPONENTS to open the 'Variables' editor.
- While editing the code worksheet of a POU. The code editors provide the context menu commands 'Create New Variable' or 'Create New Function Block Instance' for undeclared variables/FB instances. The command inserts the declaration into the respective table.Automatisms for global/external variables:
- When you declare an 'External' variable this way, the related global declaration ('Global' keyword) is also entered automatically in the Data List of the respective resource (controller or Safety PLC) provided that the POU is already instantiated in the controller or Safety PLC (i.e., a program instance exists or an FB instance within a program instance).The same applies when declaring an external variable in a safety-related POU: the related 'Global' declaration is automatically inserted in the Data List of the 'Safety PLC'.
- When you insert an existing global variable (declared as 'Global' variable in the Data List of the 'IEC 61131-3' node) into the code worksheet and no local variable with the same name exists in the 'Variables' table, the related external variable declaration ('Usage = External') is automatically added to the 'Variables' table.
- In the Data List of the 'IEC 61131-3' node in the PLANT. Double-click the 'IEC 61131-3' node in the PLANT to open the Data List editor.In the controller Data List, you can declare global variables for the standard controller. Furthermore, you can assign:
- global controller variables to process data items of I/O devices.
- global controller variables to standard Safety PLC variables thus defining exchange variables (communication between standard controller and Safety PLC).
- global controller variables to safety-related I/O variables (assigned to a safety-related input or output process datum). This way, a safety-related signal can also be read in the standard application.
- global controller variables to HMI tags.
- In the Data List of the 'Safety PLC' node. Double-click the 'Safety PLC' node in the PLANT to open the Data List editor.In the Safety PLC Data List, you can declare global variables for the Safety PLC using the 'Global' keyword. These variables can be of safety-related data types or standard data types. Depending on the data type of a variable, the following assignments can be made in the Safety PLC Data List:
- safety-related global variables of the Safety PLC can be assigned to safety-related process data items (safety-related I/Os).
Such a safety-related I/O variable can additionally be assigned to a global variable of the standard controller. This way, a safety-related signal can also be read in the standard application. - standard global variables of the Safety PLC can be assigned to standard process data items (standard I/Os).
- standard global variables of the Safety PLC can be assigned to standard variables of the controller (exchange variables) thus defining exchange variables. Exchange variables are always of a standard data type and enable the communication between standard controller and Safety PLC.
- No direct assignments to HMI tags are possible in the Data List of the Safety PLC. However, an HMI tag can be created for exchange variables.
- safety-related global variables of the Safety PLC can be assigned to safety-related process data items (safety-related I/Os).
- Both the variables tables and the Data Lists provide a context menu command for refactoring variables.
Note
All modifications on variable properties in one of the variables tables are immediately applied to all other variables tables where the corresponding variable is listed. |
Further Info
For detailed information on the 'Variables' and Data Lists, refer to the topic "Managing Declarations in Tables". |
Declaring variables/FB instances in a variables table or Data List
- To open the local variables table of the a POU, double-click the POU icon in the COMPONENTS area and activate the 'Variables' editor in the editor group.To open the Data List...
- of the standard (non-safety-related) controller, double-click the 'IEC 61131-3' node in the PLANT.
- of the Safety PLC, double-click the 'Safety PLC' node.
- In the table, select a line above which the new variable is to be inserted and use the 'Create Variable' button on the toolbar or the 'Create Variable' command from the context menu. Alternatively, go to the end of the table, left-click into the empty 'Enter ... here' input field and enter the name of the new variable.
In the variables table, clicking the arrow down icon on the right of the input field provides the list of all global variables that are not referenced in the current code worksheet so far.The new variable is added with default properties. - Set the variable properties (data type, usage, initial value, various flags, etc.) in the variables table.
In case of an FB instance, enter a valid instance name into the 'Name' field and select a function block in the 'Type' field.
When working with a PLCnext Technology controller, IN and OUT ports can be declared in program POUs.
Declaring variables/FB instances while editing code
Instead of first adding a variable/instance declaration to the variables table, and then inserting the relating variable or instance into a code worksheet, you can declare variables/instances directly on insertion into the code.
Note
IN and OUT ports for PLCnext Technology controllers cannot be created this way. Instead, you have to declare the port in the variables table and then insert the declared port into the code. |
To open a code worksheet of a POU, double-click the respective POU icon in the folder 'COMPONENTS | Programming > Local > Functions & Function Blocks' or 'Programs' (or any subfolder).