VisuElems.CurrentUserGroupId is not stable

Riccardo
2023-11-10
2023-11-16
  • Riccardo - 2023-11-10

    GoodMorning everyone.

    I have a system that, in case of alarm, have to block.
    When the operator logs in must have to acknoledge the alarm and should operate in the system freely.
    To perform this I detect the logged User by (VisuElems.CurrentUserGroupID <> 0) with a similar code to the the following:

    PROGRAM AlarmMngt
    VAR
        alarm : BOOL:= FALSE;
        Ack : BOOL:= TRUE;
        PushBottonOpening : BOOL:= FALSE;
        Valve : BOOL := FALSE;
        Flag: BOOL := FALSE;
    END_VAR
    
    IF alarm AND  Ack  AND (NOT Flag) THEN
        valve := FALSE;
        PushBottonOpening := FALSE;
        Ack := FALSE
        flag := TRUE;
    ELSIF (NOT alarm) AND Ack THEN
        flag := FALSE;
    END_IF
    
    (* if the system is in alarm but there is a logged operator that acknowledge the alarm the system allows the valve opening.*)
    
    IF (VisuElems.CurrentUserGroupID <> 0) AND Ack  AND Alarm AND PushBottonOpening THEN
        Valve := TRUE;
    ELSIF (VisuElems.CurrentUserGroupID = 0)   AND Alarm  THEN
        valve := FALSE;
    END_IF
    

    The problem I have is in the last 5 lines of the code:
    Even if there is a logged in user, the GroupID variable is subjected to a refresh that cyclically set for an instant it to 0 and this close the valve making difficult to the user to work
    Now I solved it creating a time hysteresys cycle but it is not a good solution.
    Someone is able to explane me why the GroupID variable is sobjected to this refresh and how to stabilize to avoiding it?

    Thank you in advance,

    Riccardo

     
  • TimvH

    TimvH - 2023-11-14

    I'm not sure what you are trying to do, but getting the CurrentUserGroupID like this will not work, because there could be multiple Visualization Clients and each can have a different user that is logged in. Also when you go online with CODESYS and open an Visualization, this is counted as a client. Probably this is the reason you see it changing.

    What you can to is "iterate" over all clients and then see which user is logged in on which visualization Client. For this you need to add the Visu Utils library to the project and call the FbIterateClients.
    See https://content.helpme-codesys.com/en/libs/Visu%20Utils/4.4.0.0/VisuUtils/VisuActionUtilities/Function-Blocks/FbIterateClients.html

    fbClientIteration(
        xExecute                := x_Execute, 
        itfClientFilter         := VU.Globals.AllClients, 
        itfIterationCallback    := fbIterator, 
        xDone                   => x_Done, 
        xBusy                   => x_Busy, 
        xError                  => x_Error,
        eError                  => e_Error);
    

    The fbIterator, in the example above, should be an instance of an FB which you have created yourself and this must implement VU.IVisualizationClientIteration. For example:

    FUNCTION_BLOCK FB_ITERATOR IMPLEMENTS VU.IVisualizationClientIteration

    Then automatically the corresponding methods will be called.

    In the HandleClient Method, you will get an interface to the client(s) and then you can get the current user through this interface:

    itfClient.UserGroupId

    You can also get the UserName:

    itfClient.UserName

     
  • Riccardo - 2023-11-16

    Goodmorning TimvH,

    Thanks for the reply.
    I don't know if your solution solve my trouble yet, I am going to see the link you sent me.

    In the mean time I try to explane better what I need to do.
    I have a turbine system that get in alarm under some condition (E.g low speed of turbine) and block the itself. When the system is stoped there is no speed turbine and the system cannot start.
    To give to the operetor the possibility to bypass the alarms, there is an acknoledgement alarm pushbutton.
    This bypass must not work for everyone but only for those client that perform the login by (User Management).
    Furthermore, if the user perform the (manual or automatic) logout in alarm conditions, the acknowlegment must be annulled and block the system again.
    To do this, I need to know if an operator is logged in the page and is working to fix the problem; otherwise the syste must autoturn off again.

    Now I go to study your solution, if I have explaned better and you have another idea tell me please.

     

Log in to post a comment.