Last active
April 4, 2022 12:59
-
-
Save Raggles/ff2c4e218f896044fdf9410f4c14c213 to your computer and use it in GitHub Desktop.
Method for acking all alarms via push button in OMI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'In an action script for a push button, add the following code | |
dim psi as System.Diagnostics.ProcessStartInfo; | |
psi = new System.Diagnostics.ProcessStartInfo(); | |
'Edit this path as required | |
psi.FileName = "C:\Scripts\AckAllAlarms.exe"; | |
psi.RedirectStandardInput = true; | |
psi.RedirectStandardOutput = false; | |
psi.UseShellExecute = false; | |
psi.CreateNoWindow = true; | |
System.Diagnostics.Process.Start(psi); | |
'End action script | |
//Compile the following C# code into a new console application | |
//(using visual studio or msbuild) | |
//and save it to the path used in above action script | |
//You will also need to import wnwrapconsumer.dll as a reference (register first if copying from another system), and set embed interop types to false. | |
//NOTE: be sure to edit the alarm query to suit your needs | |
using System; | |
using System.Threading; | |
using System.Xml; | |
namespace AlarmWrapper | |
{ | |
public static class program | |
{ | |
public static void Main() | |
{ | |
AlarmWrapper w = new AlarmWrapper(); | |
w.AckAllAlarms(); | |
} | |
} | |
public class AlarmWrapper | |
{ | |
public void AckAllAlarms() | |
{ | |
try | |
{ | |
var MyConsumer = new WNWRAPCONSUMERLib.wwAlarmConsumerClass(); | |
int Result; | |
XmlDocument xDoc; | |
object currentXMLAlarms; | |
string almStr; | |
XmlNodeList node; | |
xDoc = new System.Xml.XmlDocument(); | |
Result = MyConsumer.InitializeConsumer("ConsumerApplication3"); | |
LogMessage(Result.ToString()); | |
Result = MyConsumer.RegisterConsumer(0, "OnDemandAllAcker", "ConsumerApplication3", "1.2.0"); | |
LogMessage(Result.ToString()); | |
LogMessage("---Instantiate, Initalize, Register AlarmConsumer, SetXMLAlarmQuery---"); | |
MyConsumer.SetXmlAlarmQuery("<QUERIES FROM_PRIORITY=\"1\" TO_PRIORITY=\"999\" ALARM_STATE=\"UNACK_ALM\" DISPLAY_MODE=\"Summary\"><QUERY><NODE>localhost</NODE><PROVIDER>Galaxy</PROVIDER><GROUP>Network</GROUP></QUERY></QUERIES>"); | |
//note that for the above line, you need to have write permissions on HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Wonderware\SuiteVoyager\wwsvalmsvc otherwise you will get a popup message. | |
//There needs to be a small delay between setting the query and getting the alarms, I think so that the query string can be written to the registry (or something) | |
Thread.Sleep(200); | |
MyConsumer.GetXmlCurrentAlarms(100, out currentXMLAlarms); | |
almStr = currentXMLAlarms.ToString(); | |
LogMessage(almStr); | |
xDoc.LoadXml(almStr); | |
node = xDoc.SelectNodes("/ALARM_RECORDS/ALARM"); | |
if (node != null) | |
{ | |
//node.InnerText property Get the concatenated values of the node and all its child nodes | |
foreach (XmlNode leafnode in node) | |
{ | |
try | |
{ | |
if (leafnode["STATE"].InnerText == "UNACK_ALM" && leafnode["TYPE"].InnerText != "Comm") | |
{ | |
Result = MyConsumer.AlarmAckByName(leafnode["TAGNAME"].InnerText, @"\\localhost\Galaxy", leafnode["GROUP"].InnerText, "", System.Environment.UserName, System.Environment.MachineName, System.Environment.UserDomainName, System.Environment.UserName); | |
LogMessage("AckOnDemand " + leafnode["TAGNAME"].InnerText + ":" + leafnode["VALUE"].InnerText + ":" + Result); | |
} | |
} | |
catch (Exception ex) | |
{ | |
LogMessage(ex.ToString()); | |
} | |
} | |
} | |
MyConsumer.DeregisterConsumer(); | |
} | |
catch (Exception ex) | |
{ | |
LogMessage(ex.ToString()); | |
} | |
} | |
public void LogMessage(string message) | |
{ | |
Console.WriteLine(string.Format("{0}:{1}", DateTime.Now.ToString(), message)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment