Calling Visualization with Interface

You can declare an interface for parameters for a visualization that is to be referenced. Parameters are then transferred to the interface when the visualization is called at runtime. CODESYS therefore handles a visualization in a similar way to a function block.

First of all, declare the interface variables in the visualization interface editor. Then configure the parameters that are transferred to the interface by assigning a data-type-compliant application variable to each interface variable. The assignment is configured under the property References in the case of a frame or a tab control.

Depending on the display variant, the parameter transfer of local variables (with the variable type VAR) is limited. If you execute the visualization as an integrated visualization, you can only transfer local variables having a basic data type as parameters. If the visualization is called as CODESYS TargetVisu or CODESYS Web Visualization, you can also transfer parameters with a user-defined data type.

See also

User-controlled update of the transfer parameters

If you have configured visualization references and then save a change to the variable declaration for one of these visualizations in an interface editor, the dialog Updating the frame parameters automatically appears. It requests you to adapt the references. The dialog displays a list of all the visualizations affected, so that the parameter transfers can be reassigned at the changed interface.

On closing the dialog, the changes are accepted and the elements affected are displayed under the property References.

See also

Calling visualization with interface (VAR_IN_OUT)

  1. Open the visualization.

  2. Select the command Visualization ‣ Interface editor.

  3. Declare a variable in the interface editor.

    The visualization has an interface and the dialog Updating the frame parameters appears.

  4. Assign a type-compliant transfer parameter to the interface variables in all calls by entering an application variable under Value. Close the dialog.

    A transfer parameter is assigned at the points where the visualization is to be referenced. These now appear in the main visualization under the property References.

Example

The visualization visPie contains an animated, colored circle sector. The main visualization visMain calls the visualization visPie several times in a tab control. Color information, angle information and labelling are transferred via the interface pieItf. The circle sectors vary at runtime.

Visualization:code:`visPie:`

../_images/39d82df74c8d04cfc0a8640e000ad6f0
Properties of the element Pie.
Variable for begin pieItf.iStart
Variable for end pieItf.iEnd
Texts ‣ Text pieItf.sLabel
Color variable ‣ Normal state pieItf.dwColor

Interface of the visualization ‘visPie’:

VAR_IN_OUT
pieItf : DATAPIE;
END_VAR

Main visualization ‘visMain’:

Properties of the element Tab control:
References  
visPie  
Heading A
ItfPie PLC_PRG.pieA
visPie  
Heading B
ItfPie PLC_PRG.pieB
visPie  
Heading C
ItfPie PLC_PRG.pieC

Declaration of DATAPIE (STRUCT):

TYPE DATAPIE : //parameter type used in visPie
STRUCT
dwColor : DWORD; //color data
iStart : INT; // angle data
iEnd : INT;
sLabel : STRING;
END_STRUCT
END_TYPE

Application code:

PROGRAM PLC_PRG
VAR
iInit: BOOL := TRUE;

pieA : DATAPIE; // used as argument when visPie is called
pieB : DATAPIE;
pieC : DATAPIE;

iGrad : INT; // for animation of element pie
END_VAR

IF iInit = TRUE THEN
pieA.dwColor := dwBlue;
pieA.iStart := 0;
pieA.sLabel := 'Blue';

pieB.dwColor := dwGreen;
pieB.iStart := 22;
pieB.sLabel := 'Green';

pieC.dwColor := dwYellow;
pieC.iStart := 45;
pieC.sLabel := 'Yellow';

iInit := FALSE;
END_IF

iGrad := (iGrad + 1) MOD 360;

pieA.iEnd := iGrad;
pieB.iEnd := iGrad;
pieC.iEnd := iGrad;

Main visualization ‘visMain’ in runtime:

../_images/40fca3ae4c91445ac0a8640e01db5313

Outputting the instance name of a transfer parameter

In order to obtain and output the instance name of a transfer parameter, you can implement an interface variable (data type STRING) with the attribute parameterstringof under the variable type VAR_INPUT.

  1. Open the visualization.

  2. Select the command Visualization ‣ Interface editor.

  3. Declare an interface variable (VAR_IN_OUT).

    pieItf : DATAPIE;

  4. In the interface editor, declare a variable (VAR_INPUT) with attribute {attribute 'parameterstringof'}.

    {attribute 'parameterstringof' := 'pieItf'}

    sItfLabel : STRING;

  5. Save the changes.

    The dialog Updating the frame parameters doesn’t open.

  6. Assign an output text to the interface variable in the visualization next to the element Pie in the property Text.

    %s

  7. Assign the interface variable in the visualization next to the element Pie in the property Text.

    The element is labelled with the instance name.

Example

The visualization visPie contains an animated circle sector, which is filled with color. The main visualization visMain calls the visualization several times in a tab control. The interface declares a variable that will contain the instance name of the specified transfer parameter, with which each circle sector will be labelled at runtime.

Visualization:code:`visPie:`

../_images/39d82df74c8d04cfc0a8640e000ad6f0
Properties of the element:guilabel:`Pie.`
Variable for begin pieItf.iStart
Variable for end pieItf.iEnd
Text %s
Text variable sIftLabel
Color variable ‣ Normal state pieItf.dwColor

Interface of the visualization ‘visPie’:

VAR_INPUT
{attribute 'parameterstringof' := 'pieItf'}
sIftLabel : STRING;
END_VAR
VAR_IN_OUT
pieItf : DATAPIE;
END_VAR

Main visualization ‘visMain’:

Properties of the element Tab control:
References  
visPie  
Heading A
ItfPie PLC_PRG.pieA
visPie  
Heading B
ItfPie PLC_PRG.pieB
visPie  
Heading C
ItfPie PLC_PRG.pieC

Declaration of DATAPIE (STRUCT):

TYPE DATAPIE : //parameter type used in visPie
STRUCT
dwColor : DWORD;
iStart : INT;
iEnd : INT;
END_STRUCT
END_TYPE

Application code:

PROGRAM PLC_PRG
VAR
iInit: BOOL := TRUE;

pieA : DATAPIE; // used as argument when visPie is called
pieB : DATAPIE;
pieC : DATAPIE;

iGrad : INT; // for animating element pie
END_VAR

IF iInit = TRUE THEN
pieA.iStart := 0;
pieB.iStart := 22;
pieC.iStart := 45;

pieA.dwColor := dwBlue;
pieB.dwColor := dwGreen;
pieC.dwColor := dwYellow;

iInit := FALSE;
END_IF

iGrad := (iGrad + 1) MOD 360;

pieA.iEnd := iGrad;
pieB.iEnd := iGrad;
pieC.iEnd := iGrad;

Main visualization ‘visMain’ in runtime:

../_images/8d2f29895497ed4ec0a8640e0128b0eb