示例#1
0
        /// <summary>
        ///     private routine for enumerating a hub
        /// </summary>
        /// <param name="hub">Hub</param>
        /// <param name="foundDevice">USB device</param>
        /// <param name="instanceId">Device instance ID</param>
        static void SearchHubInstanceId(UsbHub hub, ref UsbDevice foundDevice, string instanceId)
        {
            foreach (UsbPort port in hub.GetPorts())
            {
                if (port.IsHub)
                {
                    SearchHubInstanceId(port.GetHub(), ref foundDevice, instanceId);
                }
                else
                {
                    if (!port.IsDeviceConnected)
                    {
                        continue;
                    }

                    UsbDevice device = port.GetDevice();
                    if (device.InstanceId != instanceId)
                    {
                        continue;
                    }

                    foundDevice = device;
                    break;
                }
            }
        }
示例#2
0
        /// <summary>
        ///     Finds a device connected to a specified hub by it's DriverKeyName
        /// </summary>
        /// <param name="hub">Hub</param>
        /// <param name="foundDevice">UsbDevice</param>
        /// <param name="driverKeyName">DriverKeyName</param>
        static void SearchHubDriverKeyName(UsbHub hub, ref UsbDevice foundDevice, string driverKeyName)
        {
            foreach (UsbPort port in hub.GetPorts())
            {
                if (port.IsHub)
                {
                    SearchHubDriverKeyName(port.GetHub(), ref foundDevice, driverKeyName);
                }
                else
                {
                    if (!port.IsDeviceConnected)
                    {
                        continue;
                    }

                    UsbDevice device = port.GetDevice();
                    if (device.DeviceDriverKey != driverKeyName)
                    {
                        continue;
                    }

                    foundDevice = device;
                    break;
                }
            }
        }
示例#3
0
 /// <summary>
 ///     private routine for enumerating a hub
 /// </summary>
 /// <param name="hub">Hub</param>
 /// <param name="devList">Device list</param>
 static void ListHub(UsbHub hub, ICollection <UsbDevice> devList)
 {
     foreach (UsbPort port in hub.GetPorts())
     {
         if (port.IsHub)
         {
             ListHub(port.GetHub(), devList);
         }
         else
         {
             if (port.IsDeviceConnected)
             {
                 devList.Add(port.GetDevice());
             }
         }
     }
 }
示例#4
0
 private static IEnumerable <UsbDevice> ListHub(UsbHub hub, string driveName)
 {
     foreach (var port in hub.GetPorts())
     {
         if (port.IsHub)
         {
             foreach (var device in UsbLogic.ListHub(port.GetHub(driveName), driveName))
             {
                 yield return(device);
             }
         }
         else
         {
             if (port.IsDeviceConnected)
             {
                 yield return(port.GetDevice(driveName));
             }
         }
     }
 }
示例#5
0
        private static void SearchHubDriverKeyName(UsbHub hub, ref UsbDevice foundDevice, string driverKeyName, string driveName)
        {
            foreach (var port in hub.GetPorts())
            {
                if (port.IsHub)
                {
                    UsbLogic.SearchHubDriverKeyName(port.GetHub(driveName), ref foundDevice, driverKeyName, driveName);
                }
                else
                {
                    if (port.IsDeviceConnected)
                    {
                        var device = port.GetDevice(driveName);

                        if (device.DriverKey == driverKeyName)
                        {
                            foundDevice = device;
                            break;
                        }
                    }
                }
            }
        }
示例#6
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;
                        }
                    }
                }
            }
        }
示例#7
0
        public static IEnumerable <UsbTreeItem> TextHub(int depth, UsbHub hub)
        {
            foreach (var port in hub.GetPorts())
            {
                yield return(new UsbTreeItem {
                    Depth = depth, Value = $"P-{port?.PortNumber} ({port?.Address})"
                });

                if (port.IsHub)
                {
                    foreach (var item in UsbTreeView.TextHub(depth + 1, port.GetHub(null)))
                    {
                        yield return(item);
                    }
                }
                else
                {
                    foreach (var item in UsbTreeView.TextPort(depth + 1, port))
                    {
                        yield return(item);
                    }
                }
            }
        }