问题
I have this code:
private async void OnDeviceAdded(DeviceWatcher watcher, DeviceInformation deviceInformation)
{
if (deviceInformation.Name.StartsWith("ClearShot") && deviceInformation.IsEnabled)
{
targetDevice = await UsbDevice.FromIdAsync(deviceInformation.Id);
OnConnected(EventArgs.Empty);
}
}
This is actually an event that is called from a DeviceWatcher
The problem is that targetDevice
is always null.
No crashes no nothing, It's just null, doesn't change. Why ?
Edit: This is the thing that i have in the manifest:
<DeviceCapability Name="usb">
<Device Id="vidpid:184c 0001">
<Function Type="classId:ff * *"/>
</Device>
</DeviceCapability>
回答1:
I just note for memory that it there is null after UsbDevice.FromIdAsync one should check the following:
Presence of the device with WinUsb driver in device manager.
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,\
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>
回答2:
I found the problem, the WInUSB driver that Windows installed for me didn't work for some reason, I had to install another one.
来源:https://stackoverflow.com/questions/39427148/usbdevice-fromidasync-returns-null