HidDevice.FromIdAsync returns null with readwrite
Asked Answered
H

1

3

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.

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

Manifest code

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

Connection code

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
Hypsometry answered 28/5, 2017 at 15:52 Comment(4)
Are you ensure your UWP app has ReadWrite permission on your device?Lydon
@SunteenWu-MSFT If you mean in the HidDevice function then yes. If not then where can I set those permissions.Hypsometry
Any luck with this issue?Contralto
@SunteenWu-MSFT did you find what the issue is. Trying to connect to a Hide device and always getting null when calling FromIdAsuncAsoka
E
0

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.

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

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

Emulate answered 25/11, 2018 at 3:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.