Example #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());
        }
Example #2
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();
        }
 private UsbDeviceInterfaceData(IntPtr handle, UsbDeviceWinApi.SP_DEVICE_INTERFACE_DATA deviceInterfaceData)
 {
     this.handle = handle;
     this.deviceInterfaceData = deviceInterfaceData;
 }
        public static UsbDevice GetUsbDevice(IntPtr handle, UsbDeviceWinApi.SP_DEVICE_INTERFACE_DATA deviceInterfaceData)
        {
            UsbDeviceInterfaceData usbDeviceInterface = new UsbDeviceInterfaceData(handle, deviceInterfaceData);

            return(usbDeviceInterface.GetDevice());
        }
 private UsbDeviceInterfaceData(IntPtr handle, UsbDeviceWinApi.SP_DEVICE_INTERFACE_DATA deviceInterfaceData)
 {
     this.handle = handle;
     this.deviceInterfaceData = deviceInterfaceData;
 }