comparison USBLib/Communication/WinUsb/WinUsbRegistry.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.WinUsb {
6 public class WinUsbRegistry : WindowsUsbDeviceRegistry, IUsbDeviceRegistry {
7 private WinUsbRegistry(DeviceNode device, String interfacepath) : base(device, interfacepath) { }
8 public IList<Guid> DeviceInterfaceGuids { get; private set; }
9
10 public static List<WinUsbRegistry> DeviceList {
11 get {
12 List<WinUsbRegistry> deviceList = new List<WinUsbRegistry>();
13 IList<DeviceNode> usbdevices = DeviceNode.GetDevices("USB");
14 foreach (DeviceNode device in usbdevices) {
15 WinUsbRegistry regInfo = GetDeviceForDeviceNode(device);
16 if (regInfo != null) deviceList.Add(regInfo);
17 }
18 return deviceList;
19 }
20 }
21 public static WinUsbRegistry GetDeviceForDeviceNode(DeviceNode device) {
22 if (device.Service != "WinUSB") return null;
23 String[] devInterfaceGuids = device.GetCustomPropertyStringArray("DeviceInterfaceGuids");
24 if (devInterfaceGuids == null || devInterfaceGuids.Length < 1) return null;
25 Guid deviceInterfaceGuid = new Guid(devInterfaceGuids[0]);
26 String[] interfaces = device.GetInterfaces(deviceInterfaceGuid);
27 if (interfaces == null || interfaces.Length < 1) return null;
28 WinUsbRegistry regInfo = new WinUsbRegistry(device, interfaces[0]);
29 regInfo.DeviceInterfaceGuids = Array.ConvertAll(devInterfaceGuids, delegate(String g) { return new Guid(g); });
30 return regInfo;
31 }
32
33 public WinUsbDevice Open() {
34 return new WinUsbDevice(DevicePath, this);
35 }
36 IUsbDevice IUsbDeviceRegistry.Open() {
37 return Open();
38 }
39 }
40 }