Trying to open a device using HidDevice FromIdAsync in UWP always returns null unless using FileAccessMode.Read

Victor Chen 106 Reputation points
2022-12-06T12:36:23.19+00:00

I can confirm that my HID device can have read and write capabilities, because this has been verified in WPF application, where one Endpoint can read and the other can read and write.

I thought it might be a permissions issue, but I defined almost every possible Usage in the manifest, and this still doesn't work.

Is there any other way to test HID besides buying SuperMUTT? (It costs 350$)

My code:

   csharp  
               //This method will be called on the UI thread  
               private async Task OpenDevice()  
               {  
                   string aqs = HidDevice.GetDeviceSelector(0x0001, 0x0005, 0xAAAA, 0xBBBB);  
                   //Two Endpoints are returned here, one of which can only be opened by Read, and the other cannot be opened by Read or ReadWrite  
                   var devices = await DeviceInformation.FindAllAsync(aqs);  
                   foreach (var deviceInfo in devices)  
                   {  
                       var access = DeviceAccessInformation.CreateFromId(deviceInfo.Id);  
                       if (access.CurrentStatus == DeviceAccessStatus.Allowed)  
                       {  
                           var deviceWithReadWrite = await HidDevice.FromIdAsync(deviceInfo.Id, FileAccessMode.ReadWrite);  
                           //deviceWithReadWrite is null  
                           var deviceWithRead = await HidDevice.FromIdAsync(deviceInfo.Id, FileAccessMode.ReadWrite);  
                           //deviceWithRead is not null  
                       }  
                   }  
               }  

Capabilities in Package.appxmanifest

   <Capabilities>  
   		<DeviceCapability Name="humaninterfacedevice">  
   			<Device Id="any">  
   				<Function Type="usage:0001 *"/>  
   				<Function Type="usage:0009 *"/>  
   				<Function Type="usage:FF00 *"/>  
   				<Function Type="usage:FFF0 *"/>  
   				<Function Type="usage:FF80 *"/>  
   			</Device>  
   		</DeviceCapability>  
   	</Capabilities>  

HID Report Descriptor

   0x08,              // Usage  
   0x05, 0x01,        // Usage Page (Generic Desktop Ctrls)  
   0x09, 0x05,        // Usage (Game Pad)  
   0xA1, 0x01,        // Collection (Application)  
   0x85, 0x01,        //   Report ID (1)  
   0x09, 0x30,        //   Usage (X)  
   0x09, 0x31,        //   Usage (Y)  
   0x09, 0x32,        //   Usage (Z)  
   0x09, 0x35,        //   Usage (Rz)  
   0x15, 0x00,        //   Logical Minimum (0)  
   0x26, 0xFF, 0x00,  //   Logical Maximum (255)  
   0x75, 0x08,        //   Report Size (8)  
   0x95, 0x04,        //   Report Count (4)  
   0x81, 0x02,        //   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)  
   0x09, 0x39,        //   Usage (Hat switch)  
   0x15, 0x00,        //   Logical Minimum (0)  
   0x25, 0x07,        //   Logical Maximum (7)  
   0x35, 0x00,        //   Physical Minimum (0)  
   0x46, 0x3B, 0x01,  //   Physical Maximum (315)  
   0x65, 0x14,        //   Unit (System: English Rotation, Length: Centimeter)  
   0x75, 0x04,        //   Report Size (4)  
   0x95, 0x01,        //   Report Count (1)  
   0x81, 0x42,        //   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,Null State)  
   0x65, 0x00,        //   Unit (None)  
   0x05, 0x09,        //   Usage Page (Button)  
   0x19, 0x01,        //   Usage Minimum (0x01)  
   0x29, 0x11,        //   Usage Maximum (0x11)  
   0x15, 0x00,        //   Logical Minimum (0)  
   0x25, 0x01,        //   Logical Maximum (1)  
   0x75, 0x01,        //   Report Size (1)  
   0x95, 0x11,        //   Report Count (17)  
   0x81, 0x02,        //   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)  
   0x06, 0x00, 0xFF,  //   Usage Page (Vendor Defined 0xFF00)  
   0x09, 0x20,        //   Usage (0x20)  
   0x75, 0x03,        //   Report Size (3)  
   0x95, 0x01,        //   Report Count (1)  
   0x81, 0x02,        //   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)  
   0x05, 0x01,        //   Usage Page (Generic Desktop Ctrls)  
   0x09, 0x33,        //   Usage (Rx)  
   0x09, 0x34,        //   Usage (Ry)  
   0x15, 0x00,        //   Logical Minimum (0)  
   0x26, 0xFF, 0x00,  //   Logical Maximum (255)  
   0x75, 0x08,        //   Report Size (8)  
   0x95, 0x02,        //   Report Count (2)  
   0x81, 0x02,        //   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)  
   0x06, 0x00, 0xFF,  //   Usage Page (Vendor Defined 0xFF00)  
   0x09, 0x21,        //   Usage (0x21)  
   0x95, 0x36,        //   Report Count (54)  
   0x81, 0x02,        //   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)  
   0x85, 0x05,        //   Report ID (5)  
   0x09, 0x22,        //   Usage (0x22)  
   0x95, 0x1F,        //   Report Count (31)  
   0x91, 0x02,        //   Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)  
   0x85, 0x03,        //   Report ID (3)  
   0x0A, 0x21, 0x27,  //   Usage (0x2721)  
   0x95, 0x2F,        //   Report Count (47)  
   0xB1, 0x02,        //   Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)  
   0x06, 0x80, 0xFF,  //   Usage Page (Vendor Defined 0xFF80)  
   0x85, 0xE0,        //   Report ID (-32)  
   0x09, 0x57,        //   Usage (0x57)  
   0x95, 0x02,        //   Report Count (2)  
   0xB1, 0x02,        //   Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)  
   0xC0,              // End Collection  
   0x06, 0xF0, 0xFF,  // Usage Page (Vendor Defined 0xFFF0)  
   0x09, 0x40,        // Usage (0x40)  
   0xA1, 0x01,        // Collection (Application)  
   0x85, 0xF0,        //   Report ID (-16)  
   0x09, 0x47,        //   Usage (0x47)  
   0x95, 0x3F,        //   Report Count (63)  
   0xB1, 0x02,        //   Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)  
   0x85, 0xF1,        //   Report ID (-15)  
   0x09, 0x48,        //   Usage (0x48)  
   0x95, 0x3F,        //   Report Count (63)  
   0xB1, 0x02,        //   Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)  
   0x85, 0xF2,        //   Report ID (-14)  
   0x09, 0x49,        //   Usage (0x49)  
   0x95, 0x0F,        //   Report Count (15)  
   0xB1, 0x02,        //   Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)  
   0x85, 0xF3,        //   Report ID (-13)  
   0x0A, 0x01, 0x47,  //   Usage (0x4701)  
   0x95, 0x07,        //   Report Count (7)  
   0xB1, 0x02,        //   Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)  
   0x06, 0x00, 0xFF,  //   Usage Page (Vendor Defined 0xFF00)  
   0x09, 0x00,        //   Usage (0x00)  
   0x85, 0x10,        //   Report ID (16)  
   0x15, 0x00,        //   Logical Minimum (0)  
   0x25, 0xFF,        //   Logical Maximum (-1)  
   0x35, 0x00,        //   Physical Minimum (0)  
   0x45, 0xFF,        //   Physical Maximum (-1)  
   0x75, 0x08,        //   Report Size (8)  
   0x95, 0x3F,        //   Report Count (63)  
   0x81, 0x02,        //   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)  
   0x06, 0x00, 0xFF,  //   Usage Page (Vendor Defined 0xFF00)  
   0x09, 0x20,        //   Usage (0x20)  
   0x85, 0xDD,        //   Report ID (-35)  
   0x75, 0x08,        //   Report Size (8)  
   0x95, 0x3F,        //   Report Count (63)  
   0x81, 0x02,        //   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)  
   0x85, 0x0F,        //   Report ID (15)  
   0x09, 0x22,        //   Usage (0x22)  
   0x95, 0x3F,        //   Report Count (63)  
   0x91, 0x02,        //   Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)  
   0xC0,              // End Collection  
Universal Windows Platform (UWP)
{count} votes