public static HIDDevice FindDevice(int nVid, int nPid, Type oType) { string str = $"vid_{nVid:x4}&pid_{nPid:x4}"; Guid hIDGuid = Win32Usb.HIDGuid; IntPtr lpDeviceInfoSet = Win32Usb.SetupDiGetClassDevs(ref hIDGuid, null, IntPtr.Zero, 0x12); try { Win32Usb.DeviceInterfaceData structure = new Win32Usb.DeviceInterfaceData(); structure.Size = Marshal.SizeOf(structure); for (int i = 0; Win32Usb.SetupDiEnumDeviceInterfaces(lpDeviceInfoSet, 0, ref hIDGuid, (uint)i, ref structure); i++) { string devicePath = GetDevicePath(lpDeviceInfoSet, ref structure); if (devicePath.IndexOf(str) >= 0) { HIDDevice device = (HIDDevice)Activator.CreateInstance(oType); device.Initialise(devicePath); return(device); } } } catch (Exception exception) { throw HIDDeviceException.GenerateError(exception.ToString()); } finally { Win32Usb.SetupDiDestroyDeviceInfoList(lpDeviceInfoSet); } return(null); }
// Token: 0x0600002B RID: 43 RVA: 0x00003FA4 File Offset: 0x000021A4 public static HIDDevice FindDevice(int nVid, int nPid, Type oType) { string empty = string.Empty; string value = string.Format("vid_{0:x4}&pid_{1:x4}", nVid, nPid); Guid hidguid = Win32Usb.HIDGuid; IntPtr intPtr = Win32Usb.SetupDiGetClassDevs(ref hidguid, null, IntPtr.Zero, 18u); try { Win32Usb.DeviceInterfaceData deviceInterfaceData = default(Win32Usb.DeviceInterfaceData); deviceInterfaceData.Size = Marshal.SizeOf(deviceInterfaceData); int num = 0; while (Win32Usb.SetupDiEnumDeviceInterfaces(intPtr, 0u, ref hidguid, (uint)num, ref deviceInterfaceData)) { string devicePath = HIDDevice.GetDevicePath(intPtr, ref deviceInterfaceData); if (devicePath.IndexOf(value) >= 0) { HIDDevice hiddevice = (HIDDevice)Activator.CreateInstance(oType); hiddevice.Initialise(devicePath); return(hiddevice); } num++; } } catch (Exception ex) { throw HIDDeviceException.GenerateError(ex.ToString()); } finally { Win32Usb.SetupDiDestroyDeviceInfoList(intPtr); } return(null); }
// Token: 0x0600002A RID: 42 RVA: 0x00003F40 File Offset: 0x00002140 private static string GetDevicePath(IntPtr hInfoSet, ref Win32Usb.DeviceInterfaceData oInterface) { uint nDeviceInterfaceDetailDataSize = 0u; if (!Win32Usb.SetupDiGetDeviceInterfaceDetail(hInfoSet, ref oInterface, IntPtr.Zero, 0u, ref nDeviceInterfaceDetailDataSize, IntPtr.Zero)) { Win32Usb.DeviceInterfaceDetailData deviceInterfaceDetailData = default(Win32Usb.DeviceInterfaceDetailData); deviceInterfaceDetailData.Size = 5; if (Win32Usb.SetupDiGetDeviceInterfaceDetail(hInfoSet, ref oInterface, ref deviceInterfaceDetailData, nDeviceInterfaceDetailDataSize, ref nDeviceInterfaceDetailDataSize, IntPtr.Zero)) { return(deviceInterfaceDetailData.DevicePath); } } return(null); }
private static string GetDevicePath(IntPtr hInfoSet, ref Win32Usb.DeviceInterfaceData oInterface) { uint nRequiredSize = 0; if (!Win32Usb.SetupDiGetDeviceInterfaceDetail(hInfoSet, ref oInterface, IntPtr.Zero, 0, ref nRequiredSize, IntPtr.Zero)) { Win32Usb.DeviceInterfaceDetailData oDetailData = new Win32Usb.DeviceInterfaceDetailData { Size = 5 }; if (Win32Usb.SetupDiGetDeviceInterfaceDetail(hInfoSet, ref oInterface, ref oDetailData, nRequiredSize, ref nRequiredSize, IntPtr.Zero)) { return(oDetailData.DevicePath); } } return(null); }
protected static extern bool SetupDiGetDeviceInterfaceDetail(IntPtr lpDeviceInfoSet, ref Win32Usb.DeviceInterfaceData oInterfaceData, ref Win32Usb.DeviceInterfaceDetailData oDetailData, uint nDeviceInterfaceDetailDataSize, ref uint nRequiredSize, IntPtr lpDeviceInfoData);
protected static extern bool SetupDiEnumDeviceInterfaces(IntPtr lpDeviceInfoSet, uint nDeviceInfoData, ref Guid gClass, uint nIndex, ref Win32Usb.DeviceInterfaceData oInterfaceData);