Opening a Dialog on a specific Client from ST

manuknecht
2023-08-11
2024-11-05
  • manuknecht - 2023-08-11

    I would like the following to happen: Upon pressing a button, one of several dialogs shall be opened, depending on the state of other variables. I managed to realize this by either using the "Execute ST-Code" Option in the Input Configuration or by setting a BOOL Variable on button tap and executing the same code elsewhere. The code is something like this:

    CASE eCmdType OF
        E_COMMAND_TYPE.E_MOTION:
            fbOpenMotionDialog(itfClientFilter:=VU.Globals.CurrentClient,xExecute:=TRUE,sDialogName:='VIS_InsertMotion_DLG');
    
        E_COMMAND_TYPE.E_WAIT:
            fbOpenWaitTimeDialog(itfClientFilter:=VU.Globals.CurrentClient,xExecute:=TRUE,sDialogName:='VIS_InsertWaitTime_DLG');
    END_CASE
    

    When using the client filter "AllClients", and using several visualizations (i.e. several webbrowser instances), the dialog stays open on other visus, which is undesired. Using the option "CurrentClient" is what I am looking for, however it only works when being called in the "Execute ST-Code" section of the button.

    How can I record on which client a button was pressed and open a Dialog only in the regarding client? I tried creating a variable of type VU.IVisualizationClientFilter and setting it to VU.Globals.CurrentClient in the Input Configuration of the button, but that does not seem to work.

    Would appreciate any ideas!

    Cheers
    Manuel

     

    Last edit: manuknecht 2023-08-11
  • manuknecht - 2023-09-27

    I managed to find a solution that seems to work reliably. As the VU.Globals.CurrentClient-filter accesses the CURRENTCLIENTID or at least a similar, internal variable it can only be used if called from a certain client (e.g. from a button in a visualization). My solution works by implementing a new client filter that compares the client ID of all clients to the ID of the last client that was used. The variable containing the data of the last client is defined as:

    G_LastClient    : VU.IVisualizationClient;  // Copy of last client that detected click
    

    This last client is then updated every time a button is pressed using the Execute ST-Code input configuration of the button:

    G_LastClient := VU.PublicVariables.Clients.Current;
    

    Next, I created a function block that implements the client filter interface as so:

    FUNCTION_BLOCK FB_LastClientFilter IMPLEMENTS VU.IVisualizationClientFilter
    VAR_INPUT
    END_VAR
    VAR_OUTPUT
    END_VAR
    VAR
    END_VAR
    

    Then i added a method to the FB called IsAccepted which is used to filter out the client. When creating the method, it should automatically be filled with the according variable declaration, as it is defined in the interface:

    (* For every client can be desided, if it is accepted.
    
     ``TRUE``: Client is accepted*)
    METHOD IsAccepted : BOOL
    VAR_INPUT
        (* The client, to check*)
        itfClient   : VU.IVisualizationClient;
    END_VAR
    

    Now the client can be compared to the last used client as such:

    // check if clientID corresponds to clientID of last recorderd client
    IF itfCLient.ClientId = G_LastClient.ClientId THEN
        IsAccepted := TRUE;
        ELSE
        IsAccepted := FALSE;
    END_IF
    

    To make use of this custom client filter, initialize a variable with the client filter:

    LastClient      : FB_LastClientFilter;  // Client filter to find last used client
    

    Then use this client filter when opening or closing a dialog from ST:

    fbOpenMyDialog(itfClientFilter:=LastClient,xExecute:=TRUE,sDialogName:='VIS_MyDialog_DLG');
    
     
  • jinlee - 2024-02-08

    Hi,
    for this, G_LastClient := VU.PublicVariables.Clients.Current;

    It fails to do it.

     
  • warrumungi - 2024-11-05

    Hi

    Thanks, Manuel, for providing this solution and insight. I too had exactly the same problem as you did. While I did implement a custom filter, I'd also like to point out what jinlee mentioned above...I see no reference to VU.PublicVariables.Clients.Current anywhere?? In my case I only needed to show a dialog on a "master" client, not all the clients, so I filtered by IP address to do this.

     

Log in to post a comment.