Embedded application development has come a long way from writing code in
error prone assembly language. Earlier writing code for a device needed high
level programming skills, but a lot has changed now. If you know how to write
code in C# you can still write code for smaller devices. On top of this,
embedded development has been further boosted with the availability of IDE (integrated
development environment) support. One example of this is .NET Micro Framework
which contains a subset of .NET libraries for building embedded applications for
resource constrained devices.
Direct Hit! |
Applies To: .NET developers USP: Learn to simplify embedded programming Primary Link: www.microsoft.com/netmf Keywords: .NET Micro Framework |
The high point of this framework is its integration with Visual Studio that
provides embedded developers a good ecosystem for writing applications. Besides
providing ability for writing code, the .NET Micro Framework also provides a
hardware emulator for rapid prototyping and debugging. These emulators can also
be extended for different hardware. This framework can run on small 32-bit
processors and there is no requirement for a memory management unit in the
processor. Instead of using a full version of an operating system, the .NET
Micro Framework uses a scaled version of Common Language Runtime that sits
directly on hardware with very low memory (RAM) requirements. Now the question
arises why should one use this framework when there are other Microsoft embedded
technologies available like Windows CE and Windows XP Embedded? The answer is
that the .NET Micro Framework uses the lowest resources as compared to the other
two. This framework provides an abstraction that allows the application to be
separated from the hardware platform. The code specific to the hardware platform
is fed into a hardware abstraction layer (HAL) so that the .NET Micro Framework
and applications can be moved to new platforms without any difficulty.
The .NET Micro Framework is ideal for resource constrained devices as there is no need for an underlying OS. |
After you have installed the SDK you can find new project templates in the 'New Project' window of VS 2008 SP1. |
How it works
To start writing code with .NET Micro Framework one needs Visual Studio 2008
SP1 or Visual C# 2008 Express Edition plus .NET Micro Framework SDK. Download
the latest version (v3.0) of SDK from http://tinyurl.com/create.php. Once this
SDK is installed it would create new project type and template in VS. Along with
these software components one also needs hardware for which you are writing
embedded code along with SDK. Even if you don't have any hardware you can
install SDK for a particular hardware. The SDKs also include hardware emulators
making it possible to write code for a particular hardware even if you don't
have any hardware with you. To download SDKs for Tahoe board visit http://tinyurl.com/y9vcjeu
and download 'TahoeSDK-20081119.msi' file by clicking on 'Tahoe SDK V3.0' under
'Device Solutions SDK'. In this sample implementation we are using VS 2008 SP1.
Start with creating a new project with 'Project Type' as 'Micro Framework' and
'Template' as 'Windows Application'(MFWindowApplication2). Once you have created
an application, you can run it to get sample output on Windows emulator. Instead
of this output if you want to display your own message on an emulator, replace
the content of your 'Program.cs' file with the following code:
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using
Microsoft.SPOT.Presentation.Media;
using
Microsoft.SPOT.Presentation.Controls;
using MFWindowApplication2;
namespace MFWindowsApplication2
{
public class Program : Application
{
public static void Main()
{
To get output on a particular emulator, right click on 'MFWindowApplication2' in 'Solution Explorer' window and go to properties. Select '.NET Micro Framework.' |
Application myApplication = new
Program();
Window myWindow = new MainWindow();
myApplication.Run(myWindow);
}
}
public class MainWindow : Window
{
public MainWindow()
{
this.Left = 0;
this.Top = 0;
this.Width =
SystemMetrics.ScreenWidth;
this.Height =
SystemMetrics.ScreenHeight;
this.Background = new SolidColorBrush((Color)0x0000FF);
Font F =
Resources.GetFont(Resources.FontResources.small);
UIElement control = new Text(F,"This
is our first .NET Framework Application");
control.HorizontalAlignment =
HorizontalAlignment.Center;
control.VerticalAlignment =
VerticalAlignment.Center;
this.Child = control;
}
}
}
In this sample code we are changing background color of
given display to a different color plus we are writing a custom message at the
center. If you want to use the same application and check the output on
different hardware (Tahoe in our case), simply right click on
'MFWindowApplication2' in the 'Solution Explorer' window and go to properties.
Now select '.NET Micro Framework' from the right column and select 'Emulator'
under 'Transport' and 'TahoeEmulator' under 'Device'. However, if you have the
actual device then simply connect it to your machine and select it from list of
devices.