问题
Being new to Windows Store app development, I am working on an app that has to connect to several USB devices. I am using VS 2013 (community) with C#.
For example, a list of attached webcams is obtained using:
var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
This indeed gives me a list of attached webcams. To access the first device, a UsbDevice object should be created using:
DeviceInformation device = devices[0];
UsbDevice usbDevice = await UsbDevice.FromIdAsync(device.Id);
However, the object usbDevice is always null... I have tried this with several devices (different webcams, mouses, flash drives, etc...)
Any suggestions on how to fix this issue or whether there are alternatives to this approach?
回答1:
The devices you mention are all well known device types which are used via more specific classes (e.g. MediaCapture for the webcam). They don't use the winusb.sys driver and cannot be controlled with the Windows.Devices.Usb namespace intended for generic devices.
From the MSDN documentation for Windows.Devices.Usb:
The Windows.Devices.Usb defines Windows Runtime classes that a Windows store app can use to communicate with a USB device that does not belong to a device class, or for which Microsoft does not provide an in-box driver.
来源:https://stackoverflow.com/questions/28721091/c-sharp-windows-store-app-returning-null-for-usbdevice