Unable to select last Active Alarm

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
Subho
Posts: 9
Joined: Fri Apr 05, 2019 11:56 pm

Unable to select last Active Alarm

Post by Subho »

I am trying to select the last active alarm using following script.

void Screen2_Opened(System.Object sender, System.EventArgs e)
{
SQLiteConnection db = new SQLiteConnection("DataSource=Database.db");
string query ="Select [Text] from AlarmServer WHERE State = 'Active' ORDER BY ActiveTime DESC LIMIT 1";
SQLiteCommand comm = new SQLiteCommand(query);
comm.Connection = db;
db.Open();
SQLiteDataReader read = (null);
read = comm.ExecuteReader();
while (read.Read())
{
Globals.Tags.AlarmString.Value = (read["Text"].ToString());
}
read.Close();
db.Close();
}

But it always select Last-1 alarm and show its text in AlarmString tag. Where am I doing wrong?

I have also attached the project for reference.
Attachments
Alarm Banner.rar
(146.13 KiB) Downloaded 621 times

User avatar
Russ C.
Posts: 213
Joined: Thu Nov 16, 2017 3:32 pm
Contact:

Re: Unable to select last Active Alarm

Post by Russ C. »

It looks like the database write is too slow for the read.

You could do it this way in a script module:

Code: Select all

void ScriptModule1_Created(System.Object sender, System.EventArgs e)
		{
			Globals.AlarmServer.AlarmActive += AlarmStatus;
		}

		void AlarmStatus(System.Object sender, System.EventArgs e)
		{
			try
			{
				IAlarmEvent alarm = (IAlarmEvent)sender;
            
				Globals.Tags.AlarmString.Value = "";
				Globals.Tags.AlarmString.SetString(alarm.DisplayText);

			}
			catch (Exception) { }
		}
What this does is capture the triggering alarm event and pull its data, so only the most recent active alarm will be distplayed.

And remove the script from your Screen2
Best regards,

Russ
(801) 708-6690
Technical Support
Contact Us

Beijer Electronics AB
http://www.beijerelectronics.us

Subho
Posts: 9
Joined: Fri Apr 05, 2019 11:56 pm

Re: Unable to select last Active Alarm

Post by Subho »

Thank you Russ for the script. It solved the problem. :)

I am also wondering if Alarm ID can be selected using the same script and acknowledge that particular Alarm when the "Close" button is pressed.

nxen
Posts: 19
Joined: Wed Jan 16, 2013 3:18 am

Re: Unable to select last Active Alarm

Post by nxen »

Hi Russ,

is there a way to clear the string when no alarm is active?

Thanks in advance.
Best Regards,
Nikos X

Post Reply