Project - Example NETMF USB app with a simple WinUSB client and instructions on building the required driver

I just posted Example NETMF USB app with a simple WinUSB client and instructions on building the required driver. on Codeshare. Feel free to discuss and make suggestions here.


@ untitled - Wow, this looks really useful. Will it run on Cerb Family devices?

It should run on any NETMF board that supports Microsoft.SPOT.Hardware.Usb …I suppose your board also needs free endpoints, etc. But basically, if you debug via USB I think this code will work on your board.

On the PC side, it should run on XP - Windows 8.

I made this example in a rush. In a perfect world everyone would simplify it a little bit more and pretty soon we’d have something ridiculously useful.

I plan on adding a ClickOnce installer that deploys the driver automatically.

I have tried implementing this on my unit. So I use the USB to debug through Visual studio. I deploy my application which has your USB Device class implement. At start up, I do what you have done in your example of creating another thread for the usb and I init the USB. But it fails to stop the USB controller used for the debugger and therefore it can not use that USB controller for communication. Essentially it doesn’t find a free USB controller.

Am I doing something wrong?

@ Greg_ZANewbie

I think you should enable another USB port on firmware level.

Download the Microsoft USB Device Viewer (USBView) so you can see what’s going on. That comes with the Windows Driver Kit but that’s a huge download. FTDI has it as a tiny separate download on this page… Utilities - FTDI

With USBView running, try this…

  1. Deploy to the device.
  2. Unplug the device and plug it back in.

In USBView you should first see the device as it normally appears. After a few moments (because of that Sleep command) that device should disappear and a new device with your config should appear.

To deploy again keep the device unplugged. Hit Deploy in VS and wait until it is trying to connect to the device. Then plug the device in and it will connect & deploy.

Which board?

You shouldn’t have to do this. In the device’s USB.cs there is an Init method. This method Stops the controller that’s normally used for debugging and then re-configures it for your own use.

My point was to enable another USB port, you have to recompile firmware.
Otherwise you will not able to debug you application.

That makes sense. But the point of my codeshare post was that this technique allows you to use the USB feature without updating the firmware.

couldn’t use the code below instead of the sleep directly?

if (System.Diagnostics.Debugger.IsAttached)
                 Debug.Print("I'm attached to a debugger");

or does that flag get set after deployment?

Yes, this is how it SHOULD work. I tried this first. The problem is that System.Diagnostics.Debugger.IsAttached only returns true if VS is connected. So after you reboot (remove/re-attach) your device it won’t see VS and won’t pause. You need that pause so you can connect VS (erase the firmware from MFDeploy, etc).

@ untitled - Thanks for sharing this code.

I’m trying to deploy this sample on Cerberus board with no lucky.
May be usefully to know what hardware are you using, in netmf 4.2 “” the ‘UsbController.GetController(0).Stop()’ is not working, because after running the ‘stop’ the controller still ‘running’ and always get :

“All available USB controllers already in use. Set the device to use Ethernet or Serial debugging”

Any idea?

Tried using just the USB Device project from this code share on a G400-D hardware and the 2015 Pre-Release 2 SDK.

I was getting an exception thrown by usbController.CreateUsbStream(usbController);
The Windows host just using Device Manger (no host side software running) would list the G400-D as Unknown or Get Device Descriptors failed.

I make a few changes to prevent some exceptions.

The first one is to change ConfigureUSBController(usbController) to pass by reference ConfigureUSBController(ref usbController) and the definition ConfigureUSBController(ref UsbController USBusbController);

Now the usbController.CreateUsbStream(WRITE_EP, READ_EP); has the updated usbController information from the configuration method.

Next I found the usbStream.WriteTimout(60000); and usbStream.ReadTimeout(60000); both throw an exception.
So place those statements inside a conditional test of if the controller can support timeouts:

if (usbController.CanTimeout)

So now I have prevented exceptions from occurring but I still see an Unknown USB Device in the Windows Device Manager.

This is as far as I can take it at this point, hope this saves someone so time to bring up this code share project.