35
|
1 using System; |
|
2 using System.Collections.Generic; |
|
3 using UCIS.HWLib.Windows.Devices; |
|
4 |
|
5 namespace UCIS.USBLib.Communication.USBIO { |
|
6 public class USBIORegistry : WindowsUsbDeviceRegistry, IUsbDeviceRegistry { |
|
7 public static readonly Guid USBIO_IID = new Guid("{325ddf96-938c-11d3-9e34-0080c82727f4}"); |
|
8 private USBIORegistry(DeviceNode device, String interfacepath) : base(device, interfacepath) { } |
|
9 public static List<USBIORegistry> GetDevicesByInterfaceClass(Guid classGuid) { |
|
10 List<USBIORegistry> deviceList = new List<USBIORegistry>(); |
|
11 IList<DeviceNode> usbdevices = DeviceNode.GetDevices(classGuid); |
|
12 foreach (DeviceNode device in usbdevices) { |
|
13 USBIORegistry regInfo = GetDeviceForDeviceNode(device, classGuid); |
|
14 if (regInfo != null) deviceList.Add(regInfo); |
|
15 } |
|
16 return deviceList; |
|
17 } |
|
18 public static List<USBIORegistry> DeviceList { |
|
19 get { return GetDevicesByInterfaceClass(USBIO_IID); } |
|
20 } |
|
21 public static USBIORegistry GetDeviceForDeviceNode(DeviceNode device, Guid classGuid) { |
|
22 String[] iLibUsb = device.GetInterfaces(classGuid); |
|
23 if (iLibUsb == null || iLibUsb.Length == 0) return null; |
|
24 return new USBIORegistry(device, iLibUsb[0]); |
|
25 } |
|
26 public static USBIORegistry GetDeviceForDeviceNode(DeviceNode device) { |
|
27 return GetDeviceForDeviceNode(device, USBIO_IID); |
|
28 } |
|
29 |
|
30 public IUsbDevice Open() { |
|
31 return new USBIODevice(DevicePath, this); |
|
32 } |
|
33 IUsbDevice IUsbDeviceRegistry.Open() { |
|
34 return Open(); |
|
35 } |
|
36 } |
|
37 } |