无法从DeviceInformation.Id创建UsbDevice

时间:2016-05-11 12:34:17

标签: c# windows-runtime usb win-universal-app hardware

我正在尝试使用仅适用于PC的通用Windows应用程序(无手机)(WinRT)通过Windows.Devices.Usb API连接到设备(SecuGen Hamster Pro 20)。

该设备是指纹扫描仪。

我已经完成了在线找到的所有步骤:

我使用以下方法查找了所有设备:

var myDevices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync();

这将返回大约1400个设备。经过一些过滤后使用:

 var resultList = myDevices.Where(s => s.Name.ToLower().Contains("secu")).ToList<DeviceInformation>();

resultList在我的机器中包含3个设备(我在其他机器上尝试过它,并在一些机器上找到10个结果)。

我没有使用重载来查找设备DeviceInformation.FindAllAsync(String aqsFilter),因为它返回0结果,但我确定我做得对(使用了正确的VID和PID)

这里的问题是当我尝试使用以下三种结果中的任何一种创建UsbDevice对象时:

UsbDevice device = await UsbDevice.FromIdAsync(resultList[0].Id);

返回值为null,我已经尝试了所有这些(resultList[0]resultList[1]resultList[2])而没有运气。

我使用以下方法配置了功能:

 <DeviceCapability Name="usb">
      <Device Id="vidpid:1162 2200">
        <Function Type="name:vendorSpecific"/>
      </Device>
    </DeviceCapability> 

我还尝试从UsbDevice返回的1400个设备中的任何一个创建DeviceInformation.FindAllAsync()对象,但所有设备都返回null,甚至有些设备抛出了the system cannot find the file specified 0x80070002

的异常

我尝试阅读DeviceAccessInformation所返回的设备DeviceAccessStatus.Unspecified

任何人都可以带我到我在这里失踪的地方吗?

2 个答案:

答案 0 :(得分:1)

您必须使用UsbDevice.GetDeviceSelector,然后在搜索设备时使用选择器。如果没有返回任何内容,则设备未正确“配置”为使用WinUSB.sys驱动程序。 (根据我的理解,它必须使用该驱动程序与usbdevice类一起使用)。

如果您手动告诉它在设备管理器中使用该驱动程序,那么理论上,您仍然必须在使用regedit之前更改密钥(注意:我这样做但它仍然无效)。我在这里找到了一个解决方案: http://www.lewisbenge.net/2013/09/20/integrating-windows-8-1-with-owi-535-robotic-arm/ 基本上,您必须使用inf文件安装驱动程序。使用在该站点上链接的那个并使用NTarm替换NTamd64,具体取决于目标平台

答案 1 :(得分:0)

首先,尝试按供应商和产品ID缩小搜索范围

此方法将帮助您做到这一点:

public static async Task<List<wde.DeviceInformation>> GetDevicesByProductAndVendorAsync(int vendorId, int productId)
{
    return ((IEnumerable<wde.DeviceInformation>)await wde.DeviceInformation.FindAllAsync($"System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True AND System.DeviceInterface.Hid.VendorId:={vendorId} AND System.DeviceInterface.Hid.ProductId:={productId} ").AsTask()).ToList();
}

https://github.com/MelbourneDeveloper/Hid.Net/blob/c69e3368343e59e51e8818c87dbea00e6ccfecae/Hid.Net.UWP/UWPHelpers.cs#L11

您将能够从中获取已连接设备的列表。然后,您应该可以与FromIdAsync连接。