Example #1
0
        private static UsbDevice FindDeviceByInstanceID(string instanceID, string driveName)
        {
            UsbDevice foundDevice = null;

            foreach (var controller in UsbHost.GetControllers())
            {
                UsbLogic.SearchHubInstanceID(controller.GetRootHub(), ref foundDevice, instanceID, driveName);

                if (foundDevice != null)
                {
                    break;
                }
            }

            return(foundDevice);
        }
Example #2
0
        private static void SearchHubInstanceID(UsbHub hub, ref UsbDevice foundDevice, string instanceID, string driveName)
        {
            foreach (var port in hub.GetPorts())
            {
                if (port.IsHub)
                {
                    UsbLogic.SearchHubInstanceID(port.GetHub(driveName), ref foundDevice, instanceID, driveName);
                }
                else
                {
                    if (port.IsDeviceConnected)
                    {
                        var device = port.GetDevice(driveName);

                        if (device.InstanceID == instanceID)
                        {
                            foundDevice = device;
                            break;
                        }
                    }
                }
            }
        }