Content assist in the ST-editor
A very instrumental function to quickly enter ST-code is Content Assist.
In this article: |
---|
Adding ST elements by adding keywords and using templates
How to add ST elements by adding keywords and using templates:
-
Position within the ST-code where you need the appropriate ST-code.
-
Start content assist: context menu within ST-editor, Source, Content Assist
Keyboard shortcut: Press Ctrl+Space.
Result: You see a list with all elements that are possible within the current context of the ST-code. -
Do one of the following:
-
Enter one or more letters. This displays a list with all elements fitting your input.
Example 1: Enter the beginning of a →keyword; such as:PRO
– A keyword is prefixed by iconin the list.
Example 2: Enter the beginning of a →template; such as:fun
– A template is prefixed by iconin the list.
For details on a template: Click on a template or select it with the cursor movement keys ↑ (Up) or ↓ (Down) in order to see the code for the template to the left of the list. -
Click an element in the list or select it (by using the mouse or the cursor movement keys) and press the Enter-key.
Result: The keyword or the code of the template is inserted at the current position. If the template contains one or more template variables, the first template variable is selected.What is a template variable?
A template variable marks an editable location in the code of the template. They can be resolves to a concrete value when the code of the template is evaluated in its context. They can also provide a list of alternative proposals valid at the given location. For instance, a template variable within a declaration template stands in for the identifier that is needed within a declaration.
-
Press the ESC-key to close the list and exit content assist.
-
-
If the inserted code contains template variables, overwrite these template variables as follows
-
As the first template variable is already selected, just type the requested identifier. (If the same template variable is repeatedly used in the code, the identifier is automatically entered at all of these places.)
-
Press the Tab-key to select the next template variable. Overwrite it as well.
-
Press the Tab-key until there are no template variables left to overwrite. Then you leave the code of the template.
-
Neuron has provided many templates for you to use. You can view them in the preferences: menu Window, Preferences, group ST-Object, Templates
There, you may also create your own templates or edit the existing ones.
Declaring external variables based on global variables
If you declare an →external variable (VAR_EXTERNAL...END_VAR
) as described under "Declaration of external variables in ST", it is imperative that you know the name and data type of the basic →global variable. If you declare an external variable and no global variable has been declared for it, the application cannot be built because the external variable cannot be resolved.
The best practice is to use the second list of the content assist of the ST editor so that an external variable is declared based on an already existing global variable and so that the external variable is added in the ST code where the content assist has been started:
-
Position the mouse pointer at the position where you want to add the external variable. Usually, this is in the body of the language element.
-
Start the content assist: From the context menu of the ST editor, select Content Assist. Alternative: Press Ctrl+Space.
Result: A list is displayed with all →variables already declared in the POU and with all available →functions and →function blocks. -
Now press Ctrl+Space again.
Result: The list changes to display the global variables (icon) that have been declared in →programs or →resources (within a PLC-object). The entry for the global variable includes its data type. Example:
portSetting (LocalConfiguration.local) : INT
– Meaning: This is the global variable with nameportSetting
and →data typeINT
. The global variable is declared in the →configurationLocalConfiguration
and the resourcelocal
. -
Enter one or more letters. This displays a list with all elements fitting your input.
Example: Enterport
. The list provides all global variables containing the textport
. -
Click an element in the list or select it (by using the mouse or the cursor movement keys) and press the Enter-key.
If you want to close the list without any action, click the primary mouse button outside the input field or press the ESC-key.
Good to know |
---|
|