Monday, 11 February 2013

Gadgeteer Ethernet J11D module not working in NETMF 4.2 projects

I had some problems getting an Ethernet module working with my Gadgeteer mainboard in a NetMF 4.2 project last night, so i thought i'd share how i got it working.

I'm using a Fez Spider mainboard and Ethernet J11D module and it seems that the Ethernet module works a bit differently under NetMF 4.2 that what i'm used to.





















Adding the Ethernet module to the Gadgeteer visual designer in the same way as other modules will cause a null reference exception.

We no longer need to add the Ethernet module to the designer. Instead we use the EthernetBuiltIn class and the NetworkInterfaceExtension.AssignNetworkingStackTo method.

You can find some sample code to get the Ethernet module working below.

You'll need to add a reference to GHI.Premium.Net for the EthernetBuiltIn class.

 static readonly EthernetBuiltIn Ethernet = new EthernetBuiltIn();  
   
     void ProgramStarted()  
     {  
       Debug.Print("Program Started");  
   
       Ethernet.Open();  
   
       NetworkInterfaceExtension.AssignNetworkingStackTo(Ethernet);  
   
       Ethernet.NetworkAddressChanged += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(Ethernet_NetworkAddressChanged);  
   
       Ethernet.NetworkInterface.EnableDhcp();  
     }  
   
     void Ethernet_NetworkAddressChanged(object sender, EventArgs e)  
     {  
       Debug.Print("Network Address Changed");  
       Debug.Print(Ethernet.NetworkInterface.IPAddress);  
     }  

This code should be enough to get you started with the Ethernet module under NETMF 4.2

Friday, 1 February 2013

Gadgeteer - Setting system time from the internet


I came across a scenario recently where i needed to get set the system time from an NTP server on my gadgeteer mainboard.

















It's easy enough to set the system time using the Utility.SetLocalTime method, but we still need some way of getting the correct time from the network.

Turns out that we have some built in functionality to do this.


TimeService


The TimeService class provides some helper methods to allow syncing the local system time from an NTP server. We can also specify a time period, after which the TimeService will update from the NTP server again.

The code below gets the current time from time.windows.com syncs the system time and prints it out the the console.

First make sure you have added a reference to Microsoft.Spot.Time


    void SetTime()   
    {   
     Debug.Print("setting time");
   
     TimeService.SystemTimeChanged += new SystemTimeChangedEventHandler(TimeService_SystemTimeChanged);   
     TimeService.TimeSyncFailed += new TimeSyncFailedEventHandler(TimeService_TimeSyncFailed);  
 
     var settings = new TimeServiceSettings();   
     settings.ForceSyncAtWakeUp = true;
   
     // refresh time is in seconds   
     settings.RefreshTime = 1800;
    
     settings.PrimaryServer = GetTimeServerAddress();
   
     TimeService.Settings = settings;   
     TimeService.SetTimeZoneOffset(0);   
     TimeService.Start();   
    }
   
    byte[] GetTimeServerAddress()   
    {   
     IPAddress[] address = Dns.GetHostEntry("time.windows.com").AddressList;   
     if (address != null && address.Length > 0)   
     {   
      return address[0].GetAddressBytes();   
     }   
     throw new ApplicationException("Could not get time server address");   
    }
   
    void TimeService_TimeSyncFailed(object sender, TimeSyncFailedEventArgs e)   
    {   
     Debug.Print("error synchronizing time with NTP server: " + e.ErrorCode);   
    } 
  
    void TimeService_SystemTimeChanged(object sender, SystemTimeChangedEventArgs e)   
    {   
     Debug.Print("network time received. Current Date Time is " + DateTime.Now.ToString());   
    }   
 

Hopefully this will be useful for someone else out there.

Thursday, 24 January 2013

HP Z1 Review


About four months ago I swapped my Windows-bootcamped iMac for a new HP Z1 workstation that HP were kind enough to let us test drive. 

First impressions were OK – it's a neat all in one matt black machine, and although not as shiny and pretty as my iMac, it's a really nice looking pc. The 27 inch ips display is stunning.

I've been using the Z1 for a few months now and as a Windows workstation i have to say that i definitely prefer the it to the iMac.

Performance wise, the Z1 is packing a quad core Xeon processor with 8gb ram and a 2gb Nvidia Quadro graphics card, which is probably a bit better than the i5 processor, 8gb ram, and Radeon graphics card in the Mac. It's a great machine on the occasions we decide to play a few games in the office.

One area where the Z1 excels is in it's upgradability. I've added a solid state drive to mine and now it beats the iMac hands down. Windows 8 boots in a matter of seconds and everything feels nice and snappy. On the bootcamped iMac it's around 15-20 seconds boot time and can occasionally feel a bit sluggish. 



I ran PC Mark 07 on both machines. The iMac scored 3205 and the Z1 with ssd scored 4940. 
Obviously it's not a fair comparison. The iMac is running a bootcamped installation of windows on a sata hard disk, whereas the Z1 is a real windows installation on a solid state drive. Unfair maybe, but i know which one I'd prefer to work on.

While it's not a laptop, it's very portable for something that's so powerful. I recently used it on an R&D project (Real Weather) as a server, and I it was really useful to be able to just pick it up and plug it in where we were setting up.   

Overall i'm really happy with the Z1. My only criticism would be aesthetic: although the screen is awesome, overall the shape/look/general shininess of the machine isn't quite as nice as the iMac, and the keyboard and mouse provided with it definitely don't look right.   But that's a relatively minor quibble considering the performance that i can get from the Z1