UsbDevice.FromIdAsync returns 空

UsbDevice.FromIdAsync returns null

我有这个代码:

private async void OnDeviceAdded(DeviceWatcher watcher, DeviceInformation deviceInformation)
    {
        if (deviceInformation.Name.StartsWith("ClearShot") && deviceInformation.IsEnabled)
        {

            targetDevice = await UsbDevice.FromIdAsync(deviceInformation.Id);
            OnConnected(EventArgs.Empty);

        }

    }

这实际上是一个从 DeviceWatcher 调用的事件 问题是 targetDevice 总是空的。

没有崩溃没有什么,它只是空的,没有改变。 为什么?

编辑:这是我在清单中的内容:

<DeviceCapability Name="usb">
    <Device Id="vidpid:184c 0001">
        <Function Type="classId:ff * *"/>
    </Device>
</DeviceCapability> 

我发现了问题,Windows 为我安装的 WInUSB 驱动程序由于某种原因无法使用,我不得不安装另一个。

为了记忆,我只是注意到它在 UsbDevice.FromIdAsync 之后是空的,应该检查以下内容:

  1. 设备管理器中存在带有 WinUsb 驱动程序的设备。

  2. 在注册表中存在具有生成的 GUID 的多字符串参数 DeviceInterfaceGUIDs

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_184C&PID_000100013\Device Parameters]
    "DeviceInterfaceGUIDs"=hex(7):7b,00,32,00,34,00,42,00,35,00,37,00,46,00,34,00,\
    37,00,2d,00,41,00,37,00,41,00,43,00,2d,00,34,00,46,00,41,00,32,00,2d,00,39,\
    00,43,00,31,00,33,00,2d,00,32,00,38,00,36,00,42,00,30,00,33,00,34,00,46,00,\
    
  3. Package.appxmanifest

    中存在适当的 DeviceCapability
    <Capabilities>
        <DeviceCapability Name="usb">
          <Device Id="vidpid:184C 0001">
            <Function Type="classId:ff * *" />
            <Function Type="name:vendorSpecific" />
          </Device>
        </DeviceCapability>