HidDevice HidDevice HidDevice HidDevice HidDevice Class

Definition

Represents a top-level collection and the corresponding device.

public : sealed class HidDevice : IHidDevice, IClosable
struct winrt::Windows::Devices::HumanInterfaceDevice::HidDevice : IHidDevice, IClosable
public sealed class HidDevice : IHidDevice, IDisposable
Public NotInheritable Class HidDevice Implements IHidDevice, IDisposable
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

The following example demonstrates how a UWP app built with XAML and C# uses the GetDeviceSelector method to create a selector for a specific HID device and then uses** FromIdAsync** method to open a connection to that device.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Windows.Devices.Enumeration;
using Windows.Devices.HumanInterfaceDevice;
using Windows.Storage;
using Windows.Storage.Streams;

namespace HidSampleCS
{
    class Enumeration
    {
        // Enumerate HID devices
        private async void EnumerateHidDevices()
        {
            UInt32 vendorId = 0x045E;
            UInt32 productId = 0x078F;
            UInt32 usagePage = 0xFF00;
            UInt32 usageId = 0x0001;

            // Create a selector that gets a HID device using VID/PID and a 
            // VendorDefined usage
            string selector = HidDevice.GetDeviceSelector(usagePage, usageId, 
                              vendorId, productId);

            // Enumerate devices using the selector
            var devices = await DeviceInformation.FindAllAsync(selector);

            if (devices.Count > 0)
            {
                // Open the target HID device
                HidDevice device = await HidDevice.FromIdAsync(devices.ElementAt(0).Id, 
                                   FileAccessMode.ReadWrite);

                // At this point the device is available to communicate with
                // So we can send/receive HID reports from it or 
                // query it for control descriptions
            }
            else
            {
                // There were no HID devices that met the selector criteria
                this.NotifyUser("MUTT HID device not found");
            }
        }
    }
}

Properties

ProductId ProductId ProductId ProductId ProductId

Gets the product identifier for the given HID device.

UsageId UsageId UsageId UsageId UsageId

Gets the usage identifier for the given HID device.

UsagePage UsagePage UsagePage UsagePage UsagePage

Gets the usage page of the top-level collection.

VendorId VendorId VendorId VendorId VendorId

Gets the vendor identifier for the given HID device.

Version Version Version Version Version

Gets the version, or revision, number for the given HID device.

Methods

Close() Close() Close() Close() Close()

Closes the connection between the host and the given HID device.

CreateFeatureReport() CreateFeatureReport() CreateFeatureReport() CreateFeatureReport() CreateFeatureReport()

Creates the only, or default, feature report that the host will send to the device.

CreateFeatureReport(UInt16) CreateFeatureReport(UInt16) CreateFeatureReport(UInt16) CreateFeatureReport(UInt16) CreateFeatureReport(UInt16)

Creates a feature report, identified by the reportId parameter, that the host will send to the device.

CreateOutputReport() CreateOutputReport() CreateOutputReport() CreateOutputReport() CreateOutputReport()

Creates the only, or default, output report that the host will send to the device.

CreateOutputReport(UInt16) CreateOutputReport(UInt16) CreateOutputReport(UInt16) CreateOutputReport(UInt16) CreateOutputReport(UInt16)

Creates an output report, identified by the reportId parameter, that the host will send to the device.

Dispose() Dispose() Dispose() Dispose() Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

FromIdAsync(String, FileAccessMode) FromIdAsync(String, FileAccessMode) FromIdAsync(String, FileAccessMode) FromIdAsync(String, FileAccessMode) FromIdAsync(String, FileAccessMode)

Opens a handle to the device identified by the deviceId parameter. The access type is specified by the accessMode parameter.

GetBooleanControlDescriptions(HidReportType, UInt16, UInt16) GetBooleanControlDescriptions(HidReportType, UInt16, UInt16) GetBooleanControlDescriptions(HidReportType, UInt16, UInt16) GetBooleanControlDescriptions(HidReportType, UInt16, UInt16) GetBooleanControlDescriptions(HidReportType, UInt16, UInt16)

Retrieves the descriptions of the boolean controls for the given HID device.

GetDeviceSelector(UInt16, UInt16) GetDeviceSelector(UInt16, UInt16) GetDeviceSelector(UInt16, UInt16) GetDeviceSelector(UInt16, UInt16) GetDeviceSelector(UInt16, UInt16)

Retrieves an Advanced Query Syntax (AQS) string based on the given usagePage and usageId.

GetDeviceSelector(UInt16, UInt16, UInt16, UInt16) GetDeviceSelector(UInt16, UInt16, UInt16, UInt16) GetDeviceSelector(UInt16, UInt16, UInt16, UInt16) GetDeviceSelector(UInt16, UInt16, UInt16, UInt16) GetDeviceSelector(UInt16, UInt16, UInt16, UInt16)

Retrieves an Advanced Query Syntax (AQS) string based on the given usagePage, usageId, vendorId, and productId.

GetFeatureReportAsync() GetFeatureReportAsync() GetFeatureReportAsync() GetFeatureReportAsync() GetFeatureReportAsync()

Asynchronously retrieves the first, or default, feature report from the given HID device.

GetFeatureReportAsync(UInt16) GetFeatureReportAsync(UInt16) GetFeatureReportAsync(UInt16) GetFeatureReportAsync(UInt16) GetFeatureReportAsync(UInt16)

Asynchronously retrieves a feature report, identified by the reportId parameter, for the given HID device.

GetInputReportAsync() GetInputReportAsync() GetInputReportAsync() GetInputReportAsync() GetInputReportAsync()

Asynchronously retrieves the default, or first, input report from the given HID device.

GetInputReportAsync(UInt16) GetInputReportAsync(UInt16) GetInputReportAsync(UInt16) GetInputReportAsync(UInt16) GetInputReportAsync(UInt16)

Asynchronously retrieves an input report, identified by the reportId parameter, from the given HID device.

GetNumericControlDescriptions(HidReportType, UInt16, UInt16) GetNumericControlDescriptions(HidReportType, UInt16, UInt16) GetNumericControlDescriptions(HidReportType, UInt16, UInt16) GetNumericControlDescriptions(HidReportType, UInt16, UInt16) GetNumericControlDescriptions(HidReportType, UInt16, UInt16)

Retrieves the descriptions of the numeric controls for the given HID device.

SendFeatureReportAsync(HidFeatureReport) SendFeatureReportAsync(HidFeatureReport) SendFeatureReportAsync(HidFeatureReport) SendFeatureReportAsync(HidFeatureReport) SendFeatureReportAsync(HidFeatureReport)

Sends an feature report asynchronously from the host to the device.

SendOutputReportAsync(HidOutputReport) SendOutputReportAsync(HidOutputReport) SendOutputReportAsync(HidOutputReport) SendOutputReportAsync(HidOutputReport) SendOutputReportAsync(HidOutputReport)

Sends an output report asynchronously from the host to the device.

Events

InputReportReceived InputReportReceived InputReportReceived InputReportReceived InputReportReceived

Establishes an event listener to handle input reports issued by the device when either GetInputReportAsync() or GetInputReportAsync(System.UInt16 reportId) is called.

See Also