Mercurial > hg > ucis.core
view USBLib/Communication/USBIO/USBIORegistry.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 | 6fcedb1030bf |
children |
line wrap: on
line source
using System; using System.Collections.Generic; using UCIS.HWLib.Windows.Devices; namespace UCIS.USBLib.Communication.USBIO { public class USBIORegistry : WindowsUsbDeviceRegistry, IUsbDeviceRegistry { public static readonly Guid USBIO_IID = new Guid("{325ddf96-938c-11d3-9e34-0080c82727f4}"); private USBIORegistry(DeviceNode device, String interfacepath) : base(device, interfacepath) { } public static List<USBIORegistry> GetDevicesByInterfaceClass(Guid classGuid) { List<USBIORegistry> deviceList = new List<USBIORegistry>(); IList<DeviceNode> usbdevices = DeviceNode.GetDevices(classGuid); foreach (DeviceNode device in usbdevices) { USBIORegistry regInfo = GetDeviceForDeviceNode(device, classGuid); if (regInfo != null) deviceList.Add(regInfo); } return deviceList; } public static List<USBIORegistry> DeviceList { get { return GetDevicesByInterfaceClass(USBIO_IID); } } public static USBIORegistry GetDeviceForDeviceNode(DeviceNode device, Guid classGuid) { String[] iLibUsb = device.GetInterfaces(classGuid); if (iLibUsb == null || iLibUsb.Length == 0) return null; return new USBIORegistry(device, iLibUsb[0]); } public static USBIORegistry GetDeviceForDeviceNode(DeviceNode device) { return GetDeviceForDeviceNode(device, USBIO_IID); } public IUsbDevice Open() { return new USBIODevice(DevicePath, this); } IUsbDevice IUsbDeviceRegistry.Open() { return Open(); } } }