1

I'm trying to write a simple lightweight app that will tell you if the last connected usb drive was negotiated at usb 3 or usb 2 speeds. So far I have only succeeded to show the last connected drive with Win32_DiskDrive, with some open source code, but I cannot retrieve any information about the device speed that it is running. I found that Win32_USBControllerDevice does have a "negotiatedspeed" property. But I can't find any helpful resources on how to build a console app with that. perhaps someone has a code snippet for me to use? thank you for your help!

Puzis
  • 11
  • 4

1 Answers1

0

I've got a working solution I found here.

USB devices

How it works? Well, it enumerates the USB Host Controllers. gets the Root Hub and enumerates the ports that owns it. If there is a device connected and it's not a hub then it displays the required information as followings:

Example code:

    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( "Name: " + device.Name );
                    Console.WriteLine( "Speed:  " + port.Speed );
                    Console.WriteLine( "Port:   " + device.PortNumber + Environment.NewLine );
                }
            }
        }
        Console.ReadLine();
    }
Sievajet
  • 3,443
  • 2
  • 18
  • 22
  • This is really great, I can at least verify the speeds. Perhaps you could help me out by modifying the code to just show the last connected devices speed? I need this to be a dynamic app – Puzis Jan 03 '15 at 18:02
  • I'm not sure if there is a property that covers that – Sievajet Jan 03 '15 at 18:12
  • this libUsb is giving me some useless results, apart from the port.speed, I cant get the serial number of the device :/ or the drive letter.. any suggestions? – Puzis Jan 03 '15 at 20:55
  • See this thread : http://stackoverflow.com/questions/3331043/get-list-of-connected-usb-devices assuming your looking for a usb drive, you should enumerate through all the drives – Sievajet Jan 03 '15 at 20:57