• 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 with the visu types TargetVisuand WebVisu.

    In addition, a Visu_Task is also created automatically.





As of SP17:

  • Open the Library Manager and add the following libraries:
    VisuUtils




  • Create a new FB named FB_Iteration and implement the interface VU.IVisualizationClientIteration.



    The following methods are created automatically with the FB:
    EndIteration
    HandleClient
    StartIteration



  • Adapt the FB_Iteration function block as follows:



    Declaration

    FUNCTION_BLOCK FB_Iteration IMPLEMENTS VU.IVisualizationClientIteration
    VAR CONSTANT
    	c_MaxClients	: __XINT := 5;
    END_VAR
    VAR
    	_iIndex			: __XINT;
    	asIpAddresses	: ARRAY [0..c_MaxClients-1] OF STRING;
    END_VAR






  • Adapt the EndIteration method as follows:



    Declaration

    METHOD EndIteration
    VAR
    	_iCounter : __XINT;
    END_VAR




    Implementation

    FOR _iCounter := (c_MaxClients - 1) TO _iIndex BY -1 DO
    	asIpAddresses[_iCounter] := '';
    END_FOR






  • Adapt the HandleClient method as follows:



    Implementation

    IF _iIndex <= (c_MaxClients - 1) THEN
    	asIpAddresses[_iIndex] := itfClient.GetIPv4Address();
    	_iIndex := _iIndex + 1;
    END_IF






  • Adapt the StartIteration method as follows:



    Implementation

    _iIndex := 0;





  • Adapt the POU PLC_PRG as follows:



    Declaration

    VAR
        fbIteration         : FB_Iteration;
        fbIterateClients    : VU.FbIterateClients;	
    	xIterate			: BOOL;
    END_VAR




    Implementation

    fbIterateClients(xExecute := xIterate, itfClientFilter := VU.Globals.OnlyWebVisu, itfIterationCallback := fbIteration);
    
    IF fbIterateClients.xDone  THEN
    	xIterate := FALSE;
    END_IF






  • Start the project and insert the variable PLC_PRG.fbIteration in the watch list.
  • Open a browser and type in the following address: http://localhost:8080/webvisu.htm
  • Set the PLC_PRG.xIterate variable to TRUE.





Up to SP16:

  • Create a new POU named ClientInfo and call it from Visu_Task.

    The call of the ClientInfo POU must originate from the Visu_Task because only then is the required client handle passed.




  • Adapt the ClientInfo POU as follows:



    Declaration

    VAR
        pClient       :    POINTER TO VisuElems.VisuElemBase.VisuStructClientData;
        helper        :    VisuElems.VisuFbClientTagDataHelper;
        s1            :    STRING;
    END_VAR




    Implementierung

    VisuElems.g_ClientManager.BeginIteration();
    
    WHILE (pClient := VisuElems.VisuElemBase.g_ClientManager.GetNextClient()) <> 0 DO
        IF pClient^.GlobalData.ClientType = VisuElems.VisuElemBase.Visu_ClientType.WebVisualization THEN
            helper(pClientData := pClient);
            s1 := helper.stIPv4;
        END_IF
    END_WHILE





  • Start the project and set a breakpoint in line 6 of the ClientInfo POU.



  • Open a browser and type in the following address: http://localhost:8080/webvisu.htm
  • After the client has connected, execution is halted at the breakpoint and the IP address can be read.



    The information is available only for web clients. A TargetVisu connected to the controller does not contain this information.