我正在尝试制作连接到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>
Run Code Online (Sandbox Code Playgroud)
可以肯定的是,这是设备在设备管理器中识别自身的方式:

然后用
string aqs = UsbDevice.GetDeviceSelector(vid, pid);
var finder = await DeviceInformation.FindAllAsync(aqs);
Run Code Online (Sandbox Code Playgroud)
但是,没有成功.问题很简单,应用程序找不到任何设备.然后我继续修改这个示例应用程序(使用DeviceWatcher而不是上面找到连接设备USB的方式):
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/CustomUsbDeviceAccess
其中也没有找到USB设备.当然,我尝试了一台不同的PC来查看它是否与我的配置有关,但正如您所料,没有成功.这让我觉得它可能与USB设备有关,但可能出错?或者我真的在这五行中犯了一些错误?还有其他方法可以尝试连接USB设备吗?任何提示都表示赞赏!
相关问题:
看来我找到了一种方法来解决这个问题,这有点愚蠢,但是嘿,谁问我了......
我在 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
Run Code Online (Sandbox Code Playgroud)
请注意,我在驱动程序中留下了任意 VID 和 PID,但我仍然必须连接设备告诉我的 VID 和 PID。
| 归档时间: |
|
| 查看次数: |
1725 次 |
| 最近记录: |