Data Types
This topic contains the following sections:
Two data type classes: standard and safety-related
Safety-related and standard (non-safety-related) code is strictly distinguished in PLCnext Engineer. Therefore, also safety-related and standard variables, or more precise, data types, are distinguished.
- Standard (non-safety-related) IEC 61131-3-compliant data types. This includes elementary and user-defined data types.
- Safety-related elementary data types.
It is, for example, not possible to connect a variable with a standard data type to a formal parameter which expects a safety-related variable.
In safety-related code worksheets, safety-related and standard variables can be mixed and directly connected to each other. This corresponds to an implicit data type conversion which requires some rules to be observed.
Standard (non-safety-related) data types
In contrast to user-defined data types, elementary and generic data types do not need to be declared as they are predefined in the system, and thus immediately available in each POU.
User-defined data types such as ARRAYs, STRUCTs and STRINGs must be declared in a data type worksheet using the text editor.
The management of the data type worksheets is done in the 'Data Types' category in the COMPONENTS area on the right.
Here you add new data type worksheets, open existing worksheets for editing or structure the category by inserting folders. Each data type declaration block starts with the TYPE keyword and ends with the END_TYPE keyword. A declaration block can contain one or more data type declarations.
Declaration example
TYPE
graph : ARRAY[1..23] OF INT;
props :
STRUCT
height : REAL;
ident : INT;
END_STRUCT;
END_TYPE
Standard (non-safety-related) elementary data types can also be used in safety-related POUs. Rules have to be observed when mixing safety-related and standard data types.
Safety-related data types
Safety-related data types are exclusively elementary data types. Safety-related user-defined data types are not supported.
The supported safety-related elementary and safety-related generic data types do not need to be declared as they are predefined in the system, and thus immediately available in each safety-related POU.
Safety-related data types can only be used in safety-related POUs.
Representation of safety-related and standard variables
For easier distinction of standard and safety-related variables, all safety-related variables are displayed with a yellow color marking in safety-related SNOLD code worksheets, variables grids and Data Lists. Variables of standard data types are shown without color marking.
While programming safety-related FBD/LD code in SNOLD worksheets, the continuous data flow analysis in the code highlights the leading safety-related signal paths of a network by displaying them as thick yellow lines. Refer to the topic "Mixing Safety-related and Standard Variables in the Code" for details.
User-defined data types and data types worksheets
The following descriptions only apply to standard data types.
Safety-related user-defined data types are not supported.
How to manage data type worksheets
In the COMPONENTS area, data type worksheets are contained in the 'Programming' category under the 'Local' folder. Expanding the 'Data Types' folder shows the contained worksheets. Within the 'Data Types' folder, the data type worksheets can be grouped by subfolders.
Right-clicking a node (folder or worksheet) opens the context menu. The context menu contains only commands which can be applied to the selected node. In addition to the standard editing commands such as 'Cut', 'Copy', 'Paste', etc. the context menu provides the command to add new data type worksheets (see procedure below).
To organize the data type worksheets in the 'Local' folder, you can add a maximum of 3 subfolders via context menu. The digit behind the folder name indicates the number of contained worksheets. Worksheets can be simply moved via drag & drop between the user-defined folders.
Note
Elements that have been deleted in the COMPONENTS area are added to the RECYCLE BIN (if enabled in the 'Extras > Options' dialog under the 'Tool | Recycle Bin' category). You can restore the deleted elements using the 'Restore' command in the context menu of a deleted element in the RECYCLE BIN. |
Note
Elements that have been deleted in the COMPONENTS area are added to the RECYCLE BIN (if enabled in the 'Extras > Options' dialog under the 'General' category, section 'Recycle Bin'). You can restore the deleted elements using the 'Restore' command in the context menu of a deleted element in the RECYCLE BIN. |
How to open a data type worksheet
Data type declarations are edited using the text editor. The editor provides standard editing features such as 'Cut', 'Copy', 'Paste', etc. (also accessible via standard keyboard shortcuts) and syntax highlighting for declaration keywords.
To open a data type worksheet in the editors area, double-click the worksheet icon under 'COMPONENTS | Programming > Local > Data Types' (or any subfolder).
The toolbar located at the top of the worksheet provides access to the frequently used editor-specific commands. Each toolbar button provides a tooltip that shows a short description of the command and, if available, the predefined keyboard shortcut.
How to declare data types in a data type worksheet
- Either insert a new line in an existing declaration block or enter a new declaration block beginning with the TYPE keyword and ending with END_TYPE.
- Type the new data type declaration or use a prepared declaration template. Templates are available for user-defined data types ARRAY, STRUCT, and STRING. They can be inserted into the data type worksheet via the context menu command 'Insert Template'. After inserting a template, simply complete it with the actually needed names and values.
The editor supports you with an Intellisense function. When entering declarations, the editor recognizes valid declaration elements and shows them in a selection box. Pressing <Enter> or <Space> for an element in the list inserts the valid element.
Note
Elements and members of user-defined data types (ARRAYs and STRUCTs) can easily be initialized using the 'Init Value Configuration' editor. |
How to declare local constants in a data type worksheet
In the data type worksheet, you can use local or global constants for array boundaries and initialization values in arrays, structures, and enumerations.
To declare a local constant in the data type worksheet:
- Enter a declaration block beginning with the VAR CONSTANT keyword and ending with END_VAR.
- Enter the variable declarations in the declaration block.
(A global constant is created by selecting the 'Constant' attribute for a global variable defined in the variables table/data list.)
Note
Local constants can only be used in the same data type worksheet. |
How to define namespaces for user-defined data types
How to add a data type worksheet
- Right-click the folder 'COMPONENTS | Programming > Local > Data Types' (or any subfolder) and select 'Add Data Type Worksheet' from the context menu. (The 'Add' command is only available for folders.)The data type worksheet is added with a default name under the previously selected folder.To add a new folder under an existing folder, right-click the folder and select 'Add Folder' from the context menu (a maximum of 3 subfolders can be added).
- After adding an element in the COMPONENTS area, the name of the new element is in rename mode by default. You can either modify the proposed name or press <Enter> to accept it.
To rename the element later, right-click the icon and select 'Rename' from the context menu or press <F2> and
enter the desired name.