Connecting to the Device
At this point in the chapter, you should be intimately familiar with the typical pattern for getting an instance of a HID device:
async Task<HidDevice > GetHidDevice(ushort usagePage, ushort usageId) { foreach (DeviceInformation deviceInfo in await DeviceInformation.FindAllAsync(HidDevice .GetDeviceSelector( usagePage, usageId))) { // Return the first one (null if user doesn't consent) // Be sure to call FromIdAsync on the UI thread! return await HidDevice .FromIdAsync(deviceInfo.Id, FileAccessMode .ReadWrite); } return null; }
HidDevice
’s GetDeviceSelector
method requires a usage page and usage ID, and there’s an overload that ...
Get Universal Windows® Apps with XAML and C# Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.