Ejemplo n.º 1
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            //comObj.closeComport();
            DllWrapper.th03_close_unit(tempComport);

            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
Ejemplo n.º 2
0
        private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            //----------------------------------------------------------------------
            // TEMPERATUR PROGRAM
            //----------------------------------------------------------------------

            //Console.WriteLine("Temp tjeckes");
            //this.EventLog.WriteEntry("timer1_Elapsed", EventLogEntryType.Information);
            short filtered = 1;
            short ok       = 0;

            if (first == null || first == true)
            {
                first = false;

                //Ini fil variabler
                iniTempObj   = new IniFile("C:\\SMS_temp\\iniTemp.ini");
                tempComport  = Convert.ToInt16(iniTempObj.IniReadValue("SETTINGS", "TEMP_COMPORT"));
                startmaxTemp = Convert.ToInt16(iniTempObj.IniReadValue("SETTINGS", "maxTemp1"));
                maxTemp2     = Convert.ToInt16(iniTempObj.IniReadValue("SETTINGS", "maxTemp2"));
                chan         = Convert.ToInt16(iniTempObj.IniReadValue("SETTINGS", "CHANNEL"));
                tlf1         = Convert.ToInt32(iniTempObj.IniReadValue("SETTINGS", "TLFNR1"));
                tlf2         = Convert.ToInt32(iniTempObj.IniReadValue("SETTINGS", "TLFNR2"));



                maxTemp1 = startmaxTemp;
                try
                {
                    iotHUB = new AzureIOT();
                    iotHUB.init();
                }
                catch { }

                this.EventLog.WriteEntry("tempComport " + tempComport.ToString(), EventLogEntryType.Information);

                ////Der læses settings fra InitModem filen
                //iniModemObj = new IniFile("C:\\SMS_temp\\iniModem.ini");
                //modemComport = Convert.ToInt16(iniModemObj.IniReadValue("SETTINGS", "MODEM_COMPORT"));

                ////Comporten åbnes
                //comObj = new Comport("COM" + modemComport + ":");

                //Wrapper class
                ushort th_type       = 1;  //1 for EL015 temperature sensor
                ushort filter_factor = 10; //A filter_factor of 1 means add all of the difference (effectively no filtering)

                string comport = "OK";
                if ((DllWrapper.th03_open_unit(tempComport) == 0))
                {
                    Console.WriteLine("Open tempCom fail");
                    comport = "Open tempCom fail";
                }

                //this.EventLog.WriteEntry("first_3", EventLogEntryType.Information);

                DllWrapper.th03_set_channel(tempComport, chan, th_type, filter_factor);

                this.EventLog.WriteEntry("first_4", EventLogEntryType.Information);

                mail = new SMTPClass();

                mail.SendMail("mail.unigate.dk", false, true, "", "", "", "*****@*****.**", "*****@*****.**", "", "Temperatur", "Temperatur overvågning startet. " + comport, null, null);
                this.EventLog.WriteEntry("Mail sent", EventLogEntryType.Information);
            }

            //if(doubleSMS == true) // 2 telefonnumre skal have besked
            //{
            //	iniModemObj.IniWriteValue("ACTION", "SENDRDY", "1");
            //	iniModemObj.IniWriteValue("ACTION", "TEXT", "Temperaturen er: " + (temp/100) + " grader.");
            //	iniModemObj.IniWriteValue("ACTION", "TLFNR", tlf2.ToString());
            //	doubleSMS = false;
            //}

            try
            {
                ok = DllWrapper.th03_get_temp(ref temp, tempComport, chan, filtered);                 // Temperaturen hentes
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("get temp: " + ex.Message);
                System.Diagnostics.Trace.WriteLine("OK: " + ok.ToString());
            }



            if (ok == 1 && temp > 500 && temp < 10000)            // 500 = 5 grader | 10000 = 100 grader
            {
                //iotHUB.SendDeviceToCloudMessagesAsync((double)temp / 100.00);

                //Console.WriteLine("Aflaest temp: " + (temp/100));
                //Console.WriteLine("Max temp: " + maxTemp1);


                /*if((temp/100) > maxTemp2)
                 *              {
                 *                      // Gå til ekstremer hvis den går over temp2?
                 *              }*/
                int tempA = (int)(temp / 100);
                if (tempA > maxTemp1)
                {
                    //iniModemObj.IniWriteValue("ACTION", "SENDRDY", "1");
                    //iniModemObj.IniWriteValue("ACTION", "TEXT", "Temperaturen er: " + (temp / 100) + " grader.");
                    //iniModemObj.IniWriteValue("ACTION", "TLFNR", tlf1.ToString());
                    maxTemp1 += 5;
                    mail.SendMail("mail.unigate.dk", false, true, "", "", "", "*****@*****.**", "*****@*****.**", "", "Temperatur", "Temperaturen i serverrummet er: " + tempA.ToString() + " grader.", null, null);
                    this.EventLog.WriteEntry("Mail sent", EventLogEntryType.Information);
                    //Shutdown shut = new Shutdown();
                    //shut.ShutdownAll();

                    //if (tlf2 > 0)
                    //    doubleSMS = true;
                }
                else if (maxTemp1 > startmaxTemp && (startmaxTemp - 2) > (temp / 100)) //maxTemp1 sænkes hvis temperaturen falder igen
                {
                    maxTemp1 = startmaxTemp;
                    mail.SendMail("mail.unigate.dk", false, true, "", "", "", "*****@*****.**", "*****@*****.**", "", "Temperatur", "Temperaturen i serverrummet er: " + tempA.ToString() + " grader.", null, null);
                    this.EventLog.WriteEntry("Mail sent", EventLogEntryType.Information);
                }
            }
            else
            {
                //Console.WriteLine("Read tempCom fail");

                //if(readStatus == true)
                //{
                //	iniModemObj.IniWriteValue("ACTION", "SENDRDY", "1");
                //	iniModemObj.IniWriteValue("ACTION", "TEXT", "Fejl ved aflaesning af temperaturmaaler.");
                //	iniModemObj.IniWriteValue("ACTION", "TLFNR", tlf1.ToString());
                //	readStatus = false;
                //}
            }
        }