Skip to main content

Tutorial: Using Client Animation

The example shows a visualization with three screens. A menu controls the navigation of the screens. The menu is hidden until it moves into view by means of a hamburger button. During the movement, the transparency of the menu is changed. After the screen is selected, the menu moves back out of view. The animation is computed entirely on the target system. The CODESYS visualization only defines the target values (positions, transparency).

Preparation

  1. Create a new standard project with the CODESYS Control Win controller.

  2. Add a Visualization object below the Application. Choose the name Visu_Main.

  3. Open the Visualization Manager in the editor and select the Support client animations and overlay of native elements option.

For more information, see the following: Settings

Creating the PLC_PRG program

The program checks whether the menu button has been pressed. If the menu bar is not visible (position –300), then the position is moved to the visible area (0). If the menu bar is already visible (position 0), then the position is moved to the hidden area.

  1. Open the PLC_PRG program in the editor.

  2. Input the following code into the declaration editor:

    PROGRAM PLC_PRG
    VAR
        iSelection : INT; // to switch the referenced visualization page
        xVisible: BOOL; // auxiliary variable to toggle the menu bar
        iMenuPos : INT := -300; // position of the menu bar
        xToggle: BOOL; // button variable to toggle the menu bar
    END_VAR                            
  3. Input the following code into the implementation:

    IF xToggle THEN
        xToggle := FALSE;
        IF xVisible THEN
            xVisible := FALSE;
            iMenuPos := -300;
        ELSE
            xVisible := TRUE;
            iMenuPos := 0;
        END_IF
    END_IF                           

Creating a menu bar

The menu bar has three menu items. A visualization screen is displayed by clicking the corresponding menu item.

  1. Insert a Visu_Menu visualization below the application.

  2. Open the object properties. In the Visualization tab, set the Visualization size to a Width of 300 and a Height of 180.

  3. Open the visualization in the editor.

  4. Select the Advanced option in the Properties view.

  5. In the upper left corner, add a button with a Width of 300 and a Height of 60.

  6. Label the button as "Visu 1". Set the font size to 24.

  7. Open the Input configurationOnMouseClick property.

  8. Select the Execute ST code action.

  9. Input the following ST code:

    PLC_PRG.iSelection := 0;
    PLC_PRG.xToggle := TRUE;                            
  10. Set the Button state variable → Digital variable property to PLC_PRG.iSelection=0.

  11. Add two more buttons named Visu 2 and Visu 3.

  12. Edit the button properties of Visu2 (PLC_PRG.iSelection = 1) and Visu3 (PLC_PRG.iSelection = 2).

    Result:

    _visu_img_animation_menu.png

Create more visualization pages

  1. Insert the Visu1 visualization below the application.

  2. Open the object properties. In the Visualization tab, set the Visualization size to a Width of 800 and a Height of 600.

  3. Change the background color of the screen (for example, light gray).

  4. Insert a Label object into the visualization screen and name the element (for example with Visu 1).

  5. Insert two more visualizations Visu2 and Visu3 below the application. Edit the properties in the same way as for Visu1.

Create the main visualization page

On this screen, you can see the menu bar and a button to show or hide the menu bar. The different visualization screens are navigated in a Frame visualization element.

  1. Open the properties of the Visu_Main visualization. In the Visualization tab, set the Visualization size to a Width of 800 and a Height of 600.

  2. Open the visualization in the editor.

  3. Insert a Frame element into the visualization.

    The Frame Configuration dialot opens.

  4. Add the Visu1 (Index 0), Visu2 (Index 1), and Visu3 (Index 2) visualizations.

  5. Set the property values of Position as follows: X = 0, Y = 0, Width = 800, and Height = 600.

  6. Set the value of the Switch frame variableVariable property to PLC_PRG.iSelection.

  7. Insert a Button element into the visualization.

  8. Set the property values of Position as follows: X = 0, Y = 0, Width = 800, and Height = 600.

  9. Set the value of the TextsText property to =.

  10. Set the value of the Text propertiesFont property to Arial; 36.

  11. Open the Input configurationOnMouseClick property.

  12. Select the Execute ST code action.

  13. Input the following ST code:

    PLC_PRG.xToggle := TRUE;
  14. Set the value of the Button state variableDigital variable property to PLC_PRG.xVisible.

  15. Insert the Visu_Menu visualization element from the Current Project category into the visualization.

  16. Set the property values of Position as follows: X = 0, Y = 0, Width = 300, and Height = 180.

  17. Set the value of the Absolute movementMovementX property to PLC_PRG.iMenuPos.

  18. Set the value of the State variablesInvisible property to not(PLC_PRG.xVisible).

  19. Set the property value of Animation duration to 2000.

    Result:

    _visu_img_animation_project.png

Downloading the project to the controller and starting the WebVisu

  1. Build the project and download it to the PLC.

  2. Start the project.

  3. In the browser, connect to the visualization (http://localhost:8080).

    The WebVisu connects to the controller and the visualization opens.

  4. In the visualization, click the menu button.

    The menu moves into view.

  5. Select a menu item.

    The visualization screen is selected and the menu moves back out of view.