Пример #1
0
        public UsbDevice[] GetDevices()
        {
            UInt32 index = 0;

            List <UsbDevice> devices = new List <UsbDevice>();

            while (true)
            {
                UsbDeviceWinApi.SP_DEVICE_INTERFACE_DATA deviceInterfaceData = new UsbDeviceWinApi.SP_DEVICE_INTERFACE_DATA();
                deviceInterfaceData.Size = (UInt32)Marshal.SizeOf(deviceInterfaceData);

                Boolean success = UsbDeviceWinApi.SetupDiEnumDeviceInterfaces(this.handle, IntPtr.Zero, ref this.classGuid, index, ref deviceInterfaceData);

                if (!success)
                {
                    if (UsbDeviceWinApi.ERROR_NO_MORE_ITEMS == Marshal.GetLastWin32Error())
                    {
                        break;
                    }

                    this.TraceError("SetupDiEnumDeviceInterfaces");
                }

                index++;

                devices.Add(UsbDeviceInterfaceData.GetUsbDevice(this.handle, deviceInterfaceData));
            }

            return(devices.ToArray());
        }
 public static UsbDevice GetUsbDevice(IntPtr handle, UsbDeviceWinApi.SP_DEVICE_INTERFACE_DATA deviceInterfaceData)
 {
     UsbDeviceInterfaceData usbDeviceInterface = new UsbDeviceInterfaceData(handle, deviceInterfaceData);
     return usbDeviceInterface.GetDevice();
 }
        public static UsbDevice GetUsbDevice(IntPtr handle, UsbDeviceWinApi.SP_DEVICE_INTERFACE_DATA deviceInterfaceData)
        {
            UsbDeviceInterfaceData usbDeviceInterface = new UsbDeviceInterfaceData(handle, deviceInterfaceData);

            return(usbDeviceInterface.GetDevice());
        }