Main Site Documentation

Error on USB Host with USB Keyboard


#1

I’m getting an error when I try to use the UsbHost.KeyboardConnected event.

When I run the code and plug in a keyboard to the usb host I get in the debugger:

Using mainboard GHIElectronics-FEZSpider version 1.0
Program Started

UsbHost ERROR : USB device not supported.

What kind of keyboard does it take?


#2

Maybe the gadgeteer driver doesn’t support keyboards?

Please start new “NETMF console project” (not gadgeteer, no designer) and try this http://wiki.tinyclr.com/index.php?title=USB_Host


#3

Still missing type USBH_Device that I can’t find.

using GHIElectronics.NETMF.USBHost;

Error 5 The type or namespace name ‘USBH_Device’ could not be found (are you missing a using directive or an assembly reference?)


#4

http://www.tinyclr.com/forum/1/3056/


#5

What a concept: Documentation!


#6

Ok, I can make keyboard code work with a NETMF application, but when I try to use the KeyboardConnected event with the .NET Gadgeteer USBHost, I get an exception.

The following output and code from GHI documentation works fine with NETMF:

Hello World!
Device connected…
ID: 2700053376, Interface: 0, Type: 4
Device connected…
ID: 2700053376, Interface: 1, Type: 2
a
s
d
f
j
k
l
;



using System;
using Microsoft.SPOT;
using System.Threading;
using GHIElectronics.NETMF.USBHost;

namespace NETMFKeyboard
{
    public class Program
    {
        static USBH_Keyboard keyboard;

        public static void Main()
        {
            Debug.Print(
                Resources.GetString(Resources.StringResources.String1));

            // Subscribe to USBH events.
            USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;
            USBHostController.DeviceDisconnectedEvent += DeviceDisconnectedEvent;            
 
            // Sleep forever
            Thread.Sleep(Timeout.Infinite);

        }


        static void DeviceConnectedEvent(USBH_Device device)
        {
           Debug.Print("Device connected...");
           Debug.Print("ID: " + device.ID + ", Interface: " +
                   device.INTERFACE_INDEX + ", Type: " + device.TYPE);
           if (device.TYPE == USBH_DeviceType.Keyboard)
           {
               keyboard = device as USBH_Keyboard;
               keyboard.KeyDown += new USBH_KeyboardEventHandler(keyboard_KeyDown);
           }
        }

        static void keyboard_KeyDown(USBH_Keyboard sender, USBH_KeyboardEventArgs args)
        {
            Debug.Print(args.KeyAscii.ToString());
        }
 
        static void DeviceDisconnectedEvent(USBH_Device device)
        {
          Debug.Print("Device disconnected...");
            Debug.Print("ID: " + device.ID + ", Interface: " +
                        device.INTERFACE_INDEX + ", Type: " + device.TYPE);
        }
    }
}



But similar code with .NET Gadgeteer application fails on KeyboardConnected event.

Error:
Using mainboard GHIElectronics-FEZSpider version 1.0
Program Started
UsbHost ERROR : USB device not supported.
The thread ‘’ (0x5) has exited with code 0 (0x0).

Code:


namespace TestKeyboard
{
    public partial class Program
    {
        GHIElectronics.NETMF.USBHost.USBH_Keyboard keyboard;

        void ProgramStarted()
        {
            usbHost.KeyboardConnected += new UsbHost.KeyboardConnectedEventHandler(usbHost_KeyboardConnected);

            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");
        }

        void usbHost_KeyboardConnected(UsbHost sender, GHIElectronics.NETMF.USBHost.USBH_Keyboard Keyboard)
        {
            keyboard = Keyboard;
            keyboard.CharDown += new GHIElectronics.NETMF.USBHost.USBH_KeyboardEventHandler(keyboard_CharDown);
        }

        void keyboard_CharDown(GHIElectronics.NETMF.USBHost.USBH_Keyboard sender, GHIElectronics.NETMF.USBHost.USBH_KeyboardEventArgs args)
        {
            Debug.Print(args.Key.ToString());
        }


    }
}



#7

Interim Solution to KeyboardConnected error USBHost Module: http://wp.me/p1TEdE-by


#8

Looks like you are having fun :slight_smile:

Keep in mind that gadgeteer is few months old and what have is all beta. This will be much better in near future, thanks to GHI’s dedication and community contributions.


#9

No complaints from me. I wouldn’t have figured it out nearly so quickly without the good examples in your documentation.


#10

I am still getting this message…


#11

Does it still fail in Gadgeteer but work in Micro Framework?


#12

I dunno what the difference is…