gpt4 book ai didi

uwp - HidDevice.FromIdAsync 通过读写返回 null

转载 作者:行者123 更新时间:2023-12-02 05:56:59 36 4
gpt4 key购买 nike

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

可能是什么问题。 list 中的权限已设置为正确的值。

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

list 代码

<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。

我敢打赌 list 中您的设备规范有问题。看看这篇文章http://www.idevstream.com/?p=322 。它将帮助您识别设备的使用页面和使用 ID。一旦你明白了,我敢打赌它会连接起来。这是我在阅读这篇文章之前一直坚持的一个例子: 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

关于uwp - HidDevice.FromIdAsync 通过读写返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44229225/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com