0

The following code returns null in some Windows 10 systems

currentDevice = await HidDevice.FromIdAsync(devices.ElementAt(0).Id,
                               FileAccessMode.ReadWrite);

I found out that this problem could be resolved by reinstalling Windows 10/ or using 'Fresh' option in Windows 10 which removes all the third-party applications. I can't guess which application may has a conflict with the HID device.

Just for your record, I can open a handle to this HID device using WPF Win32 application but in the Universal app I can't!

New Update 7/11/2018

After doing some debugging tasks using WinDbg, we realized that our UWP access is being failed because of some Upperfilters available on this branch: [Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class]. Some of these are made and controlled by Kaspersky anti-virus.

Looking for to see which/why kernel/user driver brings this limitation on getting access to the HID devices for just UWP Store applications?

Sansei
  • 93
  • 10

1 Answers1

0

From the MSDN document:

The first time this method is invoked by a store app, it should be called from a UI thread in order to display the consent prompt. After the user has granted consent, the method can be invoked from any application thread.

So, You could call this method in Dispatcher.RunAsync like the following:

await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,()=> {
            currentDevice = await HidDevice.FromIdAsync(devices.ElementAt(0).Id,
                           FileAccessMode.ReadWrite);
        });
Xie Steven
  • 8,544
  • 1
  • 9
  • 23
  • This is not helpful, please consider that this problem will be resolved completely when we make the windows afresh which removes all user-applications. When this happens, indeed there is no way to get access to the HID device using UWP with the mentioned code. – Sansei Feb 06 '18 at 10:10
  • @Sansei Have you tried the [Custom HID device sample](https://github.com/Microsoft/Windows-universal-samples/tree/6370138b150ca8a34ff86de376ab6408c5587f5d/Samples/CustomHidDeviceAccess) to see if it will work on your side? – Xie Steven Feb 07 '18 at 09:02
  • No it doesn't work, but at the same time, I can open the device using a WPF application. – Sansei Feb 07 '18 at 13:41
  • See the attachment where the WPF can open the device, but UWP can not. I tried many HID devices, from the many vendors but it doesn't work at all. – Sansei Feb 07 '18 at 13:55