Inserting FUs/FBs and Variables
This topic applies to code worksheets in FBD/LD, NOLD, SNOLD and SFC.
In the graphic editor, objects can be inserted
- on a free connection point to auto-connect the objects, or
- by replacement of existing objects.
- In FBD/LD, objects can also be inserted at any free position (empty cell) to connect them afterwards.
In NOLD and SNOLD, it depends on the position, whether the insertion into an empty cell creates a new code section or the object is inserted on the right side of the right power rail. See procedures below for details.
Insertion of objects can be done via:
- dragging & dropping functions/functions blocks from the COMPONENTS area into the code worksheet.
- dragging & dropping variables from the variables table or a data list into the code worksheet.
- keyboard using Intellisense.
- toolbar command buttons and context menu. Common elements such as connector, return, etc. can be inserted by the corresponding toolbar button or context menu command. A description of these common elements can be found in the topic "Constants, Jumps/Labels, Returns, Connectors".
Further Info
For a description how to insert objects into an existing LD network, refer to the topic "Editing LD Networks". |
Inserting Functions/Function Blocks
The block color and the icon in the upper left corner of the symbol indicate the origin of the function (locally created, contained a user library or system library). Refer to the section "FU/FB symbol indicates origin" for details.
Insert functions/function blocks via drag & drop
- In the COMPONENTS area, open the respective 'Functions and Function Blocks' folder and select the desired subfolder.
- Drag the function/function block into the code worksheet from the COMPONENTS area and:
- drop it on a free connection point of another object to which you want to connect it.
- drop it on an existing function/function block to replace the object by the selected one (refer to the topic "Replacing/Updating Functions/Function Blocks").
- drop it on an empty cell.
In NOLD and SNOLD, it depends on the position, whether the insertion into an empty cell creates a new code section or the object is inserted on the right side of the right power rail.
When pasting an object in a NOLD/SNOLD worksheet by dropping it, markings are shown while dragging the object. These markings indicate whether an object can be dropped (pasted) at the current mouse position and what will happen when dropping it:
- If you have inserted a function block, an instance name is proposed by the programming system (shown above the FB block; 'CTD_1' in the example below). This FB instance name must be declared in the related variables table.
Insert a function/function block via keyboard using Intellisense
- In the code worksheet, open the Intellisense selection box as follows.
- Double-click a connection point, e.g., a formal parameter or variable if you want to connect the new object directly on insertion.
- Double-click an empty cell or set the mouse cursor in an empty cell and press <Enter> if you want to insert an unconnected object.
In NOLD and SNOLD, it depends on the position of the selected empty cell whether the newly inserted block creates a new code section or is inserted on the right side of the right power rail:
When inserting an element into a cell inside the frame of an existing network, it appears right of the right power rail. Example:
When inserting an element into a cell outside the frame of an existing network, a new code section is created. Example:
- In the edit box, either type the name of the object to be inserted or open the selection box and browse the drop-down list for the desired object. Press <Enter> to confirm your selection.
- If you have inserted a function block, an instance name is proposed by the programming system (shown above the FB block; 'CTD_1' in the example below). This FB instance name must be declared in the related variables table.
Further Info
Refer to the topic "Editing/Replacing/Updating FUs and FBs" for information how to add function inputs, replace blocks and how to update instances of user-defined function blocks. |
Inserting Variables
In code worksheets, you can insert already declared variables and new variables. Inserting a variable into the code worksheet can be done either via the variables table by dragging and dropping the variable into the code worksheet or directly in the code worksheet.
Further Info
For a description how to assign variables to an LD object, refer to the topic "Editing LD Networks". |
Insert one or more already declared variable(s) via drag and drop from the variables table
- In the variables table, left-click into the row header of the desired variable to select it. To select several variables, left-click the row headers of the variables to be selected while holding down the <Ctrl> key (selection of non-adjacent table lines) or <Shift> key (selection of adjacent table lines).
- Keep the mouse button pressed and drag the selection into the code worksheet and drop it at the desired position.When dragging the variable into a code worksheet that already contains a network, the valid insertion positions for the variable within the network are displayed by colored markers. As soon as a valid connection is detected by the editor when dragging the variable, the connection line is shown in green (in the following example the 'Reset' variable is dropped on the RESET formal parameter of the CTUD function block).
Insert an already declared variable directly in the code worksheet
- In the code worksheet, set the cursor at the desired position.
- To insert a variable directly connected to another object (for example, a formal parameter of a function block input) or to replace an existing variable, left-click the object/variable.
- To insert an unconnected variable, set the cursor into an empty cell in the code worksheet.In NOLD and SNOLD, it depends on the position, whether the insertion into an empty cell creates a new code section or the object is inserted on the right side of the right power rail. See procedures below for details.
- Press <F7> or click the 'Insert Object' button on the toolbar
.
- In the appearing selection box, browse for the variable to be inserted (type the first character(s) of the variable to facilitate your search), select the variable and press <Enter>.To insert an input/output variable of an FB instance or a member of a STRUCT variable, enter the function block instance or STRUCT variable followed by a dot. The appearing selection box lists all input and output variables of the corresponding FB instance resp. all members of the corresponding STRUCT variable.
Note
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. |
Insert and declare a new variable
- In the code worksheet, set the cursor at the desired position.
- To insert a variable directly connected to another object (for example, a formal parameter of a function block input), select the corresponding object.
- To insert an unconnected variable, set the cursor into an empty cell in the code worksheet. In NOLD/SNOLD, the cursor must be set inside the network border (as shown below). In this case, the new unconnected object will be inserted on the right of the right power rail:
- To replace an existing variable, left-click the object/variable.
- Press <F7> or click the 'Insert Object' button on the toolbar
.
- In the appearing input box, enter the name of the new variable and press <Enter>.
- Right-click on the variable and select 'Create New Variable > Variable type' from the context menu.See also topic "Variable Declaration Keywords" for details.
Note
IN and OUT ports for PLCnext Technology targets cannot be created via the context menu. |
The appropriate declaration is inserted with the suitable declaration keyword into the 'Variables' table.Which variable types can be selected from the context menu depends on the current POU type. In programs and functions, for example, local and external variables can be declared. In FBs, additionally input and output variables are possible.
Note
If you declare an 'External' variable this way, the related global declaration (with the 'Global' keyword) is also entered automatically in the Data List of the respective resource (PLC or Safety PLC) provided that the POU is already instantiated in the PLC or Safety PLC (i.e., a program instance exists or an FB instance within a program instance). |
- Set the variable properties 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.
Editing the properties of the variable at the cursor position or marked variable
At the lower border of the code editor, a single line grid editor is available. It shows the properties of the variable at the cursor position or which is selected in the code. Instead of first switching to the variables grid of the POU, you can edit the properties of the variable without leaving the code editor. Exception: The variable name cannot be modified here. Use the variables grid or refactoring tool instead.
Assign a global variable to a process data item
Note
If a Safety PLC is included in your project, standard and safety-related data are strictly distinguished. Therefore, resource-global variables of the Safety PLC (these can be of standard and safety-related data types) are declared in the 'Data List' of the Safety PLC. Here, you can assign Safety PLC-global variables to process data items. |
The assignment of global variables to process data items (I/O terminals, made available by the I/O devices in the PLANT) has to be done in the 'Data List' of the 'IEC 61131-3' node or of the involved I/O device.
In the following example, the global variable 'TemperatureCurrent' of the standard (non-safety-related) controller is connected to the process data item 'IN01' provided by a temperature input module.
- Double-click the 'IEC 61131-3' node or the I/O device node in the PLANT ('IEC 61131-3' node in our example, see number (1) in the figure below).
- If not visible, open the 'Data List' table in the editors area (2).
Note
Depending on the selected element in the PLANT tree, the 'Data List' table shows more or less process data items. If opened for one specific device, only the process data items of this device are shown. For the 'IEC 61131-3' node, all standard (non-safety-related) process data items of all PLANT modules can be assigned. |
- In the 'Data List', table left-click into the 'Process Datum' cell of the variable to be connected (3) and select the desired process data item from the appearing selection list (4). The selection list provides only those process data items which are allowed to connect to the selected variable (suitable data type).
 | To remove the assignment of a process data item to a variable, right-click the variable and select 'Disconnect Process Datum'. Alternatively, select the variable and click the 'Disconnect Process Datum' button on the 'Data List' toolbar or press the <Del> key. |
 | Variables that are no longer needed in the 'Data List' table can be removed via the context menu command 'Remove all unused global variables' or the corresponding toolbar button. |