Using USB Host

Hi,

I want to use the USB Host feature of my FEZ Domino for USB debugging.
I want to list all configuration, interfaces and endpoint of the connected USB device. I done most of the work but I didn’t found how to get the string descriptors (like the Manufacturer string etc)

exemple : I can get iInterface (the id of the string descriptor with the interface name), but I couldn’t find a GetStringDescriptor method, and the auxiliaryDescriptors array is empty…

Is there a way to do that?

In case you don’t know we have something that might help on Fezzer:
http://www.fezzer.com/project/164/usb-discovery-helper/

Thanks, I didn’t know about this helper, I wrote my own, but like mine, this one do not get string descriptors…

Is there a way to get them?

Anything is possible with FEZ :wink:
Try this:

using System;
using System.Text;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.USBHost;

namespace MFConsoleApplication1
{
    public class Program
    {
        public static void Main()
        {
            USBHostController.DeviceConnectedEvent += new USBH_DeviceConnectionEventHandler(USBHostController_DeviceConnectedEvent);
            USBHostController.DeviceDisconnectedEvent += new USBH_DeviceConnectionEventHandler(USBHostController_DeviceDisconnectedEvent);

            Thread.Sleep(Timeout.Infinite);
        }

        static void USBHostController_DeviceDisconnectedEvent(USBH_Device device)
        {
            Debug.Print("Device disconnected. ID: " + device.ID);
        }

        static void USBHostController_DeviceConnectedEvent(USBH_Device device)
        {
            Debug.Print("Device connected. ID: " + device.ID);

            USBH_RawDevice rawDevice = new USBH_RawDevice(device);

            // contains some strings indices
            USBH_Descriptors.Device dd = rawDevice.GetDeviceDescriptor();

            Debug.Print("Manufacturer: " + GetUSBString(rawDevice, dd.iManufacturer));
            Debug.Print("Product: " + GetUSBString(rawDevice, dd.iProduct));
            Debug.Print("Serial Number: " + GetUSBString(rawDevice, dd.iSerialNumber));
        }

        static string GetUSBString(USBH_RawDevice rawDevice, byte stringIndex)
        {
            if (stringIndex == 0)
                return "";

            try
            {
                byte[] temp = new byte[1];

                // read string size first
                rawDevice.SendSetupTransfer(0x80, 0x06, (ushort)(0x0300 | stringIndex), 0x0409 /*English*/, temp, 0, temp.Length);

                // allocate new size
                temp = new byte[temp[0]];

                // read string
                rawDevice.SendSetupTransfer(0x80, 0x06, (ushort)(0x0300 | stringIndex), 0x0409 /*English*/, temp, 0, temp.Length);

                // convert to ascii. skip first two bytes.
                char[] stringChars = new char[(temp.Length - 2) / 2];
                for (int i = 0; i < stringChars.Length; i++)
                {
                    stringChars[i] = (char)temp[2 + i * 2];
                }

                return new string(stringChars);
            }
            catch
            {
                return "";
            }
        }

    }
}

Thanks!

It’s exacly what I need ^^

I’m a noob in USB (started a week ago) and I never knew I could get them with low-level command like SendSetupTransfer()

Is something like this to be implemented in future versions of the GHI SDK?

PS. Sorry for my bad english…