Naming Rule
The duplication of a variable name is possible when the variables belong to different scopes:
Two Program Unit scopes, or
The global scope and a Program Unit scope.
Variables Definition and Attributes
The following table
Program Unit Variables |
Definition and access |
|
allowed |
---|---|---|---|
Input parameters |
These parameters are read-only access in the Program Unit. They are used to transfer values to the Program Unit. |
|
EDT, DDT, ARRAY, References (REF_TO), Device DDT |
Output parameters |
These parameters are read/write access in the Program Unit. They are used to transfer values from the Program Unit. |
|
EDT, DDT, ARRAY, References (REF_TO), Device DDT |
Input/Output parameters |
These parameters are read/write access in the Program Unit. They are used to transfer values to and from the Program Unit. |
|
EDT, DDT, ARRAY, Device DDT, IODDT |
Public variables |
These local variables are accessible from another Program Unit using the effective parameter assignment. |
|
EDT, DDT, ARRAY |
Private variables |
These local variables are only accessible inside the scope of the Program Unit to which they belong. |
|
EDT, DDT, ARRAY, References (REF_TO), DFB, EFB NOTE: A REF_TO can be initialized with a variable of the Program Unit which is or .
|
External variables |
The global variables are accessible in the sections of the Program Unit. These variables must be declared with the same name and data type as the ones defined in the global project. |
|
EDT, DDT, ARRAY, References (REF_TO) |
Parameter Assignment
The following table gives the rule for assigning to parameters of a Program Unit:
Program Unit Parameters |
Assignment |
---|---|
Input parameters |
Optional except for ARRAY, DDT, Device DDT, STRING, and REF_TO |
Output parameters |
|
Input/Output parameters |
Compulsory |
The way to assign variable for Program Unit parameter (formal parameter) is done via the attribute
. The assigned variable is a global variable or a public variable of another Program Unit.The Program Unit parameters and the variables which are assigned to must be of the same data type. For example, if the data type INT is defined for the input parameter, then you cannot assign to this parameter a variable of the data type DINT nor REAL.
The only exceptions are for BOOL and EBOOL data types which can be mixed. For example, a %Mi internal bit of data type EBOOL can be assigned to an input parameter defined as BOOL.
You have the following options to enter the variable in the
field:You can enter the variable name.
or
Using the button
you can open a dialog box and confirm the selected variables there with .
Example of a Data selection dialog box according to the scope:

define a global located variable in the Data editor, then
assign the global variable as an effective parameter of the Program Unit.
Program Unit Execution
The copy of the data from effective parameter to input formal parameter is performed before the Program Unit execution.
The copy of the data from output formal parameter to the effective parameter is performed after the Program Unit execution.
The following figure shows how a Program Unit is executed:

(1) Under the global scope.
(2) Under the scope of another Program Unit.
Example of Program Unit Variable Usage
The following example defines two Program Units and a section under a task:

This is a variable belonging to the global scope (declared in the
):
|
|
---|---|
|
BOOL |
This is the definition of the variables belonging to the Prog1
scope (declared in the ):
|
|
|
---|---|---|
|
BOOL |
<external> |
|
BOOL |
<inputs> |
|
BOOL |
<outputs> |
|
BOOL |
<inputs/outputs> |
|
BOOL |
<public> |
|
BOOL |
<private> |
The following table shows the syntax, the usage, and the access rights of the variables according to their nature and scope:
Variable |
Usage in |
Usage in the code of |
Usage in |
Usage in |
---|---|---|---|---|
|
|
No |
|
|
|
|
No |
No |
PROG1.Input1 (R) |
|
|
No |
No |
|
|
|
No |
No |
PROG1.InOut1 (R/W) |
|
No |
No |
No |
PROG1.Glob1 (R/W) |
|
|
No |
|
|
|
|
No |
No |
No |
|
|
|
No |
|
|
|
|
No |
|
|
|
|
No |
|
No: The variable could not be used R: Read only R/W: Read and write (1) The write access can be restricted
if (2) The write access can be restricted
in external usage if (3) The write access depends on the write access of the system bit or system word. |
Purge of Unused Variables
To purge unused variables, the Program Unit data editor tabs provide the context menu
.The purge depends on the check boxes (EDT, DDT, IODDT, and Device DDT), i.e. only the visible data (of checked types) will be purged:
Step |
Action |
---|---|
1 |
Select the tab of the Program Unit data editor. |
2 |
Right-click any column of the tab. |
3 |
Select the menu command from the context menu. |
4 |
Confirm with .Result: The unused variables will be purged. |
Export a Subset of Variables and FB Instances
A subset of variables or FB instances may be filtered out and/or selected via the Program Unit Data Editor.
Program Unit variables and FB instances are saved in source format .XPU.
Whatever the variables or FB instances you export, you can choose two options:
export with or without the content of all the DDTs used,
export with or without the content of all the DFB types used.
By default, the two "export with" options are selected.
To export filtered variables:
Step |
Action |
---|---|
1 |
Select the tab in the Program Unit data editor. |
2 |
Filter the variables as described in the chapter Filtering of Data. |
3 |
Select the menu command from the context menu.Result: A dialog box appears on the screen. |
4 |
Select the target folder for the export (directory tree) then enter the file name. |
5 |
Select the export mode (with or without DDT, DFB type). Result: When a "with" option is selected, the corresponding box is checked. |
6 |
Activate the command.Result: A progress indicator shows how the export is progressing. |
7 |
A message is displayed in the display window to indicate that the export is finished. |
To export selected variables:
Step |
Action |
---|---|
1 |
Select the tab in the Program Unit data editor. |
2 |
Click on a variable to select it in the Program Unit data editor. You can select multiple variables by holding down the Alt or Ctrl keys. |
3 |
Select the menu command from the context menu.Result: A dialog box appears on the screen. |
4 |
Select the target folder for the export (directory tree) then enter the file name. |
5 |
Select the export mode (with or without DDT, DFB type). Result: When a "with" option is selected, the corresponding box is checked. |
6 |
Activate the command.Result: A progress indicator shows how the export is progressing. |
7 |
A message is displayed in the display window to indicate that the export is finished. |
Import a Subset of Variables and FB Instances
A subset of variables or FB instances may be imported via the Program Unit Data Editor.
If the list of variables already exists in the current Program Unit, the software asks you to choose between the following options:
keep the component of the current Program Unit,
replace the Program Unit component by the one from the import file,
rename the imported component, allowing you to keep both components.
To import variables:
Step |
Action |
---|---|
1 |
Select the tab in the Program Unit data editor. |
2 |
Activate the command from the contextual menu (by clicking the right mouse button).Result: a dialog box appears on the screen. |
3 |
Choose the source folder for the import (directory tree) then select the file to be imported (XPU or XSY). Result: the name of the file then appears in the field. |
4 |
Activate the command.Result: a progress indicator shows how the import is progressing. |
5 |
A message tells you when the import is complete. If errors occur during the import, they are indicated by a message in the display window. |
Access Right for Animation Tables in a Program Unit
The access right for object of an Animation table in a Program Unit depends on the nature of the variable:
Nature |
Type |
Access Right |
|
---|---|---|---|
With Effective Parameter |
Without Effective Parameter |
||
|
BOOL, EBOOL, and INT |
R |
R/W |
ARRAY, DDT, STRING, and REF_TO |
R |
N/A |
|
|
BOOL, EBOOL, and INT |
R |
R |
ARRAY, DDT, STRING, and REF_TO |
R |
N/A |
|
|
BOOL, |
R |
R |
EBOOL, EDT, ARRAY, DDT, STRING, and REF_TO |
R |
N/A |
|
R: Read only R/W: Read and write N/A: Not applicable |
Nature |
Type |
Access Right |
---|---|---|
|
EDT, DDT, and ARRAY |
R/W |
Constant |
R |
|
|
EDT, DDT, ARRAY, DFB, and EFB |
R/W |
REF_TO, and constant |
R |
|
R: Read only R/W: Read and write |
The implementation of animation tables dedicated to a Program Unit and its management is similar to the ones in the Animation Tables.
folder in the directory. For detailed information refer to chapterHMI Access
The following Program Unit variables are accessible from HMI/SCADA:
Parameters: | They have read only access by default. NOTE: <inputs> parameter without assigned have read and write access by
default.
|
Public: | They are read and write access by default. |
Using the attribute
, you can restrict the default access as:Read only for public variables.
No access for public variables and parameters.
In the Program Unit data editor, select the attribute
to embed the variable in the data dictionary. These variables will be visible for HMI/SCADA.To access the Program Unit variable from HMI/SCADA, use the variable
syntax: <Program Unit name>.<variable
name>
. For example: Program1.MyVar