comparison USBLib/Windows/USB/UsbController.cs @ 62:edc41c861d96

Updates and cleanup in Windows USB enumeration code
author Ivo Smits <Ivo@UCIS.nl>
date Sun, 13 Oct 2013 02:47:08 +0200
parents 3424fa5a12c9
children 309c705d7460
comparison
equal deleted inserted replaced
61:2b24666cd759 62:edc41c861d96
4 using UCIS.HWLib.Windows.Devices; 4 using UCIS.HWLib.Windows.Devices;
5 using UCIS.USBLib.Internal.Windows; 5 using UCIS.USBLib.Internal.Windows;
6 6
7 namespace UCIS.HWLib.Windows.USB { 7 namespace UCIS.HWLib.Windows.USB {
8 public class UsbController { 8 public class UsbController {
9 static readonly Guid IID_DEVINTERFACE_USB_CONTROLLER = new Guid(UsbApi.GUID_DEVINTERFACE_HUBCONTROLLER); 9 static readonly Guid IID_DEVINTERFACE_USB_HOST_CONTROLLER = new Guid(UsbApi.GUID_DEVINTERFACE_USB_HOST_CONTROLLER);
10 public String DevicePath { get; private set; } 10 public String DevicePath { get; private set; }
11 public DeviceNode DeviceNode { get; private set; } 11 public DeviceNode DeviceNode { get; private set; }
12 public String DeviceDescription { get { return DeviceNode.DeviceDescription; } } 12 public String DeviceDescription { get { return DeviceNode.DeviceDescription; } }
13 public String DriverKey { get { return DeviceNode.DriverKey; } } 13 public String DriverKey { get { return DeviceNode.DriverKey; } }
14 public UsbHub RootHub { 14 public UsbHub RootHub {
22 this.DeviceNode = di; 22 this.DeviceNode = di;
23 this.DevicePath = devicePath; 23 this.DevicePath = devicePath;
24 } 24 }
25 25
26 public static UsbController GetControllerForDeviceNode(DeviceNode node) { 26 public static UsbController GetControllerForDeviceNode(DeviceNode node) {
27 String[] interfaces = node.GetInterfaces(IID_DEVINTERFACE_USB_CONTROLLER); 27 String[] interfaces = node.GetInterfaces(IID_DEVINTERFACE_USB_HOST_CONTROLLER);
28 if (interfaces == null || interfaces.Length == 0) return null; 28 if (interfaces == null || interfaces.Length == 0) return null;
29 return new UsbController(node, interfaces[0]); 29 return new UsbController(node, interfaces[0]);
30 } 30 }
31 31
32 public static IList<UsbController> GetControllers() { 32 public static IList<UsbController> GetControllers() {
33 IList<UsbController> devices = new List<UsbController>(); 33 IList<UsbController> devices = new List<UsbController>();
34 foreach (DeviceNode dev in DeviceNode.GetDevices(IID_DEVINTERFACE_USB_CONTROLLER)) { 34 foreach (DeviceNode dev in DeviceNode.GetDevices(IID_DEVINTERFACE_USB_HOST_CONTROLLER)) {
35 UsbController controller = GetControllerForDeviceNode(dev); 35 UsbController controller = GetControllerForDeviceNode(dev);
36 if (controller != null) devices.Add(controller); 36 if (controller != null) devices.Add(controller);
37 } 37 }
38 return devices; 38 return devices;
39 } 39 }