Using Input Assistance

CODESYS provides tools and features to help you code when creating programs.

Input Assistant

The input assistant provides all program elements that you can insert at the current cursor position. Open the Input Assistant dialog by clicking Edit ‣ Input Assistant or by pressing F2.

See also

Dialog ‘Auto Declare’

This dialog supports the declaration of variables.

See also

“List components”

The “List components” function is an input tool in textual editors to help you input valid identifiers. Activate this function by clicking Tools ‣ Options and then the SmartCoding category. Select the List components after typing a dot (.) check box.

  • If you type a dot (.) instead of a global variable, then a drop-down list opens with all available global variables. You insert the selected variable after the dot by double-clicking a variable in the drop-down list or by pressing Enter.

  • If you type a dot (.) instead of a global variable after a function block instance variable or a structure variable, then CODESYS opens a drop-down list with all global variables, all input and output variables for the function block, or all structure members.

    You insert the selected variable after the dot by double-clicking a variable in the drop-down list or by pressing Enter.

    Note: When you also want to choose from the local variables of function block instances, select the Show all instance variables in input assistant option in the CODESYS options (SmartCoding category).

  • If a component access (with a dot) for a drop-down list has already happened, then the last selected entry is preselected at the next component access.

  • When you type any sequence of characters and then press Ctrl+Space, a drop-down list opens with all available POUs and global variables. The first element in this list that starts with the sequence of characters is selected by default and you can insert it by double-clicking it or by pressing Enter.

    Matches with the entered character string are highlighted in yellow in the drop-down list.

    If the entered character string is changed, then the displayed drop-down list is refreshed.

  • In the ST editor, you can filter the displayed drop-down list by scopes:

    Depending on the displayed drop-down list, you can use the Arrow right and Arrow left keys to toggle between the following drop-down lists:

    • All items

    • Keywords

    • Global declarations

    • Local declarations

  • CODESYS displays a tooltip if you type an opening parenthesis for a POU parameter when calling a function block, a method, or a function. This tooltip includes information about the parameters as they are declared in the POU. The tooltip remains open until you click to close it or you change the focus away from the current view. If you accidentally close the tooltip, then you can reopen it by pressing Ctrl+Shift+Space.

Note

You can use the pragma attribute 'hide' for excluding variables from the “List components” feature.

Examples

Typing structure variables:

list

Calling a function block:

See also

Short form feature

The short form feature allows you to type abbreviated forms for variable declarations in the declaration editor and in textual editors where variables declarations are possible. Use this feature by pressing Ctrl+Enter to end a declaration line.

CODESYS supports the following short forms:

  • All identifiers become variable identifiers except the last identifier of a line.

  • The data type of the declaration is determined by the last identifier of the line. The following applies:

    • B or BOOL yields BOOL

    • I or INT yields INT

    • R or BOOL yields BOOL

    • S or STRING yields STRING

  • If a data type is not defined using this rule, then the data type is automatically BOOL, and the last identifier is not used as the data type (see Example 1).

  • Depending on the type of declaration, every defined constant becomes an initialization or string length definition (see Example 2 and 3).

  • An address, such as %MD12, is automatically extended with the AT attribute (see Example 4).

  • Any text after a semicolon (;) is converted into a comment (see Example 3).

  • All other characters in the line are ignored (see exclamation mark in Example 5).

Examples

Example

Short Form

Resulting declaration

1

A

A: BOOL

2

A B I 2

A, B: INT := 2;

3

ST S 2; A string

ST:STRING(2); (* A string *)

4

X %MD12 R 5 Real Number

X AT %MD12: REAL := 5.0;(* Real Number *)

5

B !

B: BOOL

See also

Smart tag functions

Smart tags make it easier to write program code by suggest appropriate commands directly at the programming element. When you place the cursor over a programming element that has a smart tag function, the symbol appears. When you click the symbol, the commands that you can choose from are shown. Available smart tags:

  • The smart tag function provides the Declare Variable command for undeclared variables in the implementation part of the ST editor.

See also