UWP应用无法找到/连接到USB设备

时间:2016-12-12 08:34:47

标签: usb uwp

我正在尝试制作连接USB设备的UWP应用,然后执行一系列命令,例如从内部传感器检索数据(想想加速度计)。我开始遵循以下准则:

https://msdn.microsoft.com/en-us/library/windows/hardware/dn303343(v=vs.85).aspx

所以,我也尝试制作一个空白的应用程序,并相应调整清单:

<Capabilities>
  <DeviceCapability Name="usb">
    <Device Id="vidpid:1CBE 0003">
      <Function Type="classId:ff 00 00" />
    </Device>
  </DeviceCapability>
</Capabilities>

可以肯定的是,这是设备在设备管理器中识别自身的方式:

it's a WinUSB device vendor and product ID are set class ID is set to FF 00 00

然后使用

string aqs = UsbDevice.GetDeviceSelector(vid, pid);
var finder = await DeviceInformation.FindAllAsync(aqs);

然而,没有成功。问题很简单,应用程序找不到任何设备。然后我继续修改这个示例应用程序(使用DeviceWatcher而不是上面找到连接设备USB的方式):

https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/CustomUsbDeviceAccess

也没找到USB设备。当然,我尝试了一台不同的PC来查看它是否与我的配置有关,但正如您所料,没有成功。这让我觉得它可能与USB设备有关,但可能出错?或者我真的在这五行中犯了一些错误?还有其他方法可以尝试连接USB设备吗?任何提示都表示赞赏!

相关问题:

UWP/C# - Issue with AQS and USB Devices

https://social.msdn.microsoft.com/Forums/en-US/e9b85e2a-27c0-489e-9bf5-d990f0e83a61/uwpissue-with-usbdevicegetdeviceselector-not-finding-attached-bulk-usb-device?forum=wpdevelop

3 个答案:

答案 0 :(得分:2)

我似乎找到了一种方法来解决这个问题,这有点愚蠢,但是,嘿,无论如何谁问我......

我在stackoverflow上遇到过这个: Cannot create UsbDevice from DeviceInformation.Id

当我使用.inf将winusb称为驱动程序时,我的问题似乎确实得到了解决。我不知道为什么,所以如果你们有任何解释,请告诉我。

如上所述,答案指的是一个确实存在的博客帖子(我使用了回归机器),我在这里发布了inf,以防它对任何人有帮助(但它是一个普通的inf)

;
;
; Installs WinUsb
;

[Version]
Signature = "$Windows NT$"
Class     = USBDevice
ClassGUID = {88BAE032-5A81-49f0-BC3D-A4FF138216D6}
Provider  = %ManufacturerName%
CatalogFile = WinUSBInstallation.cat
DriverVer=12/12/2016,13.54.20.543

; ========== Manufacturer/Models sections ===========

[Manufacturer]
%ManufacturerName% = Standard,NTamd64

[Standard.NTamd64]
%DeviceName% =USB_Install, USB\VID_1267&PID_0000

; ========== Class definition ===========

[ClassInstall32]
AddReg = ClassInstall_AddReg

[ClassInstall_AddReg]
HKR,,,,%ClassName%
HKR,,NoInstallClass,,1
HKR,,IconPath,%REG_MULTI_SZ%,"%systemroot%\system32\setupapi.dll,-20"
HKR,,LowerLogoVersion,,5.2

; =================== Installation ===================

[USB_Install]
Include = winusb.inf
Needs   = WINUSB.NT

[USB_Install.Services]
Include =winusb.inf
Needs   = WINUSB.NT.Services

[USB_Install.HW]
AddReg=Dev_AddReg

[Dev_AddReg]
HKR,,DeviceInterfaceGUIDs,0x10000,"{9f543223-cede-4fa3-b376-a25ce9a30e74}"

; [DestinationDirs]
; If your INF needs to copy files, you must not use the DefaultDestDir         directive here.  
; You must explicitly reference all file-list-section names in this     section.

; =================== Strings ===================

[Strings]
ManufacturerName=""
ClassName="Universal Serial Bus devices"
DeviceName="OWI-535 Robotic Arm"
REG_MULTI_SZ = 0x00010000

请注意,我在驱动程序中留下了任意VID和PID,但我仍然需要连接设备告诉我的VID和PID。

答案 1 :(得分:0)

这是如何连接到UWP上的WinUSB设备。

public async Task<IEnumerable<DeviceDefinition>> GetConnectedDeviceDefinitions(uint? vendorId, uint? productId)
{
    var aqsFilter = "System.Devices.InterfaceClassGuid:=\"{DEE824EF-729B-4A0E-9C14-B7117D33A817}\" AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True AND " + $" System.DeviceInterface.WinUsb.UsbVendorId:={vendorId.Value} AND System.DeviceInterface.WinUsb.UsbProductId:={productId.Value}";

    var deviceInformationCollection = await wde.DeviceInformation.FindAllAsync(aqsFilter).AsTask();

    //TODO: return the vid/pid if we can get it from the properties. Also read/write buffer size

    var deviceIds = deviceInformationCollection.Select(d => new DeviceDefinition { DeviceId = d.Id, DeviceType = DeviceType.Usb }).ToList();
    return deviceIds;
}

以下是更完整的答案:https://stackoverflow.com/a/53954352/1878141

这是仓库中的一个类:https://github.com/MelbourneDeveloper/Device.Net/blob/master/src/Usb.Net.UWP/UWPUsbDeviceFactory.cs

答案 2 :(得分:0)

对于我来说,该设备的DeviceInterfaceGUID注册表项丢失了,这似乎是必需的,以便可以找到并实例化WinUSB设备。

我在条目HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_16D0&PID_0BD7\None\Device Parameters\DeviceInterfaceGUID中添加了一个随机GUID,例如{86529001-c433-4530-a578-9a67adf1ffa9}(在我的情况下,16D0是供应商ID,0BD7是产品ID,而None实例)。例如,可以通过在命令行中调用reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_16D0&PID_0BD7\None\Device Paramet ers" /v "DeviceInterfaceGUID" /t REG_SZ /d "{86529001-c433-4530-a578-9a67adf1ffa9}" /f来完成此操作。

我绝对不是USB方面的专家,也不知道为什么需要它或为什么它不存在。但是至少在我而言,在Windows 10 Professional和Windows 10 IoT核心版(Raspberry PI 3B)上添加GUID都有帮助。也许可以查看https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/usb-device-specific-registry-settings了解更多详情。

相关问题