Deactivate Alarm in runtime

Discussion of application development using iX Developer, including but not limited to getting started, using the functions tab, properties, objects and installation.
Post Reply
bjornidar
Posts: 49
Joined: Thu Nov 17, 2011 2:10 am
Location: Norway
Contact:

Deactivate Alarm in runtime

Post by bjornidar »

Hi,

is it possible by scripting to deactivate an alarm? So that it doesn't apper in the alarmviewer?

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Deactivate Alarm in runtime

Post by mark.monroe »

Have you tried:
Globals.AlarmServer.Default_AlarmItem0.IsEnabled = false;

Where AlarmItem0 is the name of the alarm you want to disable.
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

bjornidar
Posts: 49
Joined: Thu Nov 17, 2011 2:10 am
Location: Norway
Contact:

Re: Deactivate Alarm in runtime

Post by bjornidar »

Hi, and thank you!

I will give it a try and loop through AlarmItems :)

bjornidar
Posts: 49
Joined: Thu Nov 17, 2011 2:10 am
Location: Norway
Contact:

Re: Deactivate Alarm in runtime

Post by bjornidar »

Hi,

could you look throug my code? It doesn't seem to disable the alarm from the alarm-window. Should it be deactivated before the void AlarmServer fires?

I'm just using staic AlarmItem300 for testing.
It should be done inside the second while-loop.

Code:

Code: Select all

   public partial class AlarmServer
   {
      SmsHandling sms = new SmsHandling(9600, 1);
      
      // Alarm oppstår
      void AlarmServer_AlarmActive(System.Object sender, System.EventArgs e)
      {
         // Deaktiverer alarm (til test.)
         Globals.AlarmServer.Default_AlarmItem300.IsEnabled = false;

         
         // Oppretter spørring for databasetilkobling
         SqlConnection setupConnection = new SqlConnection("Data Source=(local)\\SQLEXPRESS;Initial Catalog=trysilfjellet_alarmer;Integrated Security=SSPI;");
         // Oppretter SQL-spørring for telefonnummer
         SqlCommand sqlTlf = new SqlCommand("SELECT * FROM alarminnstillinger ORDER BY id DESC", setupConnection);
         
         // Åpner SQL-forbindelse mot alarminnstillinger
         setupConnection.Open();
         
         SqlDataReader tlfReader = sqlTlf.ExecuteReader();
         // Variabler for telefonnummer
         int dag = 0;
         int natt = 0;
         // DateTime-variabler for arbeidstid og klokkeslett nå
         DateTime arbstart = DateTime.Now;
         DateTime arbslutt = DateTime.Now;
         DateTime naa = DateTime.Now;

         // Henter telefonnummer og arbeidstid og legger de i lokale variabler
         while(tlfReader.Read())
         {
            dag = (int)tlfReader["dagvakt"];
            natt = (int)tlfReader["nattvakt"];
            DateTime.TryParse(tlfReader["tid_arb_start"].ToString(), out arbstart);
            DateTime.TryParse(tlfReader["tid_arb_slutt"].ToString(), out arbslutt);

         }
         // Lukker SQL-forbindelse mot alarminnstillinger
         setupConnection.Close();
         
         // Henter informasjon fra aktiv alarm
         Neo.ApplicationFramework.Interfaces.IAlarmEvent alarmEvent = (Neo.ApplicationFramework.Interfaces.IAlarmEvent)sender;
         string alarmText = alarmEvent.Text;
         string alarmID = alarmEvent.AlarmItemDisplayName;

         // Lager variabel for hvilket telefonnummer alarm skal sendes til
         int nummer;
         // Sjekk for tid på døgnet mot lagret arbeidstid
         if ((naa.TimeOfDay > arbstart.TimeOfDay) && (naa.TimeOfDay < arbslutt.TimeOfDay))
         {
             nummer = dag;
         }
         else
         {
            nummer = natt;
         }
      
         // Oppretter spørring for databasetilkobling
         SqlConnection alarmConnection = new SqlConnection("Data Source=(local)\\SQLEXPRESS;Initial Catalog=trysilfjellet_alarmer;Integrated Security=SSPI;");

         // Oppretter SQL-spørring for alarmer
         SqlCommand sqlCmd = new SqlCommand("SELECT * FROM alarmer WHERE alarm_item = '" + alarmID + "'", alarmConnection);
         
         // Åpner SQL-forbindelse mot alarmtabell
         alarmConnection.Open();
         
         // Lager SQL-reader som benyttes for å hente ut verdier fra SQL-base
         SqlDataReader alarmReader = sqlCmd.ExecuteReader();
            // Leser igjennom alarmdatabase og semder SMS dersom prioritet = 2   
         while (alarmReader.Read())
         {
            string alarmTekst = replceAlarmTekst(alarmReader["alarm_tekst"].ToString());
            string aktiv = Convert.ToString(alarmReader["aktiv"]);
            if(aktiv == "2")
            {
               
               sms.SendSms("0047" + nummer, "Alarm system: " + alarmReader["stasjon"] + "\n\rFeil: " + alarmTekst);
               System.Threading.Thread.Sleep(5000);
            }
         }
         // Lukker SQL-forbindelse mot alarmtabell
         alarmConnection.Close();
         
      }
      // Erstatter æøå i alarmtekst
      static string replceAlarmTekst(string p)
      {
         StringBuilder b = new StringBuilder(p);
         b.Replace("æ", "ae");
         b.Replace("ø", "o");
         b.Replace("å", "aa");
         b.Replace("Æ", "Ae");
         b.Replace("Ø", "O");
         b.Replace("Å", "AA");
         return b.ToString();
      }

    }

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Deactivate Alarm in runtime

Post by mark.monroe »

When you disable the alarm, it will never go active. First try putting your

// Deaktiverer alarm (til test.)
Globals.AlarmServer.Default_AlarmItem300.IsEnabled = false;

code on a button and see if you can disable/enable the alarm.

I believe that if you disable the alarm on the alarm active event, the alarm will not fire the next time it is triggered. But since you are in the Alarm active event, it has already been activated, and you will get the alarm.
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

bjornidar
Posts: 49
Joined: Thu Nov 17, 2011 2:10 am
Location: Norway
Contact:

Re: Deactivate Alarm in runtime

Post by bjornidar »

Hi,

I've read the post's about looping through tags and how you can use a variable as a "AlarmItem"/ tag, but I can't figure out how to do it.

if(Convert.ToInt16(comboBox1.SelectedItem.ToString()) == 0)
{
Globals.AlarmServer.Default_globalalarmItem.IsEnabled = false;
}

where globalalarmItem contains "AlarmItemXX"

This gives me error; Can't find any definition for Default_globalalarmItem,...

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Deactivate Alarm in runtime

Post by mark.monroe »

Here is an example. Alarms have to be in a group, so their name is always prefaced with the name of the group they are in.

Code: Select all

namespace Neo.ApplicationFramework.Generated
{
    using System.Windows.Forms;
    using System;
    using System.Drawing;
    using Neo.ApplicationFramework.Tools;
    using Neo.ApplicationFramework.Common.Graphics.Logic;
    using Neo.ApplicationFramework.Controls;
    using Neo.ApplicationFramework.Interfaces;
    
	using Neo.ApplicationFramework.Tools.Alarm;
	using Neo.ApplicationFramework.Tools.OpcClient;
	using System.Reflection;
	
    public partial class Screen1
    {
		
		void Button1_Click(System.Object sender, System.EventArgs e)
		{
			AlarmItem alm = StringToAlarm("Default_AlarmItem0");
			alm.IsEnabled = false;
		}
		
		public static AlarmItem StringToAlarm(string almName)
		{
			string typeName = (new AlarmItem()).GetType().Name;
			
			PropertyInfo[] props = Globals.AlarmServer.GetType().GetProperties();
			foreach (PropertyInfo prop in props) {
				if (prop.PropertyType.Name.Equals(typeName)) {
					Globals.Tags.Tag2.Value = prop.Name;
					if (prop.Name.Equals(almName, StringComparison.CurrentCultureIgnoreCase)) {
						return (AlarmItem)prop.GetValue(Globals.AlarmServer, null);
					} 
				}
			}
			return null;
		}
    }
}
Snap 2013-09-06 at 08.26.52.jpg
Snap 2013-09-06 at 08.26.52.jpg (53.9 KiB) Viewed 12491 times
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

bjornidar
Posts: 49
Joined: Thu Nov 17, 2011 2:10 am
Location: Norway
Contact:

Re: Deactivate Alarm in runtime

Post by bjornidar »

Thank you! Works like a charm!

Post Reply