Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Obtaining USB HID device information

Obtaining USB HID device information

Scheduled Pinned Locked Moved C#
csharpc++databasequestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Leif Simon Goodwin
    wrote on last edited by
    #1

    I have a need to retrieve a list of attached USB HID devices and query their details to populate a list. .Net makes it easy to get a list of devices: ManagementObjectCollection collection; using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_PnPEntity Where PNPDeviceID like 'HID%'")) { collection = searcher.Get(); } I can then iterate over the items in the collection and query the properties. Unfortunately the properties do not include the device friendly name e.g. "Big Image Inc Reader". Is there a native .Net way to get properties such as the friendly name? I have code that can do this in C++ using DeviceIOControl etc, and it might be that the best approach is to write a non managed C++ wrapper class and invoke it from C#. But native code woud be 'cleaner'.

    G G 2 Replies Last reply
    0
    • L Leif Simon Goodwin

      I have a need to retrieve a list of attached USB HID devices and query their details to populate a list. .Net makes it easy to get a list of devices: ManagementObjectCollection collection; using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_PnPEntity Where PNPDeviceID like 'HID%'")) { collection = searcher.Get(); } I can then iterate over the items in the collection and query the properties. Unfortunately the properties do not include the device friendly name e.g. "Big Image Inc Reader". Is there a native .Net way to get properties such as the friendly name? I have code that can do this in C++ using DeviceIOControl etc, and it might be that the best approach is to write a non managed C++ wrapper class and invoke it from C#. But native code woud be 'cleaner'.

      G Offline
      G Offline
      Garth J Lancaster
      wrote on last edited by
      #2

      since WMI doesnt provide what you wish, I think you're stuck with the 'wrapper class' or P/Invoke methodology - two things that may provide inspiration are :- Simple HID Library - Home[^] and HIDSharp[^]

      L 1 Reply Last reply
      0
      • L Leif Simon Goodwin

        I have a need to retrieve a list of attached USB HID devices and query their details to populate a list. .Net makes it easy to get a list of devices: ManagementObjectCollection collection; using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_PnPEntity Where PNPDeviceID like 'HID%'")) { collection = searcher.Get(); } I can then iterate over the items in the collection and query the properties. Unfortunately the properties do not include the device friendly name e.g. "Big Image Inc Reader". Is there a native .Net way to get properties such as the friendly name? I have code that can do this in C++ using DeviceIOControl etc, and it might be that the best approach is to write a non managed C++ wrapper class and invoke it from C#. But native code woud be 'cleaner'.

        G Offline
        G Offline
        GrooverFromHolland
        wrote on last edited by
        #3

        This is how I get the friendly name of my USB serial devices. The friendly name is in the caption of the management objects. I get them like this:

        List<string> usbSerial = new List<string>();
        List<ManagementObject> listObj = new List<ManagementObject>();
        try
        {
        string query = "SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0";
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
        listObj = searcher.Get().Cast<ManagementObject>().ToList();
        searcher.Dispose();
        }
        catch (Exception ex)
        {
        MessageBox.Show(ex.ToString());
        usbSerial = new List<string>();
        }
        foreach (ManagementObject obj in listObj)
        {
        object captionObj = obj["Caption"]; //This will get you the friendly name.
        if (captionObj != null)
        {
        string caption = captionObj.ToString();
        if (caption.Contains("(COM")) //This is where I filter on COM-ports.
        {
        usbSerial.Add(caption);
        }

                   }
               }
               usbDevices = usbSerial.Distinct().OrderBy(s => s).ToArray();
        

        Hope this can help, Groover

        0200 A9 23 0202 8D 01 80 0205 00

        1 Reply Last reply
        0
        • G Garth J Lancaster

          since WMI doesnt provide what you wish, I think you're stuck with the 'wrapper class' or P/Invoke methodology - two things that may provide inspiration are :- Simple HID Library - Home[^] and HIDSharp[^]

          L Offline
          L Offline
          Leif Simon Goodwin
          wrote on last edited by
          #4

          Thanks Garth, and sorry to reply so late. The HIDSharp may well be the answer although I have written most of a COM wrapper anyway.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups