Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Call or switch visualization through structured text program code (ST)

sbt-277
2023-06-01
2023-06-04
  • sbt-277 - 2023-06-01

    I created a simple function block for a green lamp and red lamp:

    FUNCTION_BLOCK GreenLamp
    VAR
        LampActive : BOOL;
    END_VAR
    

    (Red lamp is the same, just the different name)

    And I created a visualization with just one lamp called "GreenLamp" and another one called "RedLamp" with the following interface configuration:

    VAR_IN_OUT
        Data : GreenLamp;
    END_VAR
    

    (Red lamp is the same, just the different type name)

    In my main program I instantiated two instances of the green and one instance of the red lamp:

    PROGRAM SR_Main
    VAR
        L1 : GreenLamp;
        L2 : GreenLamp := (LampActive := TRUE);
        L3 : RedLamp;
    END_VAR
    

    Now I will have a main visualization where I want to display and switch between the GreenLamp or RedLamp visualization when some requirements are met in code or when a button is pressed at the main visualization. With another button it is possible to switch between all lamps so I'm able to select which lamp visu I want to display. A primitive pseudo code could look like this:

    If RequirementGreenLampL1 Then
        // Switch to GreenLamp L1 visualization
    Elsif RequirementGreenLampL2 Then
        // Switch to GreenLamp L2 visualization
    Elsif RequirementRedLampL3 Then
        // Switch to RedLamp L3 visualization
    End_If
    

    I can't finde any VisuElems documentation. I'm looking for functions/methods to pass the data to the corresponding visualization and to show this visualization in the main visualization. A frame would be good.

    Note: This should be an easy to understand example. The real application will have more custom types (machines with settings visu).

    Does someone have any clue how to do it?

     
  • TimvH

    TimvH - 2023-06-04

    In the main visualization place 1 frame.
    In this frame add 3 visualizations (2x green lamp, 1x red lamp).
    Link the FB instances as reference to the visualizations in the frame.
    Then there are multiple options to switch between which visualization to show in the frame.
    A simple one could be just to use the "Switch frame variable" and in your IF statement set the correct value for this variable.

     

Log in to post a comment.