Using the input wizard
TwinCAT offers functionalities and wizards that facilitate code input during programming.
Dialog Input Assistant
The dialog offers all programming elements, which you can add at the current cursor position. Open the Input Assistant dialog with the command Input Assistant in the Edit menu, from the context menu, or with the keyboard shortcut [F2].
See also:
- TC3 User Interface documentation: Command Input Assistant
Auto Declare dialog
A dialog provides support for declaring variables. Open the Auto Declare dialog with the Auto Declare command in the Edit menu or via the context menu.
See also:
- TC3 User Interface documentation: Command Auto Declare
List components
The function List components is an input support feature in the text editor, which facilitates entering valid identifiers. The function can be enabled as follows:
- 1. Select the command Options in the Tools menu and then the category TwinCAT > PLC Environment > Smart coding.
- 2. Enable the option List components after typing a dot (.).
- If you then enter a dot instead of global variable, a selection list with all available global variables appears. Double-click on a variable in the selection list or press the [Enter] key to add the selected variable after the dot.
- If you enter a dot instead of a global variable or after a function block-instance variable or a structure variable, TwinCAT shows a corresponding selection list all global variables, all input and output variables of the function block or all structure components.
Double-click on a variable in the selection list or press the [Enter] key to add the selected variable after the dot.
If you also want to see the local variables of function block instances, in the TwinCAT options for smart coding enable the option List all instance variables in the input assistant. - If a component access (with dot) has already been made for a selection list, the last selected entry will be preselected for the next component access.
- If you enter any string and then press [Ctrl] + [space bar], a selection list appears with all available POUs and global variables. The first element in this list, which starts with the previously entered string, is automatically selected, and you can enter it in the editor by double-clicking or via the [Enter] key.
Matches with the entered string are highlighted in yellow in the selection list. When the entered string is changed, the displayed selection list is updated. - In the ST editor, you can filter the displayed selection list according to validity areas:
depending on the selection list displayed in each case, you can switch between the following selection lists using the [right arrow] and [left arrow] keys: - All entries
- Keywords
- Global declarations
- Local declarations
- If you call a function block, a method or a function and enter a left parenthesis for entering the POU parameters, TwinCAT shows a tooltip. This tooltip contains information on the parameters, as they are declared within the POU. The tooltip remains visible until you close it with a mouse click or by placing the focus outside the current view. If you close the tooltip accidentally, you can open it again with [Ctrl] + [shift key] + [space bar].
The pragma attribute 'hide' can be used to exclude variables from List components function. (Attribute 'hide') |
Examples:
Entering a structure variables:
Calling a function block:
Shortcut mode
Shortcut mode enables entering shortcuts for the variable declaration in the declaration editor and in the text editors, in which variable declarations are possible. You can enable this mode by ending a declaration line with the shortcut [Ctrl] + [Enter].
TwinCAT supports the following shortcuts:
- All identifiers apart from the last identifier in a line become variable identifiers of a declaration.
- The data type of the declaration is determined by the last identifier in the line. The following applies:
- B or BOOL results in BOOL
- I or INT results in INT
- R or REAL results in REAL
- S or STRING results in STRING
- If no data type is specified based on these rules, the data type is automatically set to BOOL, and the last identifier is not used as data type (see example 1).
- Each constant that is entered is interpreted as an initialization or a string length declaration, depending on the type of declaration (see examples 2 and 3).
- An address (such as in %MD12) is automatically extended with the AT attribute (see example 4)
- Text after a semicolon ";" is interpreted as a comment (see example 3).
- All other characters in the line are ignored (see exclamation mark in example 5).
Examples:
Example | Shortcut | resulting declaration |
---|---|---|
1 | bA | bA: BOOL; |
2 | nA nB I 2 | nA, nB: INT := 2; |
3 | sC S 2; C string | sC: STRING(2); // C string |
4 | X %MD12 R 5 | X AT %MD12: REAL := 5.0; |
5 | bE ! | bE: BOOL; |
Smart tag functions
Available from TC3.1 Build 4026 |
Smart tags facilitate the creation of program code by providing suitable commands for selection directly at the programming element. If you place the cursor on a programming element for which a smart tag function is available, the symbol appears. Clicking on will display the commands you can select. Available Smart Tags:
- For undeclared variables in the implementation part in the ST editor, the smart tag function provides the command Auto Declare.
See also:
- Declaring variables
- TC3 User Interface documentation: Dialog Options - Smart coding