Example #1
0
        private void CheckAlarmStatus()
        {
            //Deklarerer variabler.
            bool highTemp;
            bool lowTemp;
            bool tempOOR;
            bool batAlarm;
            bool arcomAlarm;
            bool batteryAlarm;
            // Gir verdier til variabler.
            double spH            = Convert.ToDouble(dbRead.GetHighSp(1));
            double spL            = Convert.ToDouble(dbRead.GetLowSP(1));
            double realTemp       = realTemp = arCom.Readtemp();
            int    spLBattery     = 40;
            int    batteryPercent = batteryMonitoring.PercentBatteryLeft;
            double timeLeft       = batteryMonitoring.TimeLeft;

            //Kaller opp metoder i alarmklassen og sender med parametere. Returnerer true eller false utifra verdier.
            highTemp     = alarm.HighTempAlarm(spH, realTemp);
            lowTemp      = alarm.LowTempAlarm(spL, realTemp);
            tempOOR      = alarm.TempOutOfRange(realTemp);
            batAlarm     = alarm.BatteryAlarm(batteryMonitoring.StatusChanged());
            arcomAlarm   = alarm.ArduComAlarm(arCom.comFault);
            batteryAlarm = alarm.LowBatteryPercent(spLBattery, batteryPercent, batAlarm);

            //Her sjekkes verdien til variablene. Hvis der "true" vil det skrives en alarm til databasen og det vil sendes en mail.
            //Til slutt oppdateres AlarmGrid.
            if (highTemp)
            {
                string message = "Temperature extended setpoint: High (" + spH + "°C). Temperature =" + realTemp.ToString() + "°C";
                dbWrite.WriteToAlarmHistorian(1, message);
                mail.SendMessage(message);
                this.Invoke((MethodInvoker) delegate { UpdateAlarmGrid(); });
            }
            if ((lowTemp) && (!arcomAlarm))
            {
                string message = "Temperature extended setpoint: Low (" + spL + "°C). Temperature =" + realTemp.ToString() + "°C";
                dbWrite.WriteToAlarmHistorian(2, message);
                mail.SendMessage(message);
                this.Invoke((MethodInvoker) delegate { UpdateAlarmGrid(); });
            }
            if ((tempOOR) && (!arcomAlarm))
            {
                string message = "Temperature out of range. Temperature =" + realTemp.ToString() + "°C";
                dbWrite.WriteToAlarmHistorian(3, message);
                mail.SendMessage(message);
                this.Invoke((MethodInvoker) delegate { UpdateAlarmGrid(); });
            }
            if (batAlarm)
            {
                string message = "Lost powerline. Laptop is running on battery";
                dbWrite.WriteToAlarmHistorian(4, message);
                mail.SendMessage(message);
                this.Invoke((MethodInvoker) delegate { UpdateAlarmGrid(); });
            }
            if (arcomAlarm)
            {
                string message = "Lost Connection to Arduino";
                dbWrite.WriteToAlarmHistorian(5, message);
                mail.SendMessage(message);
                this.Invoke((MethodInvoker) delegate { UpdateAlarmGrid(); });
                MessageBox.Show("The program could not find the Arduino. Go to Preferences to change COM port");
            }
            if (batteryAlarm)
            {
                string message = ("Low Battery percent. " + timeLeft + " minuttes until system shut down" + batteryPercent + "% left");
                dbWrite.WriteToAlarmHistorian(6, message);
                mail.SendMessage(message);
                this.Invoke((MethodInvoker) delegate { UpdateAlarmGrid(); });
                MessageBox.Show("Low Battery percent. " + timeLeft + " minuttes until system shut down" + batteryPercent + "% left. Connect charger");
            }
        }
Example #2
0
 private void FillTextBoxes()
 {
     txtSpL.Text = dbRead.GetLowSP(1);
     txtSpH.Text = dbRead.GetHighSp(1);
 }