Main Site Documentation

Graphical Demo - RealTimeClock issue


#1

Hi Guys,

I am trying to get the graphical demo running on my cobra, and am getting an exception here:

if (RealTimeClock.IsTimeValid)
Utility.SetLocalTime(RealTimeClock.GetTime());

It is going on the SetLocalTime:

The thread ‘’ (0x2) has exited with code 0 (0x0).
#### Exception System.ArgumentOutOfRangeException - CLR_E_OUT_OF_RANGE (1) ####
#### Message:
#### System.DateTime::.ctor [IP: 0000] ####
#### GHIElectronics.NETMF.Hardware.RealTimeClock::GetTime [IP: 001e] ####
#### GHIGraphicalDemo.Presentation.Taskbar::.ctor [IP: 0099] ####
#### GHIGraphicalDemo.Presentation.Desktop::.ctor [IP: 011b] ####
#### GHIGraphicalDemo.Program::Main [IP: 0043] ####
A first chance exception of type ‘System.ArgumentOutOfRangeException’ occurred in mscorlib.dll
An unhandled exception of type ‘System.ArgumentOutOfRangeException’ occurred in mscorlib.dll

As A test I did this:

        if (RealTimeClock.IsTimeValid)
        {
          DateTime dtNow = RealTimeClock.GetTime();
        }

This also caused the exception.

So I did this:

        if (RealTimeClock.IsTimeValid)
        {
          RealTimeClock.SetTime(DateTime.Today);
          DateTime dtNow = RealTimeClock.GetTime();
          Utility.SetLocalTime(RealTimeClock.GetTime());
        }

Now everything worked.

So it looks like IsTimeValid can return true even when the DateTime is not valid!

Maybe a bug?

Cheers

Andy


#2

IsTimeValid is to check that the RTC is functional or not but I guess it is possible that the RTC is urning but it is running with the wrong time!


#3

The original code now works having set the rt clock once.

Must have had a bit of garbage in there!

Andy


#4

We have added this to the list, should be able to make it better.


#5

Nice one.

Thanks.

Andy


#6

Problem is back after a power cycle.

Is there a battery somewhere than may be flat?

Cheers

Andy


#7

This is strange. Wrap up the code with try-catch for now and we will look into it


#8

Ok Thanks.

Andy


#9

Andy,

[quote]Problem is back after a power cycle.
Is there a battery somewhere than may be flat?[/quote]

You probably have to added some kind of 3V, i.e 6mm coin battery,

  • to the connector that labeled RTC_VBAT (connector #5 from the top)
    and - to ground,
    in order to keep the time right after you set the time on your Cobra.

#10

Ah, nice thanks for the info.

Andy