C# 在UWP应用程序中调用HidDevice.FromIdAsync,使用ReadWrite将返回null,而使用Read将返回HidDevice

C# 在UWP应用程序中调用HidDevice.FromIdAsync,使用ReadWrite将返回null,而使用Read将返回HidDevice,c#,xml,uwp,hid,C#,Xml,Uwp,Hid,首先,我可以确认这个hid设备可以在WinForm中读写。 这是我的uwp代码: var myDevices = await DeviceInformation.FindAllAsync("System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True AND System.DeviceInterface.Hid.VendorId:=3800 AND System.DeviceInterface.Hid.

首先,我可以确认这个hid设备可以在WinForm中读写。 这是我的uwp代码:

var myDevices = await DeviceInformation.FindAllAsync("System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True AND System.DeviceInterface.Hid.VendorId:=3800 AND System.DeviceInterface.Hid.ProductId:=300");
//i try to using HidDevice.GetDeviceSelector(0x0001, 0x0005) but get a empty collection
if (myDevices.Any())
{
    //readwriteDevice will be null
    var readwriteDevice = await HidDevice.FromIdAsync(myDevices[0].Id, FileAccessMode.ReadWrite);

    //readonlyDevice will be HidDevice
    var readonlyDevice = await HidDevice.FromIdAsync(myDevices[0].Id, FileAccessMode.Read);
    Debug.WriteLine($"UsageId: {readonlylDevice.UsageId}, UsagePage: {readonlylDevice.UsagePage}");//UsageId: 5, UsagePage: 1


    var information= DeviceAccessInformation.CreateFromId(myDevices[0].Id);
    Debug.WriteLine($"CurrentStatus: {information.CurrentStatus}");//Allowed
}
此外,我已经来到Package.appxmanifest,定义如下:

<DeviceCapability Name="humaninterfacedevice">
    <Device Id="vidpid:0ED8 012C">
        <Function Type="usage:0001 0005" />
    </Device>
</DeviceCapability>


所以我不知道问题出在哪里。是否有任何地方可以定义读取和写入权限?

能否共享有关hid设备信息以及应用程序目标版本和min版本的更多信息。您是否可以尝试使用其他函数类型值进行测试?请在此处选中此项,以根据设备选择正确的usageRead/Write设备访问权限。有一个设备标准定义头(属性),读/写不是头中的属性。设备的驱动程序可能只允许读取或写入设备,对属性的访问取决于供应商的唯一属性。因此,像文件系统这样的设备类型确实具有驱动器上文件的读/写权限。