USBHostController_DeviceDisconnectedEvent in 4.3?

Migrating from 4.2 to 4.3 i’m able to map:

USBHostController_DeviceConnectedEvent -> Controller_DeviceConnected
USBHostController_DeviceBadConnectionEvent -> Controller_DeviceConnectFailed

but i don’t find a event for: USBHostController_DeviceDisconnectedEvent

How do you handle a USB device that is removed?

Did you find USB_Device? What namespaces are you using? I didn’t find it either.

The 2 events i found in : GHI.Usb.Host.Controller.

Did you find GHI.Usb.Device?

Yes, there is a EventHandler but no Event?

@ David@ Emrol - The Disconnected event is now part of the connected device itself: GHI.Usb.Device.Disconnected.

@ John - How “should” this be used? Not documented yet and 0 results on the forum.

I can start digging but i ported my main project code from 4.2 to 4.3 and have another 280 errors to look at… so if anyone has used this yet :wink:


using System.Threading;
using GHI.Usb.Host;
using GHI.Usb;
using Microsoft.SPOT;


public class Program
{
    static Mouse mouse;

    public static void Main()
    {

        // Subscribe to USBH event.
        Controller.DeviceConnected += Controller_DeviceConnected;

        // Sleep forever
        Thread.Sleep(Timeout.Infinite);
    }

    static void Controller_DeviceConnected(object sender, Controller.DeviceConnectedEventArgs e)
    {
        if (e.Device.Type == Device.DeviceType.Mouse)
        {
            Debug.Print("Mouse Connected");
            mouse = new Mouse(e.Device);
            mouse.CursorMoved += mouse_CursorMoved;
            mouse.ButtonChanged += mouse_ButtonChanged;
        }

    }

    static void mouse_CursorMoved(Mouse sender, Mouse.CursorMovedEventArgs e)
    {
        Debug.Print("(x, y) = (" + e.NewPosition.X + ", " +
                    e.NewPosition.Y + ")");
    }
} 

@ Gus, GHI.USB.Device does not exist. So Device.DeviceType.Mouse does not compile.


using System.Threading;
using GHI.Usb.Host;
using GHI.Usb;
using Microsoft.SPOT;


public class Program
{
    static Mouse mouse;

    public static void Main()
    {

        // Subscribe to USBH event.
        Controller.DeviceConnected += Controller_DeviceConnected;

        // Sleep forever
        Thread.Sleep(Timeout.Infinite);
    }

    static void Controller_DeviceConnected(object sender, Controller.DeviceConnectedEventArgs e)
    {
        if (e.Device.Type == Device.DeviceType.Mouse)
        {
            Debug.Print("Mouse Connected");
            mouse = new Mouse(e.Device);
            mouse.CursorMoved += mouse_CursorMoved;
            mouse.ButtonChanged += mouse_ButtonChanged;
            e.Device.Disconnected += Device_Disconnected;
        }

    }

    static void Device_Disconnected(Device sender, EventArgs e)
    {
        throw new System.NotImplementedException();
    }

    static void mouse_CursorMoved(Mouse sender, Mouse.CursorMovedEventArgs e)
    {
        Debug.Print("(x, y) = (" + e.NewPosition.X + ", " +
                    e.NewPosition.Y + ")");
    }
} 

@ Mr. John Smith - you need both hardware and USB assemblies.

1 Like

@ Gus, sorry it’s in the library GHI.Hardware

@ Gus - Thanks, at first it seems not logical why these where separated but i can see the logic behind it now, thanks again.