Skip to main content

WEBfactory 2010

Detecting the amount of currently logged users

Abstract

Check out this article and learn how to detect the amount of currently logged in users.

The described method will detect the number of currently logged users. If any user is logged, a boolean value will be triggered inside another OPC server to indicate the logon state in a different PLC.

Create v-channels in the OPC servers

For this method to work, three v-channels will need to be created:

  • LoginCheck

  • UserCurrentlyLoggedIn

  • CodeSysLogInFlag

LoginCheck
  1. Create the LoginCheck signal under the WEBfactory 2010 Simulation server. As the signal should be a VChannel, activate the VChannel for the LoginCheck signal.

  2. The following code must be placed in the LoginCheck VChannel:

    Sub GetResult() 
    Result = 0 ' Default value
    
      If (Second(Now()) Mod 3 ) = 0 then 'do it every 3 seconds
    
    NumberOfUsers = ReadSignal("WFSInternal_LoggedOnUserCount") 'get number of currently logged on users
    
     	UserAlreadyLoggedInFlag = ReadSignal("UserCurrentlyLoggedIn") 'get flag wheatherany user is logged on ur not
    
     	If NumberOfUsers > 0 AND UserAlreadyLoggedInFlag = 0 Then
      		call WriteSignal("CodeSysLogInFlag", 1, "", "") 'tells the other opc server that webfacrtory login succeeded
      
      		call WriteSignal("UserCurrentlyLoggedIn", 1, "", "") 'set internal flag that WEBfactory 2010  login succeeded
      
      		Result = 1 'internal flag that login has been send to other opc server
     	End If
     	If (NumberOfUsers = 0 OR NumberOfUsers = "") AND UserAlreadyLoggedInFlag = 1 Then 'when user logs off
      	call WriteSignal("CodeSysLogInFlag", 0, "", "") 'beschreibe CoDeSys login Flag mit 0
      
      		call WriteSignal("UserCurrentlyLoggedIn", 0, "", "") 
      
      		Result = 0 'LogOut an CoDeSys gesendet
     	End If
    End If
    
    End Sub
  3. Select Local Second for the trigger of the VChannel.

    WF_SE_625.jpg

    LoginCheck VChannel

UserCurrentlyLoggedIn

The UserCurrentlyLoggedIn sets the internal flag when WEBfactory 2010 login succeeded. It is another VChannel that needs to be created under the same OPC Simulation server as LoginCheck.

Create the signal, activate the VChannel and set the result to 0.

WF_SE_626.jpg

UserCurrentlyLoggedIn VChannel

CodeSysLogInFlag

The CodeSysLogInFlag tells the other opc server that webfacrtory login succeeded. It can be normally any item of an OPC server connected to a PLC. For this tutorial purpose, the item will be named CodeSysLogInFlag and will be a VChannel.

IMPORTANT: The CodeSysLogInFlag is an example VChannel. In a real application, this VChannel will be replaced by an OPC item.

Create the CodeSysLogInFlag signal and activate VChannel like in the example below:

Example_below.jpg

CodeSysLogInFlag VChannel

Testing the detection of user login
  1. To test the above method, save the WEBfactory 2010Studio configuration, restart the WEBfactory 2010 Server and open WEBfactory 2010Test Center.

  2. Import the three signals into Test Center.

  3. Open a WEBfactory 2010 visualization application that has an User Login control, or create a simple application containing the User Login control.

  4. Test the application and the detection method by logging in with an existing user, at runtime.

  5. Be default, the Test Center will display the three signals with the value 0. Log in the application, and observe the value changing for UserCurrentlyLoggedIn and CodeSysLogInFlag.

WF_SE_629.jpg

Detecting logged in users

The UserCurrentlyLoggedIn and CodeSysLogInFlag should display 1, if one user is logged in.