如果设备使用USB 3.0检测 [英] Detect if device is using USB 3.0

查看:571
本文介绍了如果设备使用USB 3.0检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道一种方法来检测,如果连接到USB 3.0主机端口USB设备在3.0或2.0使用C#运行?

Does anyone know a way to detect if a USB device connected to a USB 3.0 host port is running at 3.0 or 2.0 using C#?

我们正在制造的USB 3.0延长线,我们需要确认所有的引脚都被正确焊接。我们想做到这一点的软件。我们想一个3.0拇指驱动器连接到电缆,并检查设备在USB 3.0模式下工作。如果是在2.0模式,我们知道其是被1或多个USB 3.0线的问题。

We are manufacturing USB 3.0 extension cables and we need to verify that all the pins have been soldered correctly. We would like to do this in software. We would like to connect a 3.0 thumb drive to the cable and check if the device is operating in USB 3.0 mode. If it is in 2.0 mode, we know their is a problem with 1 or more of the USB 3.0 lines.

推荐答案

我已经成功地煮了工作演示与某些源$ C ​​$ C I <一的帮助href="http://read.pudn.com/downloads105/source$c$c/windows/vxd/432626/USBLib/USB.cs__.htm">found.

I've managed to cook up a working demo with the help of some source code I found.

private static void Main(string[] args)
{
  var hostCtrls = USB.GetHostControllers();

  foreach (var hostCtrl in hostCtrls)
  {
    var hub = hostCtrl.GetRootHub();
    foreach (var port in hub.GetPorts())
    {
      if (port.IsDeviceConnected && !port.IsHub)
      {
        var device = port.GetDevice();
        Console.WriteLine("Serial: " + device.DeviceSerialNumber);
        Console.WriteLine("Speed:  " + port.Speed);
        Console.WriteLine("Port:   " + device.PortNumber + Environment.NewLine);
      }
    }
  }
}

应用程序枚举通用串行总线控制器。然后,它得到了根集线器和enumarates属于它的端口。如果连接的设备,它不是一个集线器,然后它会显示所需的信息。

The application enumerates the USB Host Controllers. Then it gets the Root Hub and enumarates the ports belonging to it. If there is a device connected and it's not a hub then it displays the required information.

在你的情况,你可能知道你要来检查,所以你可以修改源(两个以上,以及相关的code)专门只检查设备。该设备

In your case you probably know which device you want to check so you can modify the source (both the above and the linked code) to specifically check only that device.

您需要创建在USB类中的方法通过指定端口号和路径集线器从一个特定的集线器的特定端口。

You'll need to create a method in the USB class to get a specific port from a specific hub by specifying port number and the path to the hub.

是这样的:

GetDeviceSpeed(string hubPath, int portNumber) { ... }

和用适当的值调用它:

and the call it with the appropriate values:

var hubPath = @"\\.\NUSB3#ROOT_HUB30#5&b235176&0#{f18a0e88-c30c-11d0-8815-00a0c906bed8}";
var portNumber = 2;
GetDeviceSpeed(hubPath, portNumber);

如果你不过是不愿意这样做,那么你可以简单地使用上面的code,使设备要测试,只检查的速度,然后在序列号通知:

If you however are reluctant to do this then you can simply use the above code and make notice of the serial number of the device you want to test and only check the speed then:

if (device.DeviceSerialNumber == "xxxxxx")
  Console.WriteLine("Speed:  " + port.Speed);

如果你使用这个结合GUI应用程序,你可以只选择你要检查在下拉设备。

If you are to use this in an application with a GUI you could just select the device you want to check in a dropdown.

嗯...有一些想法,希望一个可行的解决方案。

Well... There are some thoughts and hopefully a working solution.

这篇关于如果设备使用USB 3.0检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆