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.
Unable to select last Active Alarm
Unable to select last Active Alarm
- Attachments
-
- Alarm Banner.rar
- (146.13 KiB) Downloaded 737 times
Re: Unable to select last Active Alarm
It looks like the database write is too slow for the read.
You could do it this way in a script module:
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
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) { }
}
And remove the script from your Screen2
Best regards,
Russ
(801) 708-6690
Technical Support
Contact Us
Beijer Electronics AB
http://www.beijerelectronics.us
Russ
(801) 708-6690
Technical Support
Contact Us
Beijer Electronics AB
http://www.beijerelectronics.us
Re: Unable to select last Active Alarm
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.
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.
Re: Unable to select last Active Alarm
Hi Russ,
is there a way to clear the string when no alarm is active?
Thanks in advance.
is there a way to clear the string when no alarm is active?
Thanks in advance.
Best Regards,
Nikos X
Nikos X