In more than one occasion I have been asked how to check the role of the user connected to a specific hardware (for example, the main HMI screen from a machine).
Knowing that, it would be possible to restrict certain actions (pressing a button or enabling certain machine module) that maybe should be restricted only to a user with enough permissions logged in from a specific screen.
To do that, in the past I used the following workaround.
First, you extract the information from the connected clients thanks to an existing session variable (AS Help). You will have to add the corresponding list binding mentioned in the help (which is not included in the software package attached to this topic).
After that, I filter out the user name depending on the IP of the screen were it should be connected (just in case multiple clients are connected to the mappView visu at the same time).
To make this piece of code work, you will have to define the following variables accordingly to your case.
- MAX_ROLE_NUM : Total number of existing roles.
- MAX_MV_CLIENTS_MINUS_ONE : Total number of clients (minus one) defined in the mappView configuration.
- MAIN_HMI_IP_ADDRESS : IP address of the mappView client where the role of the connected user will be checked.
- UserRoleList : Array containing the names of all the existing roles.
Limitations from this solution:
- The list of roles is not automatically updated in case an additional role is added to the project. In that case, the previously mentioned parameters must be adapted accordingly.
- It is considered that each user can only have a single role. In case there is more than one role assigned to a user, the first one appearing on the list (UserRoleList) will be used.
Be aware that in order to be able to read the information regarding the connected clients we need to give write permission for the variable “ClientInfo” with all the available roles.
From that point, you can check that this is working by performing a login with some user and checking its role by setting the command “CmdCheckRole”.
In case someone is interested I leave the software package here.
mVHmiRole.zip (3.1 KB)
Cheers!