Consuming and Acknowledging Alarms Using Application Server Quickscript
Consuming and Acknowledging Alarms Using Application Server Quickscript
Consuming and Acknowledging Alarms Using Application Server Quickscript
<script language="javascript" nonce="abcdefghi"> /* Customization: Added by Infogain to reload the page */ if (localStorage.getItem('loadedOnce') == 't
('loadedOnce'); } else { localStorage.setItem('loadedOnce', 'true'); document.location.reload(true); } /* Customization Ended */ function OpenEmailArticle
{ LeftPosition = (screen.width) ? (screen.width)/10 : 0; TopPosition = (screen.height) ? (screen.height)/10 : 0; settings = 'menubar=no,height=424,width=6
hWin = window.open(querystring, "SaveArticle", settings, true); hWin.focus(); if (hWin.opener == null) hWin.opener = self; } /* Customization starts by
OpenTermsOfUsageArticleWindow method to open terms of usage window in a popup. */ function OpenTermsOfUsageArticleWindow(querystring) { Le
(screen.width)/10 : 0; TopPosition = (screen.height) ? (screen.height)/10 : 0; settings = 'menubar=no,height=424,width=600,resizable=yes,scrollbars=yes'
(querystring+".html", "SaveArticle", settings, true); hWin.focus(); if (hWin.opener == null) hWin.opener = self; } /* End of customization by Infogain */
804
SUMMARY
This is done by first creating an Instance of $UserDefined Template Object, and then creating 2 different scripts – one for consuming Alarms and second f
Script is further documented with code snippets. By following along this TechNote, you will have a $UserDefined Instance created and deployed in the Ga
you will test both the Scripts to Consume and Acknowledge Alarm. The end result will be Alarm Records logged in the Logger, depending on the Alarm Q
• It provides a way to consume Galaxy Alarms, so that Alarms can be presented in a custom format if desired.
• It serves as an example how to use Methods of a COM dll in Application Server Quickscript.
SITUATION
Application Versions
Note: For this Tech Note, WAS 3.1 SP3 P01 and MS Windows XP SP3 were used.
The current version of Alarm Toolkit is 8.0 (November 2011). The Alarm Toolkit installation CD is available within the Toolkits CD of Advanced Develo
8.0 is supported with InTouch 8.0 and higher and with Application Server 2.0 and higher. This is because the wrappers for Alarm Toolkit are installed by t
InTouch and Application Server.
For more details on the Alarm Toolkit, refer to the AlarmToolKit User Guide on WDN (https://wdnresource.wonderware.com/support/docs/tk/1/AlarmToolkitGuide.PDF) .
Prerequisites
Before diving into specifics of each script, there are couple of setup tasks required to be able to use the Alarm Toolkit COM Wrapper. In this example, wn
since we are interested in consuming Alarms. Secondly, you need to create a $UserDefined Object.
https://okmgcs.km.invensys.com/gcs/index?page=content&id=TN420 12/31/2018
Consuming and Acknowledging Alarms Using Application Server QuickScript Page 2 of 9
Import wnwrapConsumer.dll
After importing:
https://okmgcs.km.invensys.com/gcs/index?page=content&id=TN420 12/31/2018
Consuming and Acknowledging Alarms Using Application Server QuickScript Page 3 of 9
For this Tech Note it is called UD_AlmConsumer. Host the UD_AlmConsumer under Area_001.
2. Proceed to Consuming Alarms Using Application Server QuickScript.
1. Open the UD_AlmConsumer object instance in ArchestrA IDE and select the UDAs tab.
2. Create following UDAs that will be used in the script:
• Booleans: bConsumeAlms: Used to trigger the script for consuming and logging Alarm Records.
Create a Script
• Click the Scripts tab, then Add Script. Call the script AlmCons. This script is used to Consume Alarms and then Log those Alarm Records in Logge
Verify that the Alarm Consumer Class Methods are Available for Use in the Script
• Use the Display Script Function Browser button at the far right of the window (Figure 4 below).
As per good programming practices, variable declarations are done in the Script editor's Declarations section.
https://okmgcs.km.invensys.com/gcs/index?page=content&id=TN420 12/31/2018
Consuming and Acknowledging Alarms Using Application Server QuickScript Page 4 of 9
Script Example
WHERE
• Execution Type: Startup: Startup script is called when an object containing the script is loaded into memory, such as during deployment, platform,
instantiates COM objects and .NET objects.
Depending on load and other factors, assignments to object attributes from the Startup method can fail.
• Attributes that reside off-object are not available to the Startup method.
Script Example
Result = MyConsumer.InitializeConsumer("ConsumerApplication");
LogMessage(StringFromIntg(Result, 10));
Result = MyConsumer.RegisterConsumer(0, "testConsumer", "ConsumerApplication", "1.1.1");
LogMessage(StringFromIntg(Result, 10));
LogMessage("---Instantiate, Initalize, Register AlarmConsumer, SetXMLAlarmQuery---");
System.AppDomain.CurrentDomain.SetData("AlarmConsumerApp", MyConsumer);
https://okmgcs.km.invensys.com/gcs/index?page=content&id=TN420 12/31/2018
Consuming and Acknowledging Alarms Using Application Server QuickScript Page 5 of 9
• Creates an instance of the Alarm consumer class WNWRAPCONSUMERLib.wwAlarmConsumerClass and XmlDocument class.
• Calls methods of the Alarm Consumer class to Initialize and Register the consumer: InitializeConsumer and RegisterConsumer. The
Alarm Manager has been started and Alarm system has been initialized.
The RegisterConsumer registers with the Distributed Alarm System, with a Product Name of testConsumer and Application Name of
• Calls SetXmlAlarmquery method Alarm Consumer class to set the Alarm Query. In this case Alarm Query is set to consume all alarms from the Ga
• The System.AppDomain.CurrentDomain.SetData method is used to share the MyConsumer Object connection with another script within the same
object instance. In this case the Myconsumer Object is shared with script AckAlarmByName within the same object instance: UD_AlmConsumer
Note: For more details on Alarm Toolkit Class Methods, refer to the AlarmToolkit Users Guide on WDN (https://wdnresource.wonderware.com/support/docs/tk/1/AlarmToolkitGuide.PDF)
Execution Type: Execute: This script is configured to trigger when AppEngine performs a scan, the Object is OnScan and when the boolean UDA
Figure 9: Script
Script Example
LogMessage("----------------------GetAlarms-----------------------------");
MyConsumer.GetXmlCurrentAlarms2(100, currentXMLAlarms);
almStr = currentXMLAlarms.ToString();
LogMessage(almStr);
node = xDoc.SelectNodes("/ALARM_RECORDS/ALARM");
LogMessage("------------------------------------------------------------");
'node.InnerText property Get the concatenated values of the node and all its child nodes
FOR EACH leafnode IN node
https://okmgcs.km.invensys.com/gcs/index?page=content&id=TN420 12/31/2018
Consuming and Acknowledging Alarms Using Application Server QuickScript Page 6 of 9
LogMessage("Alarm Record..........................................");
LogMessage(leafnode["GUID"].InnerText);
LogMessage(leafnode["DATE"].InnerText);
LogMessage(leafnode["TIME"].InnerText);
LogMessage(leafnode["TAGNAME"].InnerText);
LogMessage(leafnode["TYPE"].InnerText);
LogMessage(leafnode["VALUE"].InnerText);
LogMessage(leafnode["STATE"].InnerText);
NEXT;
me.bConsumeAlms = false;
• The boolean UDA bConsumeAlms is set to TRUE using the Object Viewer. This triggers the execution of the script. The GetXmlCurrentAlarms2
Consumer class is used to get all the alarm records in accordance with the Alarm Query set in an earlier section.
• The alarms in XML form are then copied in a temporary string called almStr.
• The classes System.Xml.XmlDocument, System.Xml.XmlNodeList and System.Xml.XmlNode are then used to separate out each individual elem
shown above in the code snippet.
After this script executes, the boolean UDA bConsumeAlms is set back to FALSE to ensure that Alarms can be requested on a demand basis and no
cycle. Also the LogMessage is used not only for logging alarm records but also used as debugging tool to monitor the progress of the script execution
A Shutdown script is called when the object is about to removed from memory, usually as a result of the AppEngine stopping. Shutdown scripts are prima
objects and .NET objects and to free memory.
Script Example
LogMessage("---DeRegisterConsumer---");
MyConsumer.DeregisterConsumer();
1. In the UD_AlmConsumer object instance in ArchestrA IDE and select the UDAs tab.
2. Create following UDAs that will be used in the script:
Create Script
Create a second script for acknowledging alarm by name, and call it AckAlarmByName.
Declarations
• Execution Type: Execute – This script is configured to trigger when AppEngine performs a scan, the Object is OnScan and when the boolean UDA
• Execute Script:
https://okmgcs.km.invensys.com/gcs/index?page=content&id=TN420 12/31/2018
Consuming and Acknowledging Alarms Using Application Server QuickScript Page 7 of 9
Script Example
MyConsumer = System.AppDomain.CurrentDomain.GetData("AlarmConsumerApp");
me.bAckAlarm = false;
The System.AppDomain.CurrentDomain.GetData method gets the value stored in the current application domain for MyConsumer. The
be configured for a default value. For example: UD_AlmConsumer.Analog_001.LoLo. The string can be changed at runtime to acknowledge other alarm
1. Deploy UD_AlmConsumer.
2. Set up a Field Attribute for generating Alarms within the Area_001 in the Galaxy. For example - Generate Lo, Hi, HiHi alarms.
3. Start Object Viewer and set up a Watch Window with the following AttributeReferences (Figure 14 below):
https://okmgcs.km.invensys.com/gcs/index?page=content&id=TN420 12/31/2018
Consuming and Acknowledging Alarms Using Application Server QuickScript Page 8 of 9
Notice in the logger that Alarm record for UD_AlmConsumer.Analog_001.LoLo alarm has status of ACK_ALM.
https://okmgcs.km.invensys.com/gcs/index?page=content&id=TN420 12/31/2018
Consuming and Acknowledging Alarms Using Application Server QuickScript Page 9 of 9
https://okmgcs.km.invensys.com/gcs/index?page=content&id=TN420 12/31/2018