VisuUtils - FBAcceptsCurrentClient - CurrentClient - WebVisu Client Independent Visualization Change

hedgetech
2023-06-21
2023-06-23
  • hedgetech - 2023-06-21

    Hello!

    Is there a way to independently (asynchronously) change the shown visualization between different WebVisu clients? Currently I am using VU.FbIterateClients to iterate through clients (follwing example from another thread) and also created a function block which implements VU.IVisualizationClientFilter, VU.IVisualizationClientIteration..Within this function block I am calling the fbChangeVisu: VU.FbChangeVisu; within the HandleClient method.

        fbChangeVisu(
            xExecute:= xChangeVisuCondition, 
            xDone=> xChageVisuDone, 
            xBusy=> xChanveVisuBusy, 
            xError=> xChangeVisuError, 
            itfClientFilter:= VU.Globals.OnlyWebVisu, 
            eError=> eError, 
            sVisuName:= 'New_Visu');
    

    With this implementation however all web visualizations (clients), will change at once to the 'New_Visu' whenever the xChangeVisuCondition is TRUE.
    (Currently I have un-checked, the checkbox Use CurrentVisu Variable under Visualization Manager/Settings, so I can have asynchronous display from different web-browsers accessing the controllers IP address)

    A more detail code snippet of what I am trying to do below:

    PROGRAM VisuHandling //<-- called from the VISU_TASK
    VAR
        xExecute, xDone, xError, xBusy      : BOOL;
        fbVisuIterate                       : VU.FbIterateClients;
        fbClientFilter                      : ClientFilter;
        fbinstItCallback                    : VisuClientIteration;
    END_VAR
    
    fbVisuIterate( itfClientFilter := fbClientFilter, itfIterationCallback := fbinstItCallback, eError => eError, xExecute := xExecute, xBusy => xBusy, xDone => xDone, xError => xError);
    

    Then in the method of the
    FUNCTION_BLOCK VisuClientIteration IMPLEMENTS VU.IVisualizationClientFilter, VU.IVisualizationClientIteration

    METHOD HandleClient
    VAR_INPUT
        (* The object representing the according client. Will not be 0.*)
        itfClient   : VU.IVisualizationClient;
    END_VAR
    
    fbChangeVisu(
        xExecute:= xChangeVisuCondition, 
        xDone=> xChageVisuDone, 
        xBusy=> xChanveVisuBusy, 
        xError=> xChangeVisuError, 
        itfClientFilter:= VU.Globals.OnlyWebVisu, 
        eError=> eError, 
        sVisuName:= 'New_Visu');
    

    Maybe the more adequate question is how do we properly use the VU.IVisualizationClientFilter to filter and make action only on the individual WebVisu client (not on all of the WebVisu's).

    Any help, insights on the above is greatly appreciated!

     
  • TimvH

    TimvH - 2023-06-23

    I'm not sure you want to go in this direction, because the example below contains code which is marked as obsolete, but the library mentions that if no other option is possible, then it could be an escape... so be warned 😬

    Add the following code to your "HandleClient" method

        xChangePage : BOOL;
        itfVisuClientRawData : VU.IVisualizationClientRaw;
    
    xQueryOK := __QUERYINTERFACE(itfClient, itfVisuClientRawData);
    IF xQueryOK AND xChangePage THEN
        VisuElems.g_VisuManager.SetMainVisu(pClientData := itfVisuClientRawData.ClientDataPointer, stVisu := 'visu2');
        xChangePage := FALSE;
    END_IF
    

    'visu2' in this case is just the name of a Visualization, of course you have to replace this with the name of the Visualization you want to switch to...

     
    πŸ‘
    1

    Last edit: TimvH 2023-06-23
    • hedgetech - 2023-06-23

      Sorry new to CODESYS forge here.... I posted a new thread below instead of responding to you directly πŸ˜… Thank you so much for sharing!

       
  • hedgetech - 2023-06-23

    Hello TimvH,

    Thank you so much! that worked flawlessly.
    Except, I see what you mentioned... It does contain code that is obsolete and I get the warning message:

    C0357: POU 'SetMainVisu' has been marked as obsolete: Please use the methods of VisuUtils instead.

    I am not sure what/which is the method that they are referring to, to use inside of the VisuUtils library to accomplish the same action.

    If it is in fact the fbChangeVisu inside of VisuUtils, I still wonder if there is a way to filter the specific WebVisu client individually....

    But what you shared above helped me out tremendously! Thank you!

     

Log in to post a comment.