C# Windows Store app returning null for UsbDevice

寵の児 提交于 2019-12-19 11:46:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!