Welcome Guest ( Login | Register )



All times are UTC - 7 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Unable to select last Active Alarm
PostPosted: Wed Feb 12, 2020 6:15 am 

Joined: Fri Apr 05, 2019 11:56 pm
Posts: 8

Offline
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 1 time
 Profile  
 
 Post subject: Re: Unable to select last Active Alarm
PostPosted: Fri Feb 14, 2020 5:56 pm 
User avatar

Joined: Thu Nov 16, 2017 3:32 pm
Posts: 195

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

You could do it this way in a script module:
Code:
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


 Profile  
 
 Post subject: Re: Unable to select last Active Alarm
PostPosted: Sat Feb 15, 2020 9:51 pm 

Joined: Fri Apr 05, 2019 11:56 pm
Posts: 8

Offline
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.


 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 7 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron