Main Site Documentation

Error trying to open FTDI USB serial with USB Host module


#1

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;
                }
            }
        }
    }
}


#2

I just checked the Gadgeteer code and found out that the only USB devices that are supported by the USB Host module are mass storage, mouse, keyboard and camera. Serial devices are not supported.

Remove the USB Host module from Gadgeteer designer, and see if that helps.


#3

More info on that device?


#4

Hi,

Thanks for your replies. Removing the host module for the designer got rid of the not supported error message.

However, I have another problem now. The device I’m using (http://www.parallax.com/Portals/0/Downloads/docs/prod/audiovis/28140-28340-RFIDreader-v2.2.pdf) requires that the DTR pin is set to high on its FTDI chip before it will send data. When I connect to it using putty with the following settings all works fine and the DTR pin is high:

Baud rate: 2400
Partity: None
Stop bits: One
Data bits: 8
Flow control: None

However, when I connect using the USB host module it doesn’t work and the DTR pin on the FTDI chip is low (I assume this is the problem. I’ve changed my code to use handshaking, but this doesn’t fix it (I tried all possibilities as well as none.


serial.Handshaking = System.IO.Ports.Handshake.None;
serial.Open();

The device I’m connecting to has an LED that flashes when it is sending data, so I’m pretty sure that the problem is not the module recieving data, but that I’m not able to initiate transmission.

Thanks in advance for any ideas you might have to fix this.


#5

I think you are mixing 2 things, the USB serial and the actual serial. You can’t use the “serial port” class/members/methods with “usb serial”. Also, the USB serial doesn’t support changing modem settings like handshaking.


#6

The code seems to work fine for various serial USB client devices that send data. I guess if changing settings/setting the DTR pin on the FTDI chip isn’t supported then I guess its not going to work either way.


#7

Resolved.

I used a utility to configure the EEPROM of the FTDI chip on the RFID reader to pull DTR high by default. Now I have a gadgeteer RFID reader :-).

Thanks for your help everyone.


#8

@ Jon Hook - Did you write a Gadgeteer/NETMF based class for this reader? I just ordered Adafruit’s NFC board http://www.adafruit.com/products/364, will be doing the same in the near future, and would like to compare notes.


#9

You can’t just tease us like that. We want to see a tutorial and some code, even a video :slight_smile:


#10

That would make a good Gadgeteer module too!


#11

@ architect - my thought exactly. RFID/NFC would be great for any FEZ.


#12

Yep on the list already :slight_smile:


#13

Hi,

Here is a quick tutorial on how to make one :-).

http://di.ncl.ac.uk/gadgeteer/2012/02/08/rfid-reader/

Jon


#14

Nice tutorial! Thank you for sharing!