Shadow
Shadow

Reputation: 2478

How to get serial number and name of hid device in UWP?

In Win32 api I could use functions HidD_GetSerialNumberString to get a device serial number. How I can get such properties in UWP? There seems to be no way to get SerialNumber.

To be clear, I am making sandboxed UWP app, and cannot use P/Invoke.

Upvotes: 0

Views: 856

Answers (1)

Rob_Stark
Rob_Stark

Reputation: 11

Serial number can reside in Feature report of the HID device (You should check with Drivers team once).

This is how I did it, may / may not work for you.

using HidDevice hidDevice = await HidDevice.FromIdAsync(Id, FileAccessMode.ReadWrite);
                
var controlDataList = hidDevice.GetNumericControlDescriptions(HidReportType.Feature, 0, UsageId);
if (controlDataList == null || controlDataList.Count == 0)
{
    return;
}

ushort featureReportId = controlDataList[0].ReportId;
HidFeatureReport response = await hidDevice.GetFeatureReportAsync(featureReportId);
byte[] data = new byte[response.Data.Length];
response.Data.CopyTo(data);
CustomFeatureReport? featureReport = data.BytesToStruct<CustomFeatureReport>();

Upvotes: 1

Related Questions