无法在UWP中使用HIDDevice类打开设备的句柄 [英] Can't open a handle to a device using HIDDevice class in UWP
问题描述
我们的应用程序,名为Hellokey,已在Store上提供,它可作为Windows Hello的配套设备管理器。
我们用于打开我们的句柄的函数HID设备如下,在某些Windows 10系统上不起作用。
string selector = HidDevice.GetDeviceSelector(0x0f0b,0x0001);
var devices = await DeviceInformation.FindAllAsync(selector);
if(devices.Count> 0)
{
currentDevice = await HidDevice.FromIdAsync(devices.ElementAt(0).Id,
FileAccessMode.ReadWrite);
}
它返回的错误提到设备正忙,但同时使用使用.NETFramework API的WPF应用程序我可以打开并运行HID设备。
我遇到的唯一解决方案是重新安装或使用'Fresh'选项,我必须完全删除所有已安装的应用程序。
你能否帮助找到问题的根源HIDDevice真的不稳定。
Hi
Hassan Seifi,
>>我们用于打开HID设备句柄的功能如下所示,这对某些Windows
10系统无效。
在那些API不起作用的情况下,是否有从应用程序显示的同意提示?
当商店应用程序第一次调用该方法时,应该调用它来自UI线程。 在
中提到了官方文件的评论 HidDevice.FromIdAsync() 。
您是否确保首次从UI线程调用此函数?
您可以使用以下代码来确保从UI线程调用它:
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,()=> {
currentDevice = await HidDevice.FromIdAsync(devices.ElementAt(0).Id,
FileAccessMode.ReadWrite);
});
< span style ="font-size:9.5pt; font-family:Consolas">
最好的问候,
Roy
Our application, named Hellokey, is already available on Store which works as a manager of companion device for Windows Hello.
The function we use for opening a handle to our HID device is as follow which doesn't works on some windows 10 systems.
string selector = HidDevice.GetDeviceSelector(0x0f0b, 0x0001); var devices = await DeviceInformation.FindAllAsync(selector); if (devices.Count > 0) { currentDevice = await HidDevice.FromIdAsync(devices.ElementAt(0).Id, FileAccessMode.ReadWrite); }
The error it returns mentioning that the device is busy, but at the same time using WPF application which uses .NETFramework API I can open and work the HID device.
The only solution I have for this issue is reinstalling or using the 'Fresh' option where I have to remove all the installed application entirely.
Could you please help with finding the source of the problem HIDDevice is really unstable.
Hi Hassan Seifi,
>> The function we use for opening a handle to our HID device is as follow which doesn't works on some windows 10 systems.
In those occasions that the API doesn’t work, is there a consent prompt that shows from the app?
When the store app invokes the method for the first time, it should be called from a UI thread. This is mentioned in the remarks of the official document HidDevice.FromIdAsync().
Have you ensured this function is called from a UI thread for the first time?
You could use the following code to mark sure it is called from the UI thread:
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { currentDevice = await HidDevice.FromIdAsync(devices.ElementAt(0).Id, FileAccessMode.ReadWrite); });
Best regards,
Roy
这篇关于无法在UWP中使用HIDDevice类打开设备的句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!