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
- Command ‘Interface Editor’
- Visualization element ‘Frame’
- Visualization Element ‘Tab’
- Dialog ‘Updating the frame parameters’
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
)
Open the visualization.
Select the command
.Declare a variable in the interface editor.
- ⇒
The visualization has an interface and the dialog Updating the frame parameters appears.
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:`
Variable for begin | pieItf.iStart |
Variable for end | pieItf.iEnd |
pieItf.sLabel |
|
pieItf.dwColor |
Interface of the visualization ‘visPie’:
VAR_IN_OUT
pieItf : DATAPIE;
END_VAR
Main visualization ‘visMain’:
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:
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
.
Open the visualization.
Select the command
.Declare an interface variable (
VAR_IN_OUT
).- ⇒
pieItf : DATAPIE;
In the interface editor, declare a variable (
VAR_INPUT
) with attribute{attribute 'parameterstringof'}
.- ⇒
{attribute 'parameterstringof' := 'pieItf'}
sItfLabel : STRING;
Save the changes.
- ⇒
The dialog Updating the frame parameters doesn’t open.
Assign an output text to the interface variable in the visualization next to the element Pie in the property Text.
- ⇒
%s
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:`
Variable for begin | pieItf.iStart |
Variable for end | pieItf.iEnd |
Text | %s |
Text variable | sIftLabel |
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’:
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: