The code I used is in amongst a whole mass of VBA code that I'm not at liberty to share, and I don't have the time at the moment to go through and extract all the relevant bits. But in short:
1. Create a "VBA" display that starts up with the client and is always present. You can either use a display that is positioned off-screen so as to be invisible, or attach it to a display component that is always there, such as a navigation bar
2. Create a folder of tags in the "HMI Tags" section of your application to contain the server status tags. I called mine "ServerInfo". Then within that, I created subfolders for each server (primary, secondary, historian, directory) so that each folder had an identical tag structure
3. On your VBA display, define the tags on display animation start:
Code:
Public Sub Display_AnimationStart()
'Set up ServerStatus tags
If ServerStatusTags Is Nothing Then
Set ServerStatusTags = Application.CreateTagGroup(Me.AreaName, 500)
Set PrimServOK = ServerStatusTags.Add("ServerInfo\Primary\ServerOK")
Set PrimServState = ServerStatusTags.Add("ServerInfo\Primary\State")
Set SecServOK = ServerStatusTags.Add("ServerInfo\Secondary\ServerOK")
Set SecServState = ServerStatusTags.Add("ServerInfo\Secondary\State")
Set DirServOK = ServerStatusTags.Add("ServerInfo\Directory\ServerOK")
Set DirServState = ServerStatusTags.Add("ServerInfo\Directory\State")
Set ActiveServName = ServerStatusTags.Add("ServerInfo\ActiveServerName")
Set ServAlarm = ServerStatusTags.Add("ServerInfo\ServerAlarm")
End If
4. You can then set and reset these tags in whatever way you want, using commands like:
Code:
If [primary server is OK] Then PrimServOK.Value = 1 Else: PrimServOK.Value = 0
5. Generate alarms based on the status of these HMI tags, or link them to your PLC and take other action - whatever you need to do
As to how you determine whether or not the server status is healthy - I used similar code to the code in the "server status" display above. That display has code to do things like "if server status is OK, make the box green and write 'Active' in it" and "if server is offline, make the box red and write 'Communication Error' in it". So you can pick through the VBA from that example from the knowledge base, and hopefully you can get enough detail out of it to do what you need to do.
Good luck!