Introduction
.NET is a set of technologies that enable us to build a variety of applications ranging from simple web pages to windows store apps. There is a version of .NET available for almost every platform. While the core .NET framework is huge and demands good enough amount of resources, there is a version of .NET exclusively dedicated for resource constrained devices called the .NET Micro Framework(abbreviated as NETMF). NETMF is an easy choice for embedded developers who are already familiar with C# or Visual Basic .NET programming languages. The development environment for NETMF is the familiar Visual Studio and this allows the existing .NET developers to enhance their skills in embedded programming.
NETMF is an Open Source under Apache 2.0 license and there is no limitation on redistributing the binaries.
We will now look at setting up the development environment for creating NETMF applications and we will also create a very simple application using the NETMF.
Setting up the development environment
One of the key advantages of the NETMF is that the applications can be developed using Visual Studio with NETMF installed. The most stable version of NETMF is ‘.NET MF 4.3 RTM(QEF1)’ and can be downloaded from the below site:
Click on the link under the ‘RECOMMEDED DOWNLOAD’ section. Once the download completes, unzip the files(or double-click the zip file) and locate the MSI file and double click it to launch the installer and follow the onscreen instructions. The install should complete in a couple of minutes.
Please note that this version requires Visual Studio 2012 or Visual Studio 2012 Express for Windows Desktop to be installed. If you do not have the complete version of Visual Studio 2012, download the express version from the below link:
However, the most recent version of NETMF is ‘.NET Micro Framework V4.3 SDK-R2-Beta’ and it includes support for Visual Studio 2013 as well. Please note that this is a Beta version. However, Visual Studio 2013 being the most recent version of the Visual Studio IDE, the announcement of this version of NETMF was more than welcome for thousands of developers who were already using Visual Studio 2013.
The ‘.NET Micro Framework V4.3 SDK-R2-Beta’ version can be downloaded from the below link and we will be using this version for our example in conjunction with Visual Studio 2013(though ‘.NET MF 4.3 RTM(QEF1)’ with Visual Studio 2012 works equally good).
Once again click on the link under the ‘RECOMMEDED DOWNLOAD’ section. Once the download completes, unzip the files(or double-click the zip file) and locate the MSI file and double click it to launch the installer and follow the onscreen instructions.
Note: Inside the ‘netmf-v4.3.2-SDK-R2-Beta’ folder, along with the MSI file, you should also see certain VSIX files. Once the MSI file completes installation, depending on the version of visual studio you have(2012 or 2013), run the corresponding VSIX file by double clicking on it. Please note that the MSI only installs the tools and reference assemblies. Running the corresponding VSIX is essential to install the NETMF extension and to complete the install.
In case you do not have the complete version of Visual Studio 2013, the most recent express version of Visual Studio 2013 can be downloaded from the below link:
Note: Please ensure that you have Visual Studio installed before installing NETMF so that the extensions get added properly.
In case you are curious, the ‘netmf-v4.3.2-SDK-R2-Beta’ also supports the upcoming Visual Studio “14”.You can download the Community Technology Preview(CTP) version of Visual Studio “14” by visiting the below link:
Once you have completed the above steps, you are all set to creating a sample NETMF application as outlined in the next section.
Your first NETMF application
Launch Visual Studio and click on FILE --> New Project to see the below dialog:
Choose the Console Application and click ‘Ok’. A new NETMF application should get created. Open the Solution Explorer and click on Program.cs. The file should look like the below:
Go ahead and press F5. You should see the sample emulator popping up for a few seconds and then, it auto-closes and you should see a ‘Hello World!’ in the output window:
The program just reads the string from the resource file and prints it. Let us add a little bit more of code that simulates switching on an LED:
Open the solution explorer, right click on References and click on ‘Add Reference’.
From the .NET tab, select ‘Microsoft.SPOT.Hardware’ and click ‘OK’:
Now inside the Main() function, remove the existing code and add the below code as shown in the below screen:
OutputPort LED = new OutputPort(Cpu.Pin.GPIO_Pin15, false);
LED.Write(true);
Here, we have created a variable of type OutputPort, instantiated it by passing a port id(GPIO_Pin15) and an initial state(false in this case, which translates to LED off). Then we have changed the state to true(which implies turning on the LED) by using a write function. In an ideal environment, you would replace ‘Cpu.pin.GPIO_Pin15’ with the actual port ID corresponding to the LED of the device. Note that here I have used Pin15, but you can substitute this with any pin of your choice from the list shown in intellisense, except with ‘Cpu.Pin.GPIO_NONE’, in which case the program will throw a run time exception.
You can run the program. As in the previous case, the Sample Emulator comes up for a few seconds and then it auto-closes and the output window shows a small ‘Done.’ message:
Please note that my intent here is to show you how to get started with Visual Studio applications. I have not used any hardware device here. In case you have a NETMF hardware device, you can do a lot more.Two of the prominent hardware manufacturers that sell a variety of hardware devices that run the .NET Micro Framework are GHI Electronics and Secret Labs. You can visit their respective catalogs at https://www.ghielectronics.com/ and http://netduino.com/.
Conclusion
.NET Micro Framework(NETMF) is an open source, highly trimmed down version of the .NET framework exclusively targeted for embedded devices with memory and resource constraints. It combines the tools of desktop development with the innovation of embedded systems. This article is a down to the earth introduction of what NETMF is and how to get started with it targeted for absolute beginners.