本文介绍了UsbDevice.FromIdAsync返回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 始终为空.

This is actually an event that is called from a DeviceWatcherThe problem is that targetDevice is always null.

没有崩溃就什么都没有,它只是null,不会改变.为什么?

No crashes no nothing, It's just null, doesn't change.Why ?

这是清单中我拥有的东西:

This is the thing that i have in the manifest:

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

推荐答案

我只是为内存指出,在UsbDevice.FromIdAsync之后,它为null,应该检查以下内容:

I just note for memory that it there is null after UsbDevice.FromIdAsync one should check the following:

  1. 设备管理器中具有WinUsb驱动程序的设备.

  1. Presence of the device with WinUsb driver in device manager.

注册表中存在带有生成的GUID的多字符串参数DeviceInterfaceGUID

Presence of multistring parameter DeviceInterfaceGUIDs with generated GUID in registry

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_184C&PID_0001\8000013\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,\

  • Package.appxmanifest中存在适当的DeviceCapability

  • Presence of appropriate DeviceCapability in Package.appxmanifest

    <Capabilities>
        <DeviceCapability Name="usb">
          <Device Id="vidpid:184C 0001">
            <Function Type="classId:ff * *" />
            <Function Type="name:vendorSpecific" />
          </Device>
        </DeviceCapability>
    

    这篇关于UsbDevice.FromIdAsync返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 10-31 10:31