This blog discusses a UWP (Universal) app that enumerates the drivers on a Windows 10 system (including IoT). Its like the Windows Device Manager app. Full source code is available.

In the  previous blog, Win 10-IoT: Raspberry Pi 2 Peripherals - Connected Devices, various methods were discussed as to how to determine the drivers that are loaded on a Windows 10 Raspberry Pi 2 (and should apply to a MinnowMax Board). Here we look at some C# code to list all Device Interfaces (aka drivers).

The Code:

  • The project is available for download from Github: WindowsDevices. Its the DeviceWatcher app in that repository.

The App UI:

image

Sample Output:

image

A Device Id string:

image

A Parsed Id:

image


Background

state diagram of DeviceWatcher states

The App State Machine, reproduced from the MSDN link above.

Watcher Class

Class: Windows.Devices.Enumeration.Watcher

  • Methods: Start, Stop
  • Events:
Event Description
Added Event that is raised
when a device is added to the collection enumerated by the DeviceWatcher.
Enumeration Completed when the enumeration of devices completes..
Removed when a device is removed from the collection of enumerated devices.
Stopped when the enumeration operation has been stopped.
Updated when a device is updated in the collection of enumerated devices.

Watcher Events


Watcher generates a list of Windows.Devices.Enumeration.DeviceInformation :

 

Property Description
Name Read-Only The name of the device.
Id Read-Only A string representing the identity of the device.
Kind Read-Only Gets the type of DeviceInformation represented by this object. Always get DeviceInterface
IsEnabled Read-Only Indicates whether this device is enabled.

Key DeviceInformation Class Properties

Code Improvements from MSDN Version

  • Whereas the MSDN version iterates through the DeviceInterfaces returned by the Watcher and “manually” generates the displayed list, this version uses Xaml Data Binding to automatically do this.
  • Various filters are part of the UI:
    image
  • A count of the devices is shown
  • The list can be sorted on the device name.

App Usage

  • Set the target CPU (x86/64) for desktop or ARM for IoT(and Phone).
    Set the target device
      • Build and run the app.
      • Press start to do a full enumeration.
      • A list of device interfaces will show.
      • Scroll through the list and select a device, its name and aspects of its Id string are parsed are displayed at the top.
      • Apply the USB filter only, stop and start the Watcher,
        Plug and unplug a USB (say) keyboard
        into the device and see that the list is automatically updated.
      • Select filters (as follows), Stop the Watcher and Start it again

Filters

  • To display just the connected USB devices (focus of the previous blog), click on USB.
    This queries in the Device Names of the returned list of Device Interfaces.
  • Alternatively, select from a wider list of device types by checking Select and choosing from the dropdown menu.
    This queries at the first part of the Device Id.
    This menu is only populated after the first enumeration run.
    USB selected will override this (ToDo: Should change to a Radio buttons).
  • Can further Filter on name:
    - Select only if name includes ..
    - Do not select if name includes …
    This later one is useful for remove system device names. Use all or part of the target device’s name.
  • Can further filter on the Id string.

Notes

  • The app enumeration is slower than the MSDN version as it does some Linq querying to generate the Selection list and to apply the filters.
  • The Xaml code needs to reworking (not functionally, just its layout)
    Functional suggestions are welcome though. Please leave a comment.
  • A number of device interfaces are listed for any one device. For example plugging in a USB keyboard can add 4 interfaces.
    It would be nice to merge these interfaces down to one listing per device,

The Take Home

This app can list USB and other devices on the desktop and an IoT device running Windows 10.