Author Topic: Relation between USB devices and SetupAPI info  (Read 12912 times)

moelski

  • Member
  • ***
  • Posts: 12
Relation between USB devices and SetupAPI info
« on: October 21, 2012, 04:22:20 pm »
Hi !

I wrote some code in C# to enumerate all USB & COM Ports via the SetupAPI and the SetupDiGetDeviceRegistryProperty methode.
And I have some code to enumerate the USB Tree.

But how can I makle a relation between these "enumerations"?

Let me explain by an example...
If I plug in a USB / SERIAL adapter I got an ne USB device Entry in the USB Tree. And I can read the device Interface and Device Registry properties with the setupapi calls. But I want to build a USB Tree that contains also some Registry Properties like FriendlyName.

But I canīt find any property which are shared be both enumerations. I thought it could be possible with SPDRP_LOCATION_INFORMATION but this field isnīt populated by all devices.

So could anyone here give me a hint how to get these two enumerations "together"?

Dominik

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Relation between USB devices and SetupAPI info
« Reply #1 on: October 21, 2012, 09:02:39 pm »
Why do you need the information? Maybe there is a different way to do what you need.

moelski

  • Member
  • ***
  • Posts: 12
Re: Relation between USB devices and SetupAPI info
« Reply #2 on: October 22, 2012, 01:53:52 am »
Hi Jan,

I know that this is not neccessary in normal situations.
But Iīm interested if it work in any way.  :)

So if you have any hints for me they are welcome.

Dominik

Tsuneo

  • Frequent Contributor
  • ****
  • Posts: 145
Re: Relation between USB devices and SetupAPI info
« Reply #3 on: October 22, 2012, 05:09:04 am »
Hi moelski,

DevInst (handle to devnode) is the common key of Setup-system and Device Tree (DevInst-system).

On the Setup-system,
- A set of Setup class is made by SetupDiGetClassDevs( DIGCF_ALLCLASSES )
- This set is enumerated by SetupDiEnumDeviceInfo(), which returns PSP_DEVINFO_DATA
- SP_DEVINFO_DATA.DevInst field holds handle to devnode.

Tsuneo

moelski

  • Member
  • ***
  • Posts: 12
Re: Relation between USB devices and SetupAPI info
« Reply #4 on: October 22, 2012, 05:17:04 am »
Hi Tsuneo,

thx for that information.

SP_DEVINFO_DATA.DevInst
This part is done by my implementation ...

But how can I get this information on the Device Tree side ?

Dominik

Tsuneo

  • Frequent Contributor
  • ****
  • Posts: 145
Re: Relation between USB devices and SetupAPI info
« Reply #5 on: October 22, 2012, 07:24:08 am »
Quote
And I have some code to enumerate the USB Tree.
Ah, you are working on a "USB Tree", instead of Device Tree.

Is your code based on USBView example on WDK?
C:\WINDDK\7600.16385.1\src\usb\usbview\

In above example, DriverNameToDeviceDesc() is called by EnumerateHubPorts() in enum.c, to get the description of the target device. DriverNameToDeviceDesc() (devnode.c) traverses Device Tree, and it finds the devInst of the target device. This devInst is the same one as SP_DEVINFO_DATA.DevInst on the Setup-System.

Tsuneo

moelski

  • Member
  • ***
  • Posts: 12
Re: Relation between USB devices and SetupAPI info
« Reply #6 on: October 22, 2012, 07:35:11 am »
Hi !

I use the code from here to get the BUS details:
http://www.emmet-gray.com/Articles/USB_SerialNumbers.htm
Look at the bottom of the page:
"Download the C# Source code for a class-based USB demonstration project:USBView.zip"

Iīm not sure if it bases on the WDK example.

Dominik

Tsuneo

  • Frequent Contributor
  • ****
  • Posts: 145
Re: Relation between USB devices and SetupAPI info
« Reply #7 on: October 22, 2012, 08:55:41 pm »
The method to make "USB Tree" is almost same in both of examples.
But the method to get the description of the target device is different.
WDK USBView example traverses Device Tree, as I briefly explained in above post.
Your reference example traces Setup-system in GetDescriptionByKeyName() (USB.cs).
If you would read other properties from the registry, like FriendlyName, you may apply SetupDiGetDeviceRegistryProperty() to this found SP_DEVINFO_DATA da.

Tsuneo

moelski

  • Member
  • ***
  • Posts: 12
Re: Relation between USB devices and SetupAPI info
« Reply #8 on: October 24, 2012, 09:12:05 am »
Hi !

I think I have a solution.
The relation can be found via the "Driver Key Name".

Dominik