Working Around the Missing Real Time Clock in Windows IoT

I’ve got a project planned involving Windows IoT for which I need the system to have the correct time. The Raspberry Pi with Windows IoT has no real time clock. It initializes the time over NTP when connected to a network. But when not connected to a network the time will be wrong.   It has no support for a real time clock at this point in time. That’s no good. I searched for how people have worked around this. A frequent solution was to add a real time IC and have ones solution communicate directly with the real time chip and ignore the native APIs built around time. I don’t like this solution. I’d like to maintain compatibility with other systems and not make something that is dependent on a specific implementation of a clock. I wanted a way to get the Raspberry Pi to initialize from the RTC instead of NTP.

It took a while to create a solution for this because the APIs needed to manipulate the system time are not available to UWP applications. I managed to create a solution with a power shell script, a program that I made, and a real time clock. The complete solution is available at CodeProject.com. Here is a summary of the solution. The stand alone application I made only does two things. It can read the time from the real time clock chip that I used and print it out as a string. It can also look at the system time and set the time in the real time clock to match. I use the latter of these two capabilities to set the time on the real time clock. When ever the system boots up the first of those capabilities is used to expose the current time in the RTC  to the Power Shell environment. From there I can use the Set-Date command to update the system time. I’ve saved a Power Shell script to run every time the system turns on to do just this. Now when I turn on my Raspberry Pi off network within a few seconds of turning it on it now has the right time. 😊

 

DS3231 Real Time Clock on Amazon

ViewModelBase and DelegateCommands in Sample Code

I’m working on some sample code for some upcoming blog post. There are two classes that are used throughout the examples and will probably be used in future samples. I wanted to mention them here for future blog post. This is applicable to both UWP and WPF projects. The first is the base class that I use for all of my ViewModel classes. 

using System;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Threading;


namespace Common
{
    public class ViewModelBase
    {

        public static System.Threading.SynchronizationContext SyncContext;
        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                SendOrPostCallback  a = (o) => { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); };
                if (SyncContext == null)
                    a(null);
                else
                    SyncContext.Send(a, null);
                
            }
        }

        protected void OnPropertyChanged(Expression> expression)
        {
            OnPropertyChanged(((MemberExpression)expression.Body).Member.Name);
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}

The field SyncContext is needed for code that runs asynchronously on another thread (for WPF projects this is a Dispatcher instead). If the code attached to PropertyChanged interacts with the UI an exception will occur if this interaction happens on a different thread than the one on which the UI controls were created. When the OnPropertyChanged method is called the SyncContext is used to marshal control back to the UI thread.  One of the OnPropertyChanged methods takes as an argument an expression. I prefer to use this when passing the name of the field being updated to the OnPropertyChange handler because it provides the advantage of compile checking for typos in the name and will be updated if the Rename command is used on a property.  The other frequently used class(es) is the DelegateCommand

using System;
using System.Windows.Input;

namespace Common
{
    public class DelegateCommand : ICommand
    {
        public DelegateCommand(Action execute)
            : this(execute, null)
        {
        }

        public DelegateCommand(Action execute, Func canExecute)
        {
            _execute = execute;
            _canExecute = canExecute;
        }

        public bool CanExecute(object parameter)
        {
            if (_canExecute != null)
                return _canExecute();

            return true;
        }

        public void Execute(object parameter)
        {
            _execute();
        }

        public void RaiseCanExecuteChanged()
        {
            if (CanExecuteChanged != null)
                CanExecuteChanged(this, EventArgs.Empty);
        }

        public event EventHandler CanExecuteChanged;

        private Action _execute;
        private Func _canExecute;
    }

    public class DelegateCommand<T> : ICommand
    {
        public DelegateCommand(Action<T> execute)
            : this(execute, null)
        {
        }

        public DelegateCommand(Action<T> execute, Func<T, bool> canExecute)
        {
            _execute = execute;
            _canExecute = canExecute;
        }

        public bool CanExecute(object parameter)
        {
            if (_canExecute != null)
            {

                return _canExecute((T)parameter);
            }

            return true;
        }

        public void Execute(object parameter)
        {
            _execute((T)parameter);
        }

        public void RaiseCanExecuteChanged()
        {
            if (CanExecuteChanged != null)
                CanExecuteChanged(this, EventArgs.Empty);
        }

        public event EventHandler CanExecuteChanged;

        private Action<T> _execute;
        private Func<T, bool> _canExecute;
    }
}

The DelegateCommand class is used to make commands that can be bound to a button. This allows us to use DataBinding to associate code with a button through data binding. 

XNA Animated Sprite code uploaded to CodeProject.com

I’ve uploaded some code I was working on to animate sprites in XNA.

Animating a sprite isn’t difficult, but I wanted some way to animate them but reduce the coupling between code and the animation. The Content Pipeline is perfect for this. So I created a component that will handle the animation scenarios that I need along with a content extension so that I could load these animations as content. Right now the animation information is in an XML file. This is a stepping point towards having a graphical tool for handling this.

You can read about the code here or see a brief description of it in the video below

Welcome to the Site Mirror!

It seems that my hosting provider has gone through some changes for the worst; once a week for the past three weeks this site has gone offline because of some failure or data loss at my provider’s location. Because of the decrease in reliability I’ll be looking for a new provider. In the mean time I’ve started mirroring my content at here. Any new content I write will also be published here(I may just use WordPress as the primary host for this site, still undecided). If the main site ever goes down remember you can see the content heretoo.

More than enough?

When it comes to computer resources I’ve always had this philosiphy that you don’t have enough until you have more than enough. That philosiphy worked out fine for me in the desktop days when the cost in space and power consumption were unnoticable. But now with all my machines (save one) being portables, it makes a big difference.

The laptop I use for work is a Dell Precision M6400. I received the machine with 4 gigs of ram and a measley 160 gig hard drive. The machine had empty memory slots and an empty drive slot. So I bumped the ram up to 12 gigs and added a second (500 gig) drive.  Adding the RAM solved a performance problem I was having; 4 gigs just wasn’t enough for the virtual machines I needed to run and for multiple instances of Visual Studio. But now that I have the RAM the machine runs much hotter. When it comes out of the hibernate state I’ve got to wait for a 12 gig hibernation file to open. If I put it in standby it won’t last a full day before the battery dies. With the extra drive and the RAM together its hard to make this machine last much longer than 20 minutes on battery power. I didn’t think I’d ever say this but I don’t plan to ever max this machins RAM or storage out in light of the tradeoffs of doing so. I’m going to take the original hard drive out.

The lesson I learned from this is that everything has it’s cost, even having more than enough.

New Hardware: Samsung Galaxy Tab

If you follow me on Twitter you’ll know I’ve been looking for a new tablet device. I’ve made my decision. I was originally going to get a Windows tablet. But when I looked at the available tablets I found that the emphasis seems to be on making them smaller and lighter and as a consequence they are lower powered than what I have with longer battery life. I get pretty good battery life already, so there wasn’t a big incentive for me to get a new Windows tablet just yet. Mine is good enough.

For a breif moment I considered the iPad 2 but the new unit looks to be an incremental upgrade from the original. So I’m leaving it alone.

Next on the list was an Android tablet. That’s what I got, a Samsung Galaxy Tab. It’s a nifty little device in it’s own right. It’s small enough to fit in one hand or the back pocket of some jeans (not that I recommend carrying that way, to many pick pockets around) but large enough to make for a good eBook reader. I was also pleased with how consistent it is with other Samsung devices. I’ll be talking more about it (and another mobile operating system!) in the coming weeks.

iOS Firmware Expired?

This always happens to me. After installing a beta/pre release version of iOS I forget to install the final version when it comes out and the firmware expires. Unlike regular firmware updates I’ve never been prompted by iTunes to perform an update of the firmware when a release version is available. It seems that one has to download it and install it manually. When the firmware expires you end up with a device that has all of the notifications and reminders still showing up but the inability to get to the applications producing those notifications or reminders.

Anyway, this happened to me again the other day. I didn’t feel like addressing it then, but now that I’ve got the time I’m downloading the updated firmware (manually) to install. I found the site iPhoneFirmware.com which keeps track of the direct links to all of the iOS device firmware. Makes it much easier to find what I need. On the downside this looks to be a 30 minute download, so I’ll go do some other development for a while.

Dare to Dream Different Contest

Microsoft is having yet another embeded development contest.  This ons is cenetered on the .Net Microframework.  For more details see the contest web site.  The contest has three phases with each phase eliminating contestants.

  • October 8 – December 15th : Present your idea
  • January 15 – May 15th : Build your idea
  • April 15 – May 31: Present your idea.

The final round sounds tough; has to be presented before a board of industry experts.  But if you survive the first round Microsoft will provide for you the hardware and the software that you need for the next round.  The prices are worth over $100k.  I don’t know what they are but if nothing else the community recognition would make the contest worth the effort.

 

 

Windows Mobile Licensing

I saw a posting on WMExperts.com about Microsoft’s licensing fees for Windows Mobile (the information cam from Reuters).  In short the posting said that Microsoft will continue to charge licensing fees for Windows Mobile and also brings attention to the functionality packaged with Windows Mobile that isn’t available with some of the free mobile operating systems.

  • Built-in Exchange push e-mail support.
  • Support for remote device management, application deployment and device policy management.
  • Support for full device encryption (including external memory cards).
  • Free sync with Windows Live Hotmail and Live Contacts.
  • Windows Live Search.
  • Live Messenger IM Client.
  • Software for simple Internet Sharing.
  • Office files reading and editing.
  • A pretty good e-mail application with built-in smart filtering search.
  • A pretty good Bluetooth stack.
  • Access to 18000 + applications already out in the market.
  • Support by carriers and a wide developer community.
  • Security certification by recognized accreditation bodies.
  • Indemnification for the technology used.

I hadn’t considered this before. but after reading it I have to wonder whether or not I should really consider the other OSes to be free.  I see quite a few features in the above that I would really hate to be without.

 

Cell Tower Rejection?

I make business trips to Scottsdale, Arizona about once ever two – three months.  When I came to Scottsdale on Monday I brought my AT&T Tilt (HTC TyTn II) with me.  This is the first 3G phone that I’ve owned.  The phone has been fitting my needs well for the past couple of months.  Before I got on the plane to Arizona I made a few phone calls, turned off the phone, and boarded the plane.  After landing my coworker and I caught a taxi to the hotel and I called home to let my family know that I had safely arrived.

Some time later I was looking at my phone and noticed it was searching for a signal.  It found one and showed 5 bars for about 15 seconds then went back to looking for a signal.  I watched it do this for about 30 minutes writing writing down the times the device went from having a tower fix to searching for a tower. It would get a fix 15 seconds after the devices clock changed to a time that had an even number for minutes.  In this state the device was almost useless; I could send a SMS as long as it was sent during this 20 second window, but I could do nothing more.

I spoke with AT&T and a representative told me the problem was with my SIM card and that the 64k AT&T SIM cards could not be used in 3G devices.  Not quite believing this I removed the SIM from the 3G data card for my laptop and saw it used the same type of SIM card.  I swapped the SIMs and found that the problem followed the phone and not the SIM.  After a lot of web research I found other customers that had experienced the same problem and some one pointed out that the problem was specific to phones acting in 3G mode. The theory was that some phones were being inexplicably rejected by some towers in 3G mode.

After hearing that I began searching for programs that I could use to disable the 3G mode in my phone and stubled on something I had seen a few weeks ago but had ignored. It is called CommMgrPro. I used the program to disable 3G mode depending on what tower the phone was connected to it afterwards I was able to make phone calls again.  I don’t have confidence in the theory I received from the AT&T rep about the problem being caused by the type of SIM card that I am using.  I can’t completely accept compromising the functionality of my phone as a solution to the problem.  I’ve forwarded the information I have on the problem to Mickey at The Cell Phone Junkie (http://thecellphonejunkie.com). He will be recording his next podcast on Sunday night and hopefully he will be able to give insight to the problem with his podcast is made available on Monday morning.

 

Microsoft’s Windows Mobile, Apple’s iPhone, and RIM’s Blackberry

In the past week I’ve seen several post on the MSDN Smart Device forums asking essentially the same question.  Some one has developed (or will develop) a program for one platform (Windows Mobile, Blackberry, iPhone) and wants to make the program run on the other.  I’ve answered the questions as I’ve encountered them, but since it is a frequent question I decided to write a post about it so that I can refer people back to an answer as the question comes up.

What is a Platform?

A platform is a collection of functionality along with the methods for accessing that functionality provided to support an application. Traditionally platforms have been viewed as a combination of hardware and software; a software application would require a certain software platform (the operating system) running on a certain hardware platform (the physical computer with a certain processor).  While that definition is still applicable presently we also have what would be considered pure software platforms; a developer targeting a browser can target a specific web standard as their platform with little to no concern for the hardware on which it is run.  It is important to also note that platforms can be layered; one platform can exists on top of another. For mobile devices I can name 5 platforms; Windows Mobile, iPhone OS X, Blackberry, Android, and Symbian.  As I type this

How do I make this program developed on platform X run on platform Y.

Unfortunately in most cases the answer to this question is “you don’t.”  You will need to rewrite your application for the other platforms on which you need for it to run. What’s the workaround for this?  Well, as I mentioned in my definition for a platform, “platforms can be layered; one platform can exists on top of another.”  If you have two dissimilar platforms and if those two platforms can support the same software platform then you can target that common platform and end up with a single application that runs on multiple platforms.

Web browsers are going to be the most common platform that you can target.  But browser applications have their limitations (those limitations are diminishing).  The two most populate virtual machine platforms are .Net and Java, but you will find that presently different devices have different levels of support for these two platforms.

So What are you Saying

After reading the above you should be able to infer what I am about to conclude.  IF you need to run a single application for multiple platforms make it a web app and adapt it to the browsers (or browser standards) that you wish to support.  If it absolutely has to be a native application then you will not be able to create a single application that runs on Windows Mobile, iPhone, Symbian, Blackberry, and OS X.

/www.j2i.net.html

 

.Net Micro Framework Development Board

The Windows Embeded Blog had a post about a .Net Micro framework development solution that cost under 100.00 USD. For the pricepoint and the functionality this is an incredible package!  I may have to pull out my notebooks for some of the automotive projects I wanted to do (I had been considering a Windows CE device for those projects but I think this package should be more than adaquate).  If you are interested you can grab one of these from GHI Electronics.

Update [2008-09-18 23:20 UTC] – feeling that this is such a power product I’ve already submitted an order for one for myself.

 

New Tilt Firmware Buggy?

The Tilt firmware update was welcomed with open arms.  I installed it, and after a few failed attempts I figured out how to prevent the bloatware from installing.   But the 6.1 firmware for the Tilt is not working as well as I had hoped.  The most annoying problem is that if the device is suspended for more than a certain amount of time upon turning it on the device turns off again.  I just found out that I am not the only one experiencing problems.  Over at Tilt Site (a subsite of the Mobility Site) users are reporting many of the same problems that I have experienced since the upgrade.  I’m not optimistic that another firmware update is forthcoming since AT&T must approve all firmware updates and they are planning to EOL (End of Life) the device. I may end up returning to the previous Windows Mobile 6.0 firmware image (so long threaded messages).

 

What Tools do I Need to Develop for Windows Mobile?

Several times in the past two weeks I’ve seen users on the MSDN forum ask what software tools are needed to develop for Windows Mobile.   It’s possible to develop for Windows Mobile devices using the .Net Compact Framework SDK and the command line compiler.  I would never suggest that some one do that; IDEs provide a much better debugging and development experience. The chart collowing this paragraph will let you know what versions of Visual Studio that you can use for each Windows Mobile and .Net version.  Note that no Visual Studio express version is lited here.

Visual Studio Version Supported Windows Mobile Versions
Visual Studio .Net 2003 Supports .Net Compact Framework 1.0 for Pocket PC 2002 and Windows Mobile 2003
Visual Studio 2005 Standard Edition or Better .Net 1.0 and .Net 2.0 from Windows Mobile 2003 to Windows Mobile 6
Visual Studio 2008 Professional .Net 2.0 and 3.5 from Windows Mobile 5 to Windows Mobile 6

Programs that you cannot presently use for Windows Mobile development include the express editions of Visual Studio and Visual Studio 2008 Standard.