Main Site Documentation

Question about Real Time Clock of EMX


#1

I want to set the RTC when RTC is running.

why there is no “AddYear()” and “AddMonth()” function?

I have a thread loop for the RTC setting:


        //RTC function loop 10
       static void RTCFunctionLoop()
       {
            Debug.Print("Random value Loop start:");

            while (true)
            {
                lock (ThreadLock)
                {
                    //Debug.Print("thread 10");


                    Display_Real_Time_Clock = ApplicationClass.Time_Int_To_ASCII(RealTimeClock.GetTime().Day, RealTimeClock.GetTime().Month, RealTimeClock.GetTime().Year-2000, RealTimeClock.GetTime().Hour, RealTimeClock.GetTime().Minute, RealTimeClock.GetTime().Second, Display_Real_Time_Clock);

                    //setting day
                    if (Parameter.Day)
                    {
                        Parameter.Day = false;
                        double PlusDay = Parameter.P[0] - RealTimeClock.GetTime().Day;
                        NewTime = RealTimeClock.GetTime().AddDays(PlusDay);
                        RealTimeClock.SetTime(NewTime);
                    }

                    //setting month
                    if (Parameter.Month)
                    {
                        Parameter.Month = false;
                        double PlusMonth = Parameter.P[1] - RealTimeClock.GetTime().Month;
                    }


                    //setting year
                    if (Parameter.Year)
                    {
                        Parameter.Year = false;
                        double PlusYear = Parameter.P[2] - RealTimeClock.GetTime().Year;

                    }

                    //setting hour
                    if (Parameter.Hour)
                    {
                        Parameter.Hour = false;
                        double PlusHour = Parameter.P[3] - RealTimeClock.GetTime().Hour;
                        NewTime = RealTimeClock.GetTime().AddHours(PlusHour);
                        RealTimeClock.SetTime(NewTime);
                    }

                    //setting minute
                    if (Parameter.Minute)
                    {
                        Parameter.Minute = false;
                        double PlusMinute = Parameter.P[4] - RealTimeClock.GetTime().Minute;
                        NewTime = RealTimeClock.GetTime().AddMinutes(PlusMinute);
                        RealTimeClock.SetTime(NewTime);
                    }



                    // wait to make sure data is transmitted
                    Thread.Sleep(100);
                }
            }
       }

I can only set the “day”, “hour”, “minute” successfully, how can I set the “year” and “month”, when RTC is running?


#2

DT = new DateTime(2012,6,25,12,12,0); // This will set the clock to 12:12:00 on 25 june 2012
RealTimeClock.SetTime(DT); //This will set the hardware Real-time Clock to what is in DT

#3

There is no unique value for month. It can be 28, 29, 30 or 31 days. The same for a year, which can be 365 or 366 days.


#4

thank you! I will try it!


#5

Ok, I understand now.