The AlarmQuery object contains the following methods:
Note: Some of the examples in this topic use the WScript.Sleep statement, which is not recommended for use when scripting in CygNet Studio or in the HSS. Use TheView EventTimer instead.
The CancelAlarmFiltering method cancels the filtering of alarms.
CancelAlarmFiltering()
Example
The following example cleans up the query after it is finished, by canceling the filtering destroying the filter.
|
Sub
' alarm query is finished AlarmQuery.CancelAlarmFiltering() AlarmQuery.DestroyAlarmFilter(100)
End Sub |
The ClearQueryResults method clears the results of a previous query and initializes the processing flags. The query (filter) itself is not cleared.
ClearQueryResults()
Clearing the results of a previous query is good programming practice if multiple queries are to be performed.
Example
The following example addresses clearing the query results before retrieving data from the query.
|
Sub
' query is all set up While bIsFiltering
WScript.Sleep(1000)
' call before retrieving data AlarmQuery.ClearQueryResults()
' retrieve data, etc. Wend
End Sub |
The CreateAlarmFilter method creates a new alarm filter thread.
CreateAlarmFilter(StartTime As Date, EndTime As Date, UpdateInterval As Integer) As Boolean
| Parameter | Required | Description |
|---|---|---|
|
StartTime |
Yes |
The earliest date/time of alarms to be filtered. Note that this value can either be a string in the machine-chosen date/time format (i.e. "MM/DD/YY hh:mm:ss" for a machine using the American date/time format), or it can be a Date returned from the CDate function. |
|
EndTime |
Yes |
The latest date/time of alarms to be filtered. Note that this value can either be a string in the machine-chosen date/time format (i.e. "MM/DD/YY hh:mm:ss" for a machine using the American date/time format), or it can be a Date returned from the CDate function. |
|
UpdateInterval |
Yes |
The periodic run interval in seconds. If this value is zero, the query will only run once. |
The StartTime and EndTime parameters will be ignored if the "ReportTime" property is used in the filter passed into SetAlarmFilterAsXml and the FilterContainsDates parameter of that method is set to "true" (see SetAlarmFilterAsXml).
The StartTime and EndTime parameters do not get included into the filter until SetAlarmFilterAsXml is called. If no additional filtering (besides start/end times and site services) is desired, call SetAlarmFilterAsXml with a blank filter string and FilterContainsDates parameter set to false after calling CreateAlarmFilter and SetAlarmSiteServices.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
|
Sub
'-----------------SETUP------------------
Dim date1, date2 date1 = Date - 10 date2 = Date Dim startDate, endDate startDate = CDate(date1) endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago Dim bCreatedOk bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice) AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for 'SetAlarmFilterAsXml for an example of an XML filter) Dim bSetFilter bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly Dim bIsFiltering, bIsRunning bIsFiltering = AlarmQuery.IsAlarmFilterFiltering() bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved pvTagList = "" bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved nSize = 0 bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = "" bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml) MsgBox pvAlarmInfoXml
Next
'clear the query and the cache AlarmQuery.ClearQueryResults
End If
'alarm query is finished AlarmQuery.CancelAlarmFiltering() AlarmQuery.DestroyAlarmFilter(100)
End Sub |
The DestroyAlarmFilter method terminates execution of the filter thread, and waits for the specified number of seconds.
DestroyAlarmFilter(TimeToWaitInSeconds As Integer) As Boolean
| Parameter | Required | Description |
|---|---|---|
|
TimeToWaitInSeconds |
Yes |
The number of seconds to wait for the alarm query to terminate. This value must be within the range [1 - 100]. |
This method will hang for the specified number of seconds while the filter thread terminates. If the filter thread has not terminated by the time the interval has expired, this method will return false and the filter thread will continue to attempt to terminate in the background. Call this method as part of the cleanup routine after querying is finished.
Example
The following example cleans up the query after it is finished, by canceling the filtering and destroying the filter.
|
Sub
' alarm query is finished AlarmQuery.CancelAlarmFiltering() AlarmQuery.DestroyAlarmFilter(100)
End Sub |
The GetAlarmFilterAsXml method returns the alarm filter as an XML string.
GetAlarmFilterAsXml(XmlFilter As Variant) As Boolean
| Parameter | Required | Description |
|---|---|---|
|
XmlFilter |
Yes |
The XML string returned from this method. |
Example
The following example sets the alarm filter, then retrieves it from the query and displays it.
|
Sub
' set the alarm filter from an existing XML (see the documentation for ' SetAlarmFilterAsXml for an example of an XML filter) Dim bSetFilter bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlAlarmFilter)
Dim xmlAlarmFilter
If (bSetFilter) Then bGetFilter = AlarmQuery.GetAlarmFilterAsXml(xmlAlarmFilter)
If (bGetFilter) Then MsgBox xmlAlarmFilter End If End If
End Sub |
The GetAlarmInfoAsXml method returns alarm information for the given tag.
GetAlarmInfoAsXml(Tag As String, AlarmInfoXml As Variant) As Boolean
| Parameter | Required | Description |
|---|---|---|
|
Tag |
Yes |
A fully qualified point tag. |
|
AlarmInfoXml |
Yes |
The alarm information for the tag returned as an XML string. |
After querying is complete, this method is used in conjunction with GetFilteredAlarmList to display the results of the query.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
|
Sub
'-----------------SETUP------------------
Dim date1, date2 date1 = Date - 10 date2 = Date Dim startDate, endDate startDate = CDate(date1) endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago Dim bCreatedOk bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice) AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for 'SetAlarmFilterAsXml for an example of an XML filter) Dim bSetFilter bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly Dim bIsFiltering, bIsRunning bIsFiltering = AlarmQuery.IsAlarmFilterFiltering() bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved pvTagList = "" bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved nSize = 0 bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = "" bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml) MsgBox pvAlarmInfoXml
Next
'clear the query and the cache AlarmQuery.ClearQueryResults
End If
'alarm query is finished AlarmQuery.CancelAlarmFiltering() AlarmQuery.DestroyAlarmFilter(100)
End Sub |
The GetFilteredAlarmList method returns the list of filtered alarms as fully qualified point tags.
GetFilteredAlarmList(SiteSvcKeyList As Array) As Boolean
| Parameter | Required | Description |
|---|---|---|
|
SiteSvcKeyList |
Yes |
A list of fully qualified point tags representing the filtered alarms. |
After querying is complete, this method is used in conjunction with GetAlarmInfoAsXml to display the results of the query.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
|
Sub
'-----------------SETUP------------------
Dim date1, date2 date1 = Date - 10 date2 = Date Dim startDate, endDate startDate = CDate(date1) endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago Dim bCreatedOk bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice) AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for 'SetAlarmFilterAsXml for an example of an XML filter) Dim bSetFilter bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly Dim bIsFiltering, bIsRunning bIsFiltering = AlarmQuery.IsAlarmFilterFiltering() bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved pvTagList = "" bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved nSize = 0 bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = "" bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml) MsgBox pvAlarmInfoXml
Next
'clear the query and the cache AlarmQuery.ClearQueryResults
End If
'alarm query is finished AlarmQuery.CancelAlarmFiltering() AlarmQuery.DestroyAlarmFilter(100)
End Sub |
The GetFilteredAlarmListSize method returns the size of the filtered alarm list as an integer
GetFilteredAlarmListSize(Size As Integer) As Boolean
| Parameter | Required | Description |
|---|---|---|
|
Size |
Yes |
The size of the filtered alarm list. |
The filtered alarm list itself can be obtained via GetFilteredAlarmList.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
|
Sub
'-----------------SETUP------------------
Dim date1, date2 date1 = Date - 10 date2 = Date Dim startDate, endDate startDate = CDate(date1) endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago Dim bCreatedOk bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice) AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for 'SetAlarmFilterAsXml for an example of an XML filter) Dim bSetFilter bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly Dim bIsFiltering, bIsRunning bIsFiltering = AlarmQuery.IsAlarmFilterFiltering() bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved pvTagList = "" bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved nSize = 0 bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = "" bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml) MsgBox pvAlarmInfoXml
Next
'clear the query and the cache AlarmQuery.ClearQueryResults
End If
'alarm query is finished AlarmQuery.CancelAlarmFiltering() AlarmQuery.DestroyAlarmFilter(100)
End Sub |
The IsAlarmFilterFiltering method returns true if the entire query process has been set up and is enabled to run.
IsAlarmFilterFiltering() As Boolean
This method will return true after a successful call to StartAlarmFiltering. Once the filtering has begun, this method will only return false if the filtering has been canceled using CancelAlarmFiltering, or if the filter has been destroyed using DestroyAlarmFilter.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
|
Sub
'-----------------SETUP------------------
Dim date1, date2 date1 = Date - 10 date2 = Date Dim startDate, endDate startDate = CDate(date1) endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago Dim bCreatedOk bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice) AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for 'SetAlarmFilterAsXml for an example of an XML filter) Dim bSetFilter bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly Dim bIsFiltering, bIsRunning bIsFiltering = AlarmQuery.IsAlarmFilterFiltering() bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved pvTagList = "" bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved nSize = 0 bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = "" bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml) MsgBox pvAlarmInfoXml
Next
'clear the query and the cache AlarmQuery.ClearQueryResults
End If
'alarm query is finished AlarmQuery.CancelAlarmFiltering() AlarmQuery.DestroyAlarmFilter(100)
End Sub |
The IsAlarmFilterRunning method returns true if the alarm query thread is running.
IsAlarmFilterRunning() As Boolean
The alarm query thread is executed after an alarm filter is created; therefore, after an alarm filter is created, this method will only return false if the filter has been destroyed using DestroyAlarmFilter.
Example
The following example creates an alarm filter, checks that it is running, destroys it, and checks that it is no longer running.
|
Sub
Dim bCreatedOk bCreatedOk = AlarmQuery.CreateAlarmFilter("10/1/2010", "10/4/2010", 5)
Dim bRunning bRunning = AlarmQuery.IsAlarmFilterRunning()
MsgBox bRunning 'should be "True"
AlarmQuery.DestroyAlarmFilter(100)
bRunning = AlarmQuery.IsAlarmFilterRunning()
MsgBox bRunning 'should be "False"
End Sub |
The SetAlarmFilterAsXml method sets the alarm filter from an XML string.
SetAlarmFilterAsXml(XmlFilter As String, FilterContainsDates As Boolean) As Boolean
| Parameter | Required | Description |
|---|---|---|
|
XmlFilter |
Yes |
The XML string representing the alarm filter to be set. |
|
FilterContainsDates |
Yes |
Specify "true" if the XmlFilter parameter contains a rule for the "ReportTime" property. If this parameter is set to "false", the filter will use the dates specified in the parameters of CreateAlarmFilter. |
This method returns false if the XML filter is invalid.
The following is an example of an XML alarm filter.
|
<ExportedRules ruleDataIdentifier='CAS Alarm Rules'> <Rules enabled='true' inverted='false' op='1' name=''> <Rule enabled='true' name='' referenceAttr='0' compareToType='0' externalData='' value='9/1/2010' operator='>=' qualifier='Case Insensitive'> <compareItem property='ReportTime' type='0'/> </Rule> <Rule enabled='true' name='' referenceAttr='0' compareToType='0' externalData='' value='10/1/2010' operator='<=' qualifier='Case Insensitive'> <compareItem property='ReportTime' type='0'/> </Rule> <Rule enabled='true' name='' referenceAttr='0' compareToType='0' externalData='' value='HIGH_ALARM' operator='=' qualifier='Case Insensitive'> <compareItem property='AlarmCond' type='0'/> </Rule> </Rules> </ExportedRules> |
This filter will select all alarms for which (ReportTime >= "9/1/2010" AND ReportTime <= "10/1/2010" AND AlarmCond = "HIGH_ALARM"). Note that the "op='1'" attribute specifies that the rules are ANDed. To OR a set of rules, use "op='0'". For a complete list of CAS XML property names, see CAS XML Properties.
A blank filter may be provided as long as FilterContainsDates parameter is set to false, start and end dates are provided with CreateAlarmFilter, and a site service list is provided with SetAlarmSiteServices.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
|
Sub
'-----------------SETUP------------------
Dim date1, date2 date1 = Date - 10 date2 = Date Dim startDate, endDate startDate = CDate(date1) endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago Dim bCreatedOk bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice) AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for 'SetAlarmFilterAsXml for an example of an XML filter) Dim bSetFilter bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly Dim bIsFiltering, bIsRunning bIsFiltering = AlarmQuery.IsAlarmFilterFiltering() bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved pvTagList = "" bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved nSize = 0 bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = "" bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml) MsgBox pvAlarmInfoXml
Next
'clear the query and the cache AlarmQuery.ClearQueryResults
End If
'alarm query is finished AlarmQuery.CancelAlarmFiltering() AlarmQuery.DestroyAlarmFilter(100)
End Sub |
The SetAlarmSiteServices method defines the list of CAS site services for the alarm filter.
SetAlarmSiteServices(SiteServices As String) As Boolean
| Parameter | Required | Description |
|---|---|---|
|
SiteServices |
Yes |
A semicolon-delimited list of CAS Site.Services (for example, "CYGDEMO.CAS;CYGDEMO.CAS1") |
This method will only return false if a filter has not yet been created.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
|
Sub
'-----------------SETUP------------------
Dim date1, date2 date1 = Date - 10 date2 = Date Dim startDate, endDate startDate = CDate(date1) endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago Dim bCreatedOk bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice) AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for 'SetAlarmFilterAsXml for an example of an XML filter) Dim bSetFilter bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly Dim bIsFiltering, bIsRunning bIsFiltering = AlarmQuery.IsAlarmFilterFiltering() bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved pvTagList = "" bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved nSize = 0 bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = "" bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml) MsgBox pvAlarmInfoXml
Next
'clear the query and the cache AlarmQuery.ClearQueryResults
End If
'alarm query is finished AlarmQuery.CancelAlarmFiltering() AlarmQuery.DestroyAlarmFilter(100)
End Sub |
The SetNotificationPoint method sets the CVS point which will contain a notification of when the queries have completed.
SetNotificationPoint(Tag As String) As Boolean
| Parameter | Required | Description |
|---|---|---|
|
Tag |
Yes |
The CVS tag of the point to be used for notifications (for example, "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"). |
This method will return false if the specified tag is invalid. Note that this method does not actually create a CVS point. A CVS point with the specified tag must exist prior to starting alarm filtering in order for CVS notifications to succeed.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
|
Sub
'-----------------SETUP------------------
Dim date1, date2 date1 = Date - 10 date2 = Date Dim startDate, endDate startDate = CDate(date1) endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago Dim bCreatedOk bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice) AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for 'SetAlarmFilterAsXml for an example of an XML filter) Dim bSetFilter bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly Dim bIsFiltering, bIsRunning bIsFiltering = AlarmQuery.IsAlarmFilterFiltering() bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved pvTagList = "" bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved nSize = 0 bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = "" bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml) MsgBox pvAlarmInfoXml
Next
'clear the query and the cache AlarmQuery.ClearQueryResults
End If
'alarm query is finished AlarmQuery.CancelAlarmFiltering() AlarmQuery.DestroyAlarmFilter(100)
End Sub |
The StartAlarmFiltering method initiates alarm filtering on the background thread.
StartAlarmFiltering() As Boolean
This method returns false if no alarm filter has been created.
It is good practice to clear any previous query results with ClearQueryResults before calling this method.
Example
The following example goes through the entire process of creating a filter, setting the XML filter, setting the notification point, starting the query, retrieving data, displaying the results, and cleaning up the query.
|
Sub
'-----------------SETUP------------------
Dim date1, date2 date1 = Date - 10 date2 = Date Dim startDate, endDate startDate = CDate(date1) endDate = CDate(date2)
'create alarm filter for alarms between now and 10 days ago Dim bCreatedOk bCreatedOk = AlarmQuery.CreateAlarmFilter(startDate, endDate, 5)
'initialize the filter (this step is good practice) AlarmQuery.ClearQueryResults
'set the service-specific filter from an existing XML (see the documentation for 'SetAlarmFilterAsXml for an example of an XML filter) Dim bSetFilter bSetFilter = AlarmQuery.SetAlarmFilterAsXml(g_xmlFilter, false)
AlarmQuery.SetAlarmSiteServices("CYGDEMO.CAS")
'set notification point AlarmQuery.SetNotificationPoint "CYGDEMO.UIS:EVENTIF_NOTIFICATION_PT"
'-----------------EXECUTION------------------
AlarmQuery.StartAlarmFiltering()
'check to see if filter has been set up correctly Dim bIsFiltering, bIsRunning bIsFiltering = AlarmQuery.IsAlarmFilterFiltering() bIsRunning = AlarmQuery.IsAlarmFilterRunning()
WScript.Sleep(1000)
Dim pvTagList, bAlarmsRetrieved pvTagList = "" bAlarmsRetrieved = AlarmQuery.GetFilteredAlarmList(pvTagList)
Dim nSize, bSizeRetrieved nSize = 0 bSizeRetrieved = AlarmQuery.GetFilteredAlarmListSize(nSize)
If nSize > 0 Then
Dim strTag, pvAlarmInfoXml, bAlarmRetrieved, iRec For iRec = 0 To UBound(pvTagList)
strTag = pvTagList(iRec)
pvAlarmInfoXml = "" bAlarmRetrieved = AlarmQuery.GetAlarmInfoAsXml(strTag, pvAlarmInfoXml) MsgBox pvAlarmInfoXml
Next
'clear the query and the cache AlarmQuery.ClearQueryResults
End If
'alarm query is finished AlarmQuery.CancelAlarmFiltering() AlarmQuery.DestroyAlarmFilter(100)
End Sub |