UsbTreeView : View Usb devices and hubs they are in in a user friendly form


I have many Usb devices in my home automation system. They have to be in Usb hubs, and some have long active Usb cables which means they get their power from Usb power lines and behave like hubs.

How Usb devices show in Windows device manager is not particularly user friend because for instance I have several Usb-to-serial-converters and all of them are based on FTDI chipsets. Even some "normal" Usb devices show as FTDI Usb-to-serial-converters because they have that same chipset inside them. So all these FTDI devices show in Windows device manager as FTDI USB2Serial converters and it always takes some time to figure out which device is connected to where.

It's also important to know which device is on which hub because there may be situations where Usb devices take too much Usb power or bandwitdh. Then you have to see your Usb device tree so you can figure out how to divide your devices into hubs.

I thought it would be easy to get information of Usb devices and their hubs because a lot of that information can be found at WMI. But it turned out that you cannot get information about the connections because Microsoft wants that information to be hidden : "it's not important in which hub the devices are connected". That might work in a virtual world but in real world I've run into situations that Usb devices take to much power. There are no warnings about that. Some devices just stopped working properly.

Only way to get the child-parent-connection information would be to to go to driver level. Luckily I found a simple program from Github that does that:
https://github.com/mkielar/get-parent-device
There was no release, so I compiled the code with SharpDevelop and release also the compiled exe with this script.

Then I created Powershell script that enumerates all Usb devices, builds the tree view and shows the friendly name of the Usb device if you have given it one.

Most of my Usb devices have a serial number. It means that if I move that device from one hub to another, Windows recognizes it as the same device and they will have same DeviceId. But some devices don't have unique serial numbers. My Usb hubs and active Usb cables are like that. If I move them to another hub, they will have different DeviceId's.

The friendly name list is in file UsbDeviceNames.ps1
It's a Powershell hash array:
$OwnUsbDeviceNames = @{
"USB\VID_04E5&PID_0605\6&13F4C3E&0&6"    = "Hama 4port passive USB hub ( the grey one)";
"USB\VID_1A40&PID_0101\6&DF2EE03&0&5"    = "Deltaco Active Usb 2.0 cable";
"USB\VID_1A40&PID_0101\7&19BC4090&0&1"    = "Delock USB2.0 4port active mini hub (the black round one)";
"USB\VID_0403&PID_6001\FTFSDFHD"        = "FTDI Serial (COM5) to projector";
"USB\VID_0403&PID_6001\FTFXXLHS"        = "FTDI Serial (COM8) to tv";
"Something" = "is nothing"
}
When you first run the UsbTreeView you only see the devices generic names and DeviceId's.
When you know which DeviceId is which device, you can add those to hash array like I did. Normally for instance active Usb cables show as hubs but it's easier to see in Usb tree the device is not actually a hub but just a long cable. It's also easier to see which FTDI converter goes to which device instead of remembering COM port numbers. Point is with this software you can name the devices the way you like and the way you remember them better.

You can attach friendly names to DeviceId's so devices that stick with their DeviceId's also keep their friendly names but for other devices without serial numbers you have to change the DeviceId attached to friendly name every time you move that device in Usb device tree.


BTW, in my Usb tree there are 44 devices. So there's a reason why I wrote this.

The code is in GitHub:
https://github.com/MarkoMarjamaa/UsbTreeView

Comments