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.

NOTE: In the same Program Unit scope, the variable name duplication is not allowed.

Variables Definition and Attributes

The following table

Program Unit Variables

Definition and access

Nature

Type allowed

Input parameters

These parameters are read-only access in the Program Unit. They are used to transfer values to the Program Unit.

<inputs>

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.

<outputs>

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.

<inputs/outputs>

EDT, DDT, ARRAY, Device DDT, IODDT

Public variables

These local variables are accessible from another Program Unit using the effective parameter assignment.

<public>

EDT, DDT, ARRAY

Private variables

These local variables are only accessible inside the scope of the Program Unit to which they belong.

<private>

EDT, DDT, ARRAY, References (REF_TO), DFB, EFB

NOTE: A REF_TO can be initialized with a variable of the Program Unit which Nature is <private> or <public> .

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.

<external>

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 Effective Parameter. 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 Effective parameter field:

  • You can enter the variable name.

    or

  • Using the button ... you can open a Data selection dialog box and confirm the selected variables there with OK.

Example of a Data selection dialog box according to the scope:

NOTE: As the management of topological variable is only supported in the data editor of the application ( Address attribute of the variable), to map an interface variable of a Program Unit to a topological variable, you have to:
  • 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 Data Editor):

Name

Type

Glob1

BOOL

This is the definition of the variables belonging to the Prog1 scope (declared in the Program Unit Data Editor):

Name

Type

Nature

Glob1

BOOL

<external>

Input1

BOOL

<inputs>

Output1

BOOL

<outputs>

InOut1

BOOL

<inputs/outputs>

Pub1

BOOL

<public>

Priv1

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 Prog1

Usage in the code of Prog2

Usage in Prog2 as Effective Parameter

Usage in Sect1

Glob1

Glob1 (R/W)

No

Glob1 (R/W)

Glob1 (R/W)

PROG1.Input1

Input1 (R)

No

No

PROG1.Input1 (R)

PROG1.Output1

Output1 (R/W)

No

No

PROG1.Output1 (R/W)

PROG1.InOut1

InOut1 (R/W)

No

No

PROG1.InOut1 (R/W)

PROG1.Glob1

No

No

No

PROG1.Glob1 (R/W)

PROG1.Pub1

Pub1 (R/W(1))

No

PROG1.Pub1 (R/W(2))

PROG1.Pub1 (R/W(1))

PROG1.Priv1

Priv1 (R/W)

No

No

No

%S6

%S6 (R/W(3))

%S6 (R/W(3))

No

%S6 (R/W(3))

%M23

%M23

%M23

No

%M23

%MW17

%MW17

%MW17

No

%MW17

No: The variable could not be used

R: Read only

R/W: Read and write

(1) The write access can be restricted if Pub1 has the attribute RW program set to read only.

(2) The write access can be restricted in external usage if Pub1 has the attribute RW program external use set to read only.

(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 Purge Unused Variables .

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 Variables tab of the Program Unit data editor.

2

Right-click any column of the tab.

3

Select the menu command Purge Unused Variables from the context menu.

4

Confirm with Yes.

Result: The unused variables will be purged.

NOTE: This action can also be done from the Interface tab and Function Blocks tab.

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 Variables tab in the Program Unit data editor.

2

Filter the variables as described in the chapter Filtering of Data.

3

Select the menu command Export Filtered 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 Export 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 Variables 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 Export Selected 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 Export 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.

NOTE: The above export procedures can be also performed for the FB instances defined under the Program Unit by selecting the Function Blocks tab of the Program Unit data editor instead of the Variables tab.

Import a Subset of Variables and FB Instances

A subset of variables or FB instances may be imported via the Program Unit Data Editor.

NOTE: If the DDTs or associated DFB types have been exported (options selected on export), they are imported with the list of variables.

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 Variables tab in the Program Unit data editor.

2

Activate the Import 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 File name field.

4

Activate the Import 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.

NOTE: The above import procedure can be also performed for the FB instances defined under the Program Unit by selecting the Function Blocks tab of the Program Unit data editor instead of the Variables tab.

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

<inputs>

BOOL, EBOOL, and INT

R

R/W

ARRAY, DDT, STRING, and REF_TO

R

N/A

<outputs>

BOOL, EBOOL, and INT

R

R

ARRAY, DDT, STRING, and REF_TO

R

N/A

<inputs/outputs>

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

<public>

EDT, DDT, and ARRAY

R/W

Constant

R

<private>

EDT, DDT, ARRAY, DFB, and EFB

R/W

REF_TO, and constant

R

R: Read only

R/W: Read and write

NOTE: In the animation table dedicated to a Program Unit (sub folder Animation Tables under Program Unit directory), only variables that belong to this Program Unit can be added.

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 Project directory. For detailed information refer to chapter Animation Tables.

HMI Access

The following Program Unit variables are accessible from HMI/SCADA:

Parameters:

They have read only access by default.

NOTE: <inputs> parameter without assigned Effective parameter have read and write access by default.
Public:

They are read and write access by default.

Using the attribute RW program external used, 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 HMI variable 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