Mercurial > hg > ucis.core
comparison USBLib/Communication/LibUsb0/LibUsb0Registry.cs @ 21:dcfec2be27c9
Added USBLib
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Mon, 15 Apr 2013 01:04:59 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
20:c873e3dd73fe | 21:dcfec2be27c9 |
---|---|
1 using System; | |
2 using System.Collections.Generic; | |
3 using UCIS.HWLib.Windows.Devices; | |
4 | |
5 namespace UCIS.USBLib.Communication.LibUsb { | |
6 public class LibUsb0Registry : WindowsUsbDeviceRegistry, IUsbDeviceRegistry { | |
7 private LibUsb0Registry(DeviceNode device, String interfacepath) : base(device, interfacepath) { } | |
8 public static List<LibUsb0Registry> GetDevicesByInterfaceClass(Guid classGuid) { | |
9 List<LibUsb0Registry> deviceList = new List<LibUsb0Registry>(); | |
10 IList<DeviceNode> usbdevices = DeviceNode.GetDevices(classGuid); | |
11 foreach (DeviceNode device in usbdevices) { | |
12 LibUsb0Registry regInfo = GetDeviceForDeviceNode(device, classGuid); | |
13 if (regInfo != null) deviceList.Add(regInfo); | |
14 } | |
15 return deviceList; | |
16 } | |
17 public static List<LibUsb0Registry> DeviceList { | |
18 get { | |
19 List<LibUsb0Registry> deviceList = new List<LibUsb0Registry>(); | |
20 IList<DeviceNode> usbdevices = DeviceNode.GetDevices("USB"); | |
21 foreach (DeviceNode device in usbdevices) { | |
22 LibUsb0Registry regInfo = GetDeviceForDeviceNode(device); | |
23 if (regInfo == null) continue; | |
24 deviceList.Add(regInfo); | |
25 } | |
26 return deviceList; | |
27 } | |
28 } | |
29 public static List<LibUsb0Registry> FilterDeviceList { | |
30 get { | |
31 return GetDevicesByInterfaceClass(new Guid("{F9F3FF14-AE21-48A0-8A25-8011A7A931D9}")); | |
32 } | |
33 } | |
34 public static LibUsb0Registry GetDeviceForDeviceNode(DeviceNode device, Guid classGuid) { | |
35 String[] iLibUsb = device.GetInterfaces(classGuid); | |
36 if (iLibUsb == null || iLibUsb.Length == 0) return null; | |
37 return new LibUsb0Registry(device, iLibUsb[0]); | |
38 } | |
39 public static LibUsb0Registry GetDeviceForDeviceNode(DeviceNode device) { | |
40 String deviceInterface = null; | |
41 if (deviceInterface == null) { | |
42 String[] interfaces = device.GetInterfaces("{20343A29-6DA1-4DB8-8A3C-16E774057BF5}"); | |
43 if (interfaces != null && interfaces.Length > 0) { | |
44 deviceInterface = interfaces[0]; | |
45 } | |
46 } | |
47 if (deviceInterface == null && device.Service == "libusb0") { | |
48 String[] devInterfaceGuids = device.GetCustomPropertyStringArray("DeviceInterfaceGuids"); | |
49 if (devInterfaceGuids != null && devInterfaceGuids.Length > 0) { | |
50 Guid deviceInterfaceGuid = new Guid(devInterfaceGuids[0]); | |
51 String[] interfaces = device.GetInterfaces(deviceInterfaceGuid); | |
52 if (interfaces != null && interfaces.Length > 0) { | |
53 deviceInterface = interfaces[0]; | |
54 } | |
55 } | |
56 } | |
57 /*if (deviceInterface == null) { | |
58 String[] interfaces = device.GetInterfaces("{F9F3FF14-AE21-48A0-8A25-8011A7A931D9}"); | |
59 if (interfaces != null && interfaces.Length > 0) { | |
60 deviceInterface = interfaces[0]; | |
61 } | |
62 }*/ | |
63 if (deviceInterface == null) return null; | |
64 return new LibUsb0Registry(device, deviceInterface); | |
65 } | |
66 | |
67 public LibUsb0Device Open() { | |
68 return new LibUsb0Device(DevicePath, this); | |
69 } | |
70 IUsbDevice IUsbDeviceRegistry.Open() { | |
71 return Open(); | |
72 } | |
73 } | |
74 } |