c# - LibUsbDotNet 调用 UsbDevice.AllDevices 时找不到设备

标签 c# visual-studio libusb libusbdotnet

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

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

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

UsbRegDeviceList allDevices = UsbDevice.AllDevices;

根本不返回任何设备,而我确实连接了我想要找到的设备,我的键盘和鼠标。

有没有人遇到过这个问题?和/或有人知道如何解决吗?

提前致谢! 米兰范戴克

最佳答案

Does libusb support HID devices?

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.

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.

关于c# - LibUsbDotNet 调用 UsbDevice.AllDevices 时找不到设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25714930/

相关文章:

c# - 将 LINQ 中的 IEnumerable 数据作为参数传递给方法

c# - 如何将(启动的)ConfigureServices 方法拆分为多个文件

c# - 如何在 C# Windows 窗体中停止加载窗体

HTML Bootstrap 向输入表单添加选项

javascript - 如何在 ASP.NET 中向串行端口或 USB 端口发送和接收数据?

C# Auto Property - 这是 'pattern' 最佳实践吗?

c# - DragDrop 事件返回表单中的位置,拖放在 flowLayoutPanel 中

c++ - 可以得到不包含头文件目录的警告或错误

c - 在 gtk 窗口中流式传输 libuvc 代码的过程是什么?

c - 使用 xusb.c 示例代码遇到 libusb 中逻辑 block 地址的偏移量?