Communicating with Netduino via USB

On netduino forums you can find information, that SecretLabs team works on 2-way USB communication based on HID implementation, but the work is still in progress. In 4.1.1 beta firmware it basically works, but you need to use serial communication and do „some magic” with external power and USB connection.

Yesterday I found out that reading Debug.Print messages sent from .NET Microframework code running on Netduino is quite simple. It’s only one way (Netduino -> PC), but sometimes it is enough and the solution is very simple.

In your project add reference to MFDeployEngine.dll (usually in C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.1\Tools\ folder). You also need to reference Microsoft.Build.Utilities.v4.0.dll (from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\) and target the code for .NET Framework 4 (not .NET 4 Client Profile).

Here is the code of Windows Form which displays all messages in the textbox:

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.NetMicroFramework.Tools.MFDeployTool.Engine;

namespace WindowsFormsApplication1 {
public partial class Form1 : Form {
public Form1() {

using (MFDeploy mfd = new MFDeploy()) {
IList<MFPortDefinition> portDefs = mfd.EnumPorts(TransportType.USB);
dev = mfd.Connect(portDefs[0]);
dev.OnDebugText += new EventHandler<DebugOutputEventArgs>(dev_OnDebugText);

MFDevice dev;

void dev_OnDebugText(object sender, DebugOutputEventArgs e) {
MethodInvoker action = delegate { textBox1.Text += e.Text; };

private void Form1_FormClosed(object sender, FormClosedEventArgs e) {