Page tree
  • Create a "Standard project" and select CODESYS Control Win V3 as the device.
  • Define the target system by means of the Network scan.



  • Insert a visualization in the device tree.
    Then the Visualization Manager is inserted automatically with the visu types TargetVisu and WebVisu.
    In addition, a VISU_TASK is also created automatically.



  • Create a user management in the Visualization Manager with the default groups and users.



    Then adapt the passwords of the users:



  • Create a new FB named FB_UserMgmtEventHandler and implement the VisuElemns.IUserMgmtEventHandler interface.



    The following methods are created automatically with the FB:
    HandleLogin
    HandleLoginFailed
    HandleLogout
    HandlePasswordChange




  • Adapt the FB_UserMgmtEventHandler function block as follows:


    Declaration

    FUNCTION_BLOCK FB_UserMgmtEventHandler IMPLEMENTS VisuElems.IUserMgmtEventHandler
    VAR_INPUT
    END_VAR
    VAR_OUTPUT
    END_VAR
    VAR
    	udiHandleLogin	:    UDINT;
    	udiHandleLogout	:    UDINT;
    END_VAR


  • Adapt the HandleLogin method as follows:


    Declaration

    (* This method will be called when a login to the visu user management is performed 
     :return: 
     TRUE  - When the handler has handled this event and it should not be handled by someone else
     FALSE - When the event is not handled by this handler*)
    METHOD HandleLogin : BOOL
    VAR_INPUT
        (* A pointer to the client structure were the event occurred.
     The name of the user, that logged in, is stored in pClient^.GlobalData.CurrentUserName*)
        pClient    : POINTER TO VisuElems.VisuStructClientData;
    END_VAR

    Implementation

    udiHandleLogin := udiHandleLogin + 1;


  • Proceed in the same way with the HandleLogout method.

  • Make sure that the VisuElems prefix is also used in the HandleLoginFailed and HandlePasswordChange methods; and that the line "{warning 'add method implementation '}" is deleted.
  • Adapt the POU PLC_PRG as follows:


    Declaration

    VAR
        fbUserMgmtEventHandler    :    FB_UserMgmtEventHandler;
    END_VAR


  • Assign the EventHandler to the visualization as follows.

    Versions < V3.5.SP10

    In old versions, the following approach is not possible, because the assignment of a program from the visualization manager was not possible.
    For these versions, an initialization must take place in the program code.


    Create a new POU of type "Program". Name it VisuInit, for example, and adapt the program code as follows:


    Declaration

    PROGRAM VisuInit
    VAR
    END_VAR

    Implementation

    VisuElems.Visu_Globals.g_VisuEventManager.SetUserMgmtEventHandler(PLC_PRG.fbUserMgmtEventHandler);


    Assign the VisuInit program to your project as the start procedure within the Visualization Manager:



  • Open the Visualization, add a box, and assign the following properties to it:



  • Repeat the steps as for a button for logging out.

  • Load the project to the controller and start it.
    The variables are increased at each successful "Login" and "Logout".