I have a USB RFID reader. It’s a Prolific chip based device that sends data via serial. When i plug it into Cobra an DeviceConnected event is fired and reader is recognized as Prolific. The problem is when the reader is already pluged in before i power up my Cobra. No DeviceConnected event is fired and GetDevices() method returns empty collection. If i unplug and plug reader back in, everything goes back to normal. How can i fix this ?
using System.Threading;
using GHIElectronics.NETMF.USBHost;
using Microsoft.SPOT;
namespace FEZ_Cobra_Console_Application
{
public class Program
{
public static void Main()
{
Debug.Print("Already connected: " + USBHostController.GetDevices().Length);
USBHostController.DeviceConnectedEvent += d => Debug.Print("Device connected!");
while (true)
{
Thread.Sleep(100);
}
}
}
}
I suppose i can manualy create the USBH_Device object if i know what should be connected to my board. But what if i don’t have that privilage?
Changing your code to Mike’s example should work just fine for you. I start up my Cobra w/ my USB HDD attached all the time and it’s picked up straight away.
Also I see your infinite sleep loop there; if you just want to sleep forever you can call:
Subscribing to DeviceConnected event or pooling GetDevices().Length works in most cases. I started plugging in different USB devices (pen drive, mouse, keyboard, and my problematic RFID reader). I repeated the test described earlier a few times for each device. Only in case of my RFID device (recognized as Serial_FTDI not as Prolific as I previously mentioned) my device was not signaling its presence. The funny thing is - the behavior is random! Doing the same test over and over sometimes the reader IS detected and sometimes it’s not.
I don’t know if I can find any pattern for this behavior to occur…
There is an excellent article that explains some of the USB internals. It is about reverse engineering USB devices and Kinect in particular. Very good read
I’ve been looking at ChipworkX for some time now, comparing it to other similar solutions and I like it the most.
-Any planned promotions in near future for that product?