本文介绍了C#Windows应用商店应用为UsbDevice返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为Windows Store应用程序开发的新手,我正在开发一个必须连接到多个USB设备的应用程序.我正在将VS 2013(社区)与C#一起使用.

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);

这确实给了我附带的网络摄像头列表.要访问第一个设备,应使用以下命令创建UsbDevice对象:

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);

但是,对象usbDevice始终为null ...我已经尝试了几种设备(不同的网络摄像头,鼠标,闪存驱动器等)

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?

推荐答案

您提到的设备都是众所周知的设备类型,可通过更特定的类(例如,网络摄像头的MediaCapture)使用.他们不使用 winusb.sys 驱动程序,并且无法通过用于通用设备的Windows.Devices.Usb命名空间进行控制.

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.

Windows的MSDN文档中.Devices.Usb :

这篇关于C#Windows应用商店应用为UsbDevice返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 17:30