UWP 应用找不到 USB 设备。总是从 UsbDevice.FromIdAsync() 得到 null

UWP app cannot find the USB device. Always getting null from UsbDevice.FromIdAsync()

我尝试按照MSDN中的说明在uwp中连接USB设备,但是我无法连接到usb设备并且总是从UsbDevice.FromIdAsync()中获取null。 我已经看到关于这个问题的问题和答案 here

但没有解决我的问题。任何帮助将不胜感激。

这些是我正在尝试的代码片段。相同的代码片段适用于 .Net 标准应用程序。但不适用于 UWP。

UsbDevice device = null;
        string HPVID = "1008";
        string pid = "9812";
        try
        {

            Task.Run(async () =>
            {
                var aqsFilter = "System.Devices.InterfaceEnabled:= System.StructuredQueryType.Boolean#True " + "AND System.DeviceInterface.WinUsb.UsbVendorId:=" + HPVID +
                    "AND System.DeviceInterface.Winusb.UsbProductId:=" + pid;
                DeviceInformationCollection deviceInterface = await DeviceInformation.FindAllAsync(aqsFilter);

                if (deviceInterface.Count > 0)
                {
                    device = await UsbDevice.FromIdAsync(deviceInterface[0].Id);
                }

            }).Wait();
        }

UWP app cannot find the USB device. Always getting null from UsbDevice.FromIdAsync()

如果添加 DeviceCapability 功能,请检查包清单文件,这里是 code sample 您可以参考。

Really I want to know what actually means

我们有 document that explain the Function . And here is document how to specify device capabilities in a package manifest. Here is support list 可以参考。

A string between 1 and 100 characters in length. Where appropriate, the string may begin with "classId:" | "winUsbId:" | "serviceId:" | "serviceId:" | "usage:" | "interfaceId:"