LibUsbDotNet调用UsbDevice.AllDevices时找不到设备 [英] LibUsbDotNet No devices found when calling UsbDevice.AllDevices

查看:821
本文介绍了LibUsbDotNet调用UsbDevice.AllDevices时找不到设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在执行LibUsbDotNet的示例代码,该代码将向我返回所有连接的USB设备的信息.您可以在下面找到此代码.

I am executing the example code of LibUsbDotNet which will return me the information of all connected usb devices. You can find this code below.

using System;
using LibUsbDotNet;
using LibUsbDotNet.Info;
using LibUsbDotNet.Main;
using System.Collections.ObjectModel;

namespace Examples
{
    internal class ShowInfo
    {
        public static UsbDevice MyUsbDevice;

        public static void Main(string[] args)
        {
            // Dump all devices and descriptor information to console output.
            UsbRegDeviceList allDevices = UsbDevice.AllDevices;
            foreach (UsbRegistry usbRegistry in allDevices)
            {
                if (usbRegistry.Open(out MyUsbDevice))
                {
                    Console.WriteLine(MyUsbDevice.Info.ToString());
                    for (int iConfig = 0; iConfig < MyUsbDevice.Configs.Count; iConfig++)
                    {
                        UsbConfigInfo configInfo = MyUsbDevice.Configs[iConfig];
                        Console.WriteLine(configInfo.ToString());

                        ReadOnlyCollection<UsbInterfaceInfo> interfaceList = configInfo.InterfaceInfoList;
                        for (int iInterface = 0; iInterface < interfaceList.Count; iInterface++)
                        {
                            UsbInterfaceInfo interfaceInfo = interfaceList[iInterface];
                            Console.WriteLine(interfaceInfo.ToString());

                            ReadOnlyCollection<UsbEndpointInfo> endpointList = interfaceInfo.EndpointInfoList;
                            for (int iEndpoint = 0; iEndpoint < endpointList.Count; iEndpoint++)
                            {
                                Console.WriteLine(endpointList[iEndpoint].ToString());
                            }
                        }
                    }
                }
            }


            // Free usb resources.
            // This is necessary for libusb-1.0 and Linux compatibility.
            UsbDevice.Exit();

            // Wait for user input..
            Console.ReadKey();
        }
    }
}

我的问题是代码中执行了第二行:

My problem is that the second line executed in the code:

UsbRegDeviceList allDevices = UsbDevice.AllDevices;

根本不返回任何设备,虽然我确实有想要连接的设备(键盘和鼠标).

does not not return any device at all, while I do have the device I want to find connected, my keyboard and mouse.

以前有人遇到过此问题吗?和/或没有人知道如何解决吗?

Has anyone encountered this problem before? And/or does anyone know how to solve it?

预先感谢! 米兰·范·迪克

Thanks in Advance! Milan van Dijck

推荐答案

libusb是否支持HID设备?

在Windows上,libusb支持本机Windows HID驱动程序,但是存在一些限制,例如由于系统保留而无法访问HID鼠标和键盘,以及直接读取HID报告描述符.除此之外,您应该像其他任何USB设备一样与HID设备进行通信.

On Windows, the native Windows HID driver is supported by libusb, but there are some limitations, such as not being able to access HID mice and keyboards, as they are system reserved, as well as getting a direct read of HID report descriptors. Apart from that, you should be communicate with an HID device as you would with any other USB device.

如果您的应用程序将围绕HID访问,建议您尝试使用Signal 11软件的HIDAPI库,该库也是跨平台的.它在Windows和Mac OS X上使用本机HID API,并且在Linux下可以使用libusb或hidraw作为后端.

If your application will revolve around HID access, you are encouraged to try to use the ​HIDAPI library by Signal 11 Software, which is also cross-platform. It uses native HID API under Windows and Mac OS X and can use libusb or hidraw as the backend under Linux.

这篇关于LibUsbDotNet调用UsbDevice.AllDevices时找不到设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆