[#HDI] HowTo: List #HID devices connected in Windows 8.1

Hello!

First the most important thing: I almost forgot to write about this. Windows 8.1 have a new capability that allows us to work with HID devices, so my posts on the USB missile launcher connected to the Kinect or the USB post light notifier, is now much easy.

To have a good start, the first article you should read is this one:

It explains the new capabilities we have in Win8.1 to connect with:

  • 3D printers
  • USB devices
  • Human Interfaces Devices
  • etc.

For this example I’ll go with the capacity to connect with HID. In the following example I’ll show who to create a Win8.1 app wich displays the list of connected HID devices.

1. Create an app Store Windows for Windows 8.1

2. Once created the app, we should define in its manifesto that it will connect with an HID device. Appxmanifiest editor does not support this functionality, so we should edit in text mode. The section that we modify is Capabilities and in this section we define access to HID.

   1: <?xml version="1.0" encoding="utf-8"?>

   2: <Package xmlns="http://schemas.microsoft.com/appx/2010/manifest"

   3:          xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest">

   4: ...

   5: ...

   6:   <Capabilities>

   7:     <Capability Name="internetClient" />

   8:     <m2:DeviceCapability Name="humaninterfacedevice">

   9:       <m2:Device Id="any">

  10:         <m2:Function Type="usage:0001 FFFF"/>

  11:       </m2:Device>

  12:     </m2:DeviceCapability>

  13:   </Capabilities>

  14: </Package>

Important:In the previous example we defined the access to any type of HID (line 10), however if we know the values of Vendor Id and Product ID, we can refine the same as in the following example:

   1: <wb:DeviceCapability Name="humaninterfacedevice">

   2:   <!--Light Sensor Device-->

   3:   <wb:Device Id="vidpid:1294 1320">

   4:     <wb:Function Type="usage:FF55 00A5" />

   5:   </wb:Device>

   6: </wb:DeviceCapability>

In upcoming posts I’ll show you detail for a Lance missile or the notifier light.

4. Once changed the appxmanifiest, we can add a listview and a button to display the connected devices. The following function performs this task.

   1: private async void EnumerateHidDevices()

   2: {

   3:     var deviceSelector = HidDevice.GetDeviceSelector(0xFF00, 0x0001);

   4:     var devices = await DeviceInformation.FindAllAsync(deviceSelector);

   5:

   6:     if (ListViewDevices.Items == null) return;

   7:     ListViewDevices.Items.Clear();

   8:     foreach (var deviceInformation in devices)

   9:     {

  10:         ListViewDevices.Items.Add("Name: " + deviceInformation.Name);

  11:         ListViewDevices.Items.Add("- Id: " + deviceInformation.Id);

  12:         ListViewDevices.Items.Add("- Is Default: " + deviceInformation.IsDefault);

  13:         ListViewDevices.Items.Add("- Is Enabled: " + deviceInformation.IsEnabled);

  14:     }

  15: }

5. If we launch the application, with the USB EMail Notifier (I wrote about this one here), we will see the following output

image

This is the sensor

image

Within the string of results, we can see that the device ID is as follows

  • Vendor Id: 1294
  • Product Id: 1320

We see that they are the same values that gives us the HID.

image

And ready! We can already make a survey for all the devices connected to your computer and in coming posts I will show as you interact with them.

Sources:

Greetings @ Home

El Bruno

imageimageimageGoogle

2 comments

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.