Friday, February 27, 2009

MSDN Premium Subscription with Visual Studio 2008

working file I have another free MSDN Premium subscription which I will give you for free.

Well, what you have to do is to link to my blog and add a comment with a link to your page, that’s all. In about 2-3 weeks I will create a simple application that will run a lottery on a .NET Micro Framework device and tell me the lucky winner.

For more details what is included have a look at the subscriptions comparison page at MSDN.

Wednesday, February 25, 2009

The .NET Micro Framework Home – Microsoft’s new start page

Microsoft has released a new start page for the .NET Micro Framework.

imageIf you are new to the .NET Micro Framework you will have a look at the Getting Started page. There you will find everything you need to start right now developing great devices.

What hardware should I use? Have a look at the Get Turnkey Hardware overview. Jan has a more detailed overview on his hardware comparison.

The Microsoft .NET Micro Framework team has its own blog which is available here. Developers should have a look at the MSDN section for .NET Micro Framework.

And don’t forget to fill out the survey for next version 4.0.

Tuesday, February 24, 2009

Managed Driver for C6820 Camera Module

imageFreesc Huang has started to build a C6820 camera module driver written in managed code. His project is available including source code at CodePlex. The C6820 camera offers JPEG images.

There is another implementation for the .NET Micro Framework for the C328R camera.

Serial Communication in .NET Micro Framework

Celiker wrote a short demo how to use serial communication in .NET Micro Framework using the Tahoe-II device.

public SerialPort c1 = new SerialPort("COM1", 9600);
private void OnButtonUp(object sender, ButtonEventArgs e)
        switch (e.Button) // e is the event record
            case Button.VK_RIGHT:

                byte[] gond = System.Text.UTF8Encoding.UTF8.GetBytes
                     ("Second : "+DateTime.Now.Second.ToString()+"\n");

                c1.Write(gond, 0, gond.Length);
    catch (Exception ex)
        text.TextRuns.Add("HATA : "+ex.Message, Resources.GetFont
        (Resources.FontResources.small), Colors.Red);

Read full story and download source code at CodeProject.

Don’t forget to have a look at the SerialPortEx class on Pavel’s blog.

HTTP Server running on .NET Micro Framework

I have updated the source code files of my simple http server to support http post. You can find the sources at CodePlex project mschwarztoolkit.

I’m currently running a simple web server live at

To use the http server you simple have to create a new instance of HttpServer with the port you want to listen on and implement a IHttpHandler (which will be very similar to IHttpHandler in ASP.NET development).

using (HttpServer http = new HttpServer(new MyHttpHandler()))
    // http.OnLogAccess += new HttpServer.LogAccessHandler(http_OnLogAccess);
    Console.WriteLine("Shutting down http server...");

Have a look on a very simple implementation of IHttpHandler:

class MyHttpHandler : IHttpHandler
    public MyHttpHandler()

    #region IHttpHandler Members

    public void ProcessRequest(HttpContext context)
        context.Response.ContentType = “text/html”;
        context.Response.Write(“<body>” + context.Request.Path + “<br/>”);


The demo above will simply return a html file containing the requested path and the current time on the device.

I will add some more examples next to read some values from XBee modules (temperature sensor) and update those values using AJAX.

SD Card Issue on Tahoe Boards – new release available soon

Some developers have reported an issue with some SD cards used on a Tahoe-II board. The same happens to me that some SD cards are readable and other not. Martin Welford has confirmed this issue some minutes ago and announced a new release:

We have found the SD card issue.  The cards that don't work are formatted with an MBR (which is not part of the SD spec, and hence not supported by the MS driver).  Re-formatting and removing this is not easy to do, and we are working on a solution to this now.  A new release wil follow as soon as this is sorted.

Keep an eye on my blog or subscribe the Device Solutions blog.

.NET Micro Framework SDK 3.0 February 2009 Documentation Update

If you don’t have already updated your .NET Micro Framework SDK docs, here you’ll find the new version.

This download provides an update to the .NET Micro Framework Platform SDK version 3.0 documentation. Please install the Micro Framework SDK v3.0 (see link below) before performing this update.

image.NET Micro Framework 3.0 SDK must be installed.

Did you had a look at the new video to see how the .NET Micro Framework is driving innovation by making small-device development easier and faster?

What’s next with .NET Micro Framework 4.0?

netmf4 Microsoft has opened a survey on Microsoft Connect concerning the next version of .NET Micro Framework:

The purpose of this survey is to obtain inputs and feedback from valuable industry thought leaders like you to help design the next version of our product. Please respond to the following questions to the best of your ability. Thanks in advance for your participation!

What is the .NET Micro Framework more commonly known as? How likely are you to use .NET Micro Framework for your next embedded development project? While selecting a platform for your next embedded project, which one of the following do you think will be the most important?

I’m looking forward running first tests on .NET MF 4.0 and to see more .NET MF enabled devices. Currently I see that some companies that have started building .NET MF devices stopped at version 2.5, others are starting right now with the latest version and all the great features.

Monday, February 23, 2009

GM862 GSM and GPS Module Class

image Else is using a GM862 GSM and GPS module from SparkFun in his Dare to Dream Different Challenge project. The GM862 is using AT commands (comparable with XBee modules) and could be easily used on .NET Micro Framework devices. He as uploaded an example program on his page.

Here are some source code lines he is using for to talk with the modules:

// Initialize GSM/GPS Device
GM862 = new GM862GPS("COM1");

// Make sure GM862 is in command state

// Wait until GM862 is ready
while (true) {
    try {
        GM862.ExecuteCommand("ATE1", 500);
    } catch {

// Store new pinRequest Handler
lock (GM862)    {
        GM862.getRequestedPIN = GM862_pinRequest;

Tahoe and Tahoe-II – don’t mix firmware updates

Last week I tried to update my Tahoe boards. While downloading updated SDKs I first started to flash the firmware on the newer Tahoe-II board (the one with the XBee connector). When finished I tried to publish my .NET MF application using Visual Studio 2008, but I could not get the screen working, it leaves black. Oh no, I need this device this week, please no hardware problem. I contacted Devices Solutions and while clicking on the Send button in my mail client I noticed that I have flashed my new Tahoe-II with the firmware of the older Tahoe board.

Well, I could easily flash the correct firmware to the Tahoe-II board and my screen comes back. Martin told me that they will add a check maybe in further firmware updates.

Wrong Date and Time on my .NET MF Device

Since embeddedworld2008 in Nuremberg I'm playing in my free time with the .NET Micro Framework and the Digi Connect ME network device. I've created a small Web server and ported the Ajax.NET Professional library to the really cool and small .NET framework.

When I reset such a device the current date and time gets wrong, too. This is very bad as I would like to have always the correct time, of course. Especially when you are working with Web servers it is very important to have the correct time because http headers contain date info when files should expire or how long they are allowed to be cached locally in Web browsers cache.

I have created a simple method to query a NTP server and set the device date to the returned value. Here is the code:

public static DateTime GetNetworkTime() {
    IPEndPoint ep = new IPEndPoint(
        Dns.GetHostEntry("").AddressList[0], 123);

    Socket s = new Socket(AddressFamily.InterNetwork,
                                                        SocketType.Dgram, ProtocolType.Udp);


    byte[] ntpData = new byte[48]; // RFC 2030
    ntpData[0] = 0x1B;
    for (int i = 1; i < 48; i++)
        ntpData[i] = 0;


    byte offsetTransmitTime = 40;
    ulong intpart = 0;
    ulong fractpart = 0;

     for (int i = 0; i <= 3; i++)
        intpart = 256 * intpart + ntpData[offsetTransmitTime + i];

    for (int i = 4; i <= 7; i++)
        fractpart = 256 * fractpart + ntpData[offsetTransmitTime + i];

    ulong milliseconds = (intpart * 1000 + (fractpart * 1000) / 0x100000000L);

    TimeSpan timeSpan = TimeSpan.FromTicks((long)milliseconds *

    DateTime dateTime = new DateTime(1900, 1, 1);
    dateTime += timeSpan;

    TimeSpan offsetAmount = TimeZone.CurrentTimeZone.GetUtcOffset(dateTime);
    DateTime networkDateTime = (dateTime + offsetAmount);

    return networkDateTime;

To set the returned DateTime as new time on the device use following utility method:


Note, that the current time zone is often wrong, too. Use following method to set the time zone to the correct value, in my example I use the time zone here in Germany:


I put this code in the Main() method of my applications to get always the correct date when I start my device.

Newer devices have a battery on board that will hold the date and time information and don’t require a NTP request or manual set.

Wake-on-LAN (WoL)

Well, I love the easy development of embedded devices with the .NET Micro Framework. As the device I'm currently using is really small I tried to build a small Web site on it to start my private servers at home using Wake-on-LAN. You'll find a lot of helper methods samples on the Internet but I couldn't find on source code that was working on the .NET Micro Framework. The problem is that there are too many missing methods or enum values.

Here is the source code I'm using now which is working.

public static void WakeUp(byte[] mac) {
    using (Socket socket = new Socket(AddressFamily.InterNetwork,
                                                                           SocketType.Dgram, ProtocolType.Udp))
        IPEndPoint endPoint = new IPEndPoint(new IPAddress(4294967295), 40000);
        // IP


        byte[] packet = new byte[17 * 6];
        for (int i = 0; i < 6; i++) packet[i] = 0xFF;
        for (int i = 1; i <= 16; i++) {
            for (int j = 0; j < 6; j++) {
                packet[i * 6 + j] = mac[j];


My network related library for .NET Micro Framework (as well as .NET Compact and the desktop/server version) includes this method.

MFDeploy and MAC Address / DHCP

Some months ago I received a Embedded Master development kit from GHI Electronics. First I tried the examples that are already on the board, wow, working great. To get a network application working I had to change the IP address (or change it to use DHCP). I downloaded MFDeploy (MSDN Library) from the Microsoft Download site. The manual says that you have to enter 00-21-03-80-00-00 and for the last two numbers you have to use the hex value of the serial number of the board. I tried this but MFDeploy didn't accept my value until I have noticed that I have to use the colon instead of the dash as separator.


For those of you trying to use DHCP enter for all IP addresses, but don't forget to put in your MAC address as DHCP servers need this.

3 Examples using MSchwarz.Net.Dns

My small .NET library which covers some network related protocols includes a DNS library. With this library you can query a DNS for i.e. the A record (IP address of a domain) or the corresponding mail server of a given domain (MX record). Here are three examples using the library.

All queries are working the same: you have to build a DnsRequest that includes the Question. The Resolve method of the DnsResolver will return a DnsResponse which contains the answer (or answers).

On a desktop .NET environment you can automatically load the DNS settings of the network adapter (for .NET Micro Framework this will be added next).

DnsResolver dns = new DnsResolver(); dns.LoadNetworkConfiguration();

Or by specifying the DNS server in the constructor (currently necessary in .NET MF):

DnsResolver dns = new DnsResolver(IPAddress.Parse(""));


1) Query IP Address of a given Domain (A Record)

DnsResponse res = dns.Resolve(
    new DnsRequest ( new Question (, DnsType.A, DnsClass.IN ) )

You will now have one or more answers in your DnsResponse:

foreach(Answer a in res.Answers) {

2) Query MX Records (Mail Exchange)

Instead of DnsType.A in the above example we’re using DnsType.MX, now. The rest of the code to write is the same. The MX record contains a Preference and a Domain that will be responsible for receiving mails for the domain. This can be accessible in the Record property of the Answer instance:

foreach(Answer a in res.Answers) {
    MXRecord mx = a.Record as MXRecord;
    if(mx != null) {
        Console.WriteLine(mx.Preference + " " + mx.Domain);

3) Reverse DNS Lookup (PTR Record)

For PTR records you need to specify the IP address instead of a domain name in the Question object.

string ip = "";
Question q = new Question(ip, DnsType.PTR, DnsClass.IN);

DnsResponse res = dns.Resolve(new DnsRequest(q));

AUG AMI DevKit shipping

AUG Elektronik GmbH has sent me AUG AMI DevKit for the .NET Micro Framework 3.0. I have received the package last weekend. Have a look at the content of the box:


The contents in detail are

  • the AMI board (MH080407 Rev. 2)
  • 3.4" AMOLED display in a plastic housing that can be screwed to the AMI board
  • resistive touch screen glued on top of the display
  • 4 plastic screws used as a stand for the display and board
  • a 1 GB Kingston USB-stick containing full documentation in PDF format and install-files for SDK, samples and more
  • a 5 V regulated power supply plug (110..240 V AC, 50/60 Hz)
  • USB-flash adapter cable for SAM-BA
  • serial cable (RS-232 PC pin assignment - use a null-modem-cable to connect to a PC)
  • DBGU serial cable (RS-232 device pin assignment - directly connect to a PC)
  • standard USB A-B cable
  • standard Ethernet patch cable
  • "Getting Started" document in printed form

My first experience was to put my little web server on the device, everything is working. What makes me very happy is the OLED display where colors look really nice compared to typically used TFT screens. I will publish some photos I have taken later this afternoon.