HidDevice.FromIdAsync通过读写返回null [英] HidDevice.FromIdAsync returns null with readwrite

查看:196
本文介绍了HidDevice.FromIdAsync通过读写返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将库从经典桌面移植到UWP.除了一件事之外,所有工作都按计划进行.当我尝试打开到设备的HID连接(wiimote)时,如果权限处于读写状态,它将无法连接.确实具有只读权限.

I am trying to port a library from classic desktop to UWP. It all works like planned except for one thing. When I try to open a HID connection to the device(A wiimote) it won't connect if the permissions are on readwrite. It does work with read only permissions.

可能是问题所在.清单中的权限设置为正确的值.

What could be the problem. The permissions in the manifest are set to the correct values.

我检查了DeviceAccessStatus以查看权限是否不好,但它返回DeviceAccessStatus.Allowed

I checked the DeviceAccessStatus to see if the permissions are not good but it returns DeviceAccessStatus.Allowed

清单代码

<Capabilities>
 <Capability Name="internetClient" />
  <DeviceCapability Name="humaninterfacedevice">
   <Device Id="any">
    <Function Type="usage:0005 *"/>
    <Function Type="usage:0001 0005"/>
   </Device>
  </DeviceCapability>
</Capabilities>

连接代码

var selector = HidDevice.GetDeviceSelector(1, 5);
var devices = await DeviceInformation.FindAllAsync(selector);
if (devices.Count > 0)
{
    foreach (var device in devices)
    {
        var deviceId = device.Id;
        var foundDevice = await HidDevice.FromIdAsync(deviceId, FileAccessMode.ReadWrite); // Does not work always returns null
        if (foundDevice == null)continue;
        // if the vendor and product IDs match up
        if (foundDevice.VendorId == VID && foundDevice.ProductId == PID)
        {
        // Unrelated code

推荐答案

您的代码看起来不错,除了要抓取的选择器可能太有选择性.您可能需要查看随即吐出的文字,并删除不必要的狭窄内容,例如使用情况页面或使用情况ID.

Your code looks good except that the selector you are grabbing may be too selective. You might want to look at the text it is spitting out and remove anything that is unnecessarily narrow like the usage page or usage id.

我想打赌清单中的设备规格有问题.看看这篇文章 http://www.idevstream.com/?p=322.它将帮助您识别设备的使用情况页面和使用情况ID.一旦您知道了,我敢打赌它将连接.这是我阅读本文之前一直坚持的一个示例: https://github.com/MelbourneDeveloper/Ledger.Net/blob/master/src/Ledger.Net.UWPUnitTest/Package.appxmanifest

I'd like to bet that there is a problem with your device specification in the manifest. Have a look at this article http://www.idevstream.com/?p=322. It will help you identify the usage page and usage id of your device. Once you've got that, I'll bet it will connect. Here's an example of one that I was stuck on until I read the article: https://github.com/MelbourneDeveloper/Ledger.Net/blob/master/src/Ledger.Net.UWPUnitTest/Package.appxmanifest

此外,请查看Hid.Net中的以下代码以进行连接: https://github.com/MelbourneDeveloper/Hid.Net/blob/80714078fc8772dd04b60648b0fe6974205a3d8f/Hid.Net.UWP/UWPHidDevice.cs#L95

Also, have a look at this code in Hid.Net for connection: https://github.com/MelbourneDeveloper/Hid.Net/blob/80714078fc8772dd04b60648b0fe6974205a3d8f/Hid.Net.UWP/UWPHidDevice.cs#L95

这篇关于HidDevice.FromIdAsync通过读写返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆