Hi,
I’m trying to read from a USB (FTDI/FT232RL) serial client device (a Parallax RFID reader) using the USB Host module. I’ve modified some of the tutorial code to do this, but I am getting an error “UsbHost ERROR : USB device not supported” when the device is connected.
This code breaks in the same way when using multiple different FTDI USB serial devices and works with another USB serial device that doens’t use an FTDI chip.
Does anyone have an idea what the problem might be?
Cheers,
Jon
using System;
using Microsoft.SPOT;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using GHIElectronics.NETMF.USBHost;
using System.Threading;
namespace DigitalOriginalsGadgeteer
{
public class ParallaxRFIDReader
{
private const int BAUD_RATE = 2400;
private const System.IO.Ports.Parity PARITY = System.IO.Ports.Parity.None;
private const System.IO.Ports.StopBits STOP_BITS = System.IO.Ports.StopBits.One;
private const int DATA_BITS = 8;
private const byte START_BYTE = 0x0A;
private const byte STOP_BYTE = 0x0D;
public delegate void TagReadEventHandler(object sender, string id);
public event TagReadEventHandler TagRead;
private string currentId;
private USBH_SerialUSB serial;
public ParallaxRFIDReader()
{
USBHostController.DeviceConnectedEvent += new USBH_DeviceConnectionEventHandler(USBHostController_DeviceConnectedEvent);
}
private void USBHostController_DeviceConnectedEvent(USBH_Device device)
{
if(device.TYPE == USBH_DeviceType.Serial_FTDI)
{
serial = new USBH_SerialUSB(device, BAUD_RATE, PARITY, DATA_BITS, STOP_BITS);
serial.ReadTimeout = 9999;
serial.Open();
Thread t = new Thread(() =>
{
while(true)
{
ReadData();
Thread.Sleep(100);
}
});
t.Start();
}
}
private void ReadData()
{
byte[] buffer = new byte[1];
serial.Read(buffer, 0, 1);
foreach (byte b in buffer)
{
if (b == START_BYTE)
{
currentId = "";
}
else if (b == STOP_BYTE && TagRead != null)
{
TagRead(this, currentId);
}
else
{
currentId += b;
}
}
}
}
}