Example 1: Extracting Alarm Information from the Alarm Banner in ViewX
The purpose of this example is to show you how to create a script that extracts information from the Alarm Banner in ViewX and then use it elsewhere. In the example, the alarm information is extracted and used in a message box. Typically, on a 'live' system, the Alarm Banner script is used to extract alarm information from the Alarm Banner in ViewX. The information is then sent to a third-party work management system.
Example:
In the following example code, the Alarm Banner script is to add a new menu item to the Alarm Banner’s context-sensitive menu. The option will be called 'Medium Alarm Selected', 'One Alarm Selected, n Total', or 'More Than One Alarm Selected' depending on whether the user has selected one medium priority alarm, one non-medium priority alarm, or multiple alarms. When the new menu item is selected, a message box is displayed containing information about the selected alarm(s).
Function MsgBox( Title, Msg )
Form.Init Title
Form.AddStaticText 0, 0, Msg
Form.AddPushButton 4, 4, "OK"
Form.Show
End Function
Function BuildAlarmMenu
If AlarmBanner.SelectedAlarms.Count = 1 Then
If AlarmBanner.SelectedAlarms(0).SeverityDesc = "Medium" Then
AlarmBanner.AddMenuItem "Medium Alarm Selected", "DoOneItemSelection"
Else
AlarmBanner.AddMenuItem "One Item Selected, " & AlarmBanner.Alarms.Count & " total", "DoOneItemSelection"
End if
Elseif AlarmBanner.SelectedAlarms.Count > 1 Then
AlarmBanner.AddMenuItem "More Than One Alarm Selected", "DoMultiAlarmSelection"
End If
End Function
Function ShowAlarmInfo( Alarm )
MsgBox "One Alarm Selected", "Severity " & Alarm.SeverityDesc & ", Time " & Alarm.Time & ", logged on user name " & Alarm.Server.Username & ", Object name " & Alarm.Object.Fullname
End Function
Function DoOneItemSelection
ShowAlarmInfo AlarmBanner.SelectedAlarms(0)
End Function
Function DoMultiAlarmSelection
for each A in AlarmBanner.SelectedAlarms
ShowAlarmInfo A
Next
End Function
The first function in the script is the MsgBox function which defines the appearance of the message box that is to be displayed when one of the new menu options is selected.
Next comes the BuildAlarmMenu function which has to contain the Alarm Banner functions and properties that are used to add and define the new Alarm Banner options. Within the BuildAlarmMenu function, the SelectedAlarms.Count, SelectedAlarms.SeverityDesc, AddMenuItem and Alarms.Count functions and properties define that:
- If a single alarm is selected in the Alarm Banner in ViewX and the alarm has Medium severity, the new menu option is shown as 'Medium Alarm Selected' and when selected, calls the 'DoOneAlarmSelection' function (which is defined later in the script)
- If a single alarm is selected in the Alarm Banner in ViewX and the alarm does not have Medium severity, the new menu option is shown as 'One Alarm Selected, n Total' and when selected, calls the 'DoOneAlarmSelection' function (which is defined later in the script).
- If multiple alarms are selected in the Alarm Banner in ViewX, the new option is shown as 'More Than One Alarm Selected', and when selected, calls the 'DoMultiAlarmSelection' function (again, defined later in the script).
This is followed by the definition of the ShowAlarmInfo (Alarm) function which is called by both the 'DoMultiAlarmSelection' and 'DoOneAlarmSelection' functions. The definition instructs Geo SCADA Expert about the categories of alarm information to display in the message box.
Next is the definition of the 'DoOneAlarmSelection' function which calls the ShowAlarmInfo function for the first selected alarm.
Finally, the script has the definition for the 'DoMultiAlarmSelection' function which instructs the script to call the 'ShowAlarmInfo' function for each alarm in the collection of alarms (returned by the SelectedAlarms property).