【问题标题】:LibUsbDotNet No devices found when calling UsbDevice.AllDevicesLibUsbDotNet 调用 UsbDevice.AllDevices 时未找到设备
【发布时间】:2014-11-01 02:55:51
【问题描述】:

我正在执行 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;

根本不返回任何设备,但我确实有我想要连接的设备、我的键盘和鼠标。

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

提前致谢! 米兰范戴克

【问题讨论】:

  • libusb 应该是通用设备管理器 API,还是只是使用 libusb-win32 驱动程序的设备的包装器?
  • 我遇到了类似的问题。我能够连接到设备一次,但之后我无法让应用程序再次连接......即使我重新启动系统。

标签: c# visual-studio libusb libusbdotnet


【解决方案1】:

Does libusb support HID devices?

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

如果您的应用程序将围绕 HID 访问,我们鼓励您尝试使用 Signal 11 Software 的 HIDAPI 库,它也是跨平台的。它在 Windows 和 Mac OS X 下使用原生 HID API,在 Linux 下可以使用 libusb 或 hidraw 作为后端。

【讨论】:

  • 嗯,看来他们需要更新我引用的页面。
  • 感谢帮助。我连接的设备似乎也被列为人机接口设备,因此不会为 UsbDevices.AllDevices 列表生成任何输出。
  • 我正在尝试访问 USB-COM 端口。这不是 HID 设备,但 UsbDevice.AllDevices 返回 emtpy 结果。这很奇怪
【解决方案2】:

The documentation 这么说

获取所有可用 USB 设备(WinUsb、LibUsb、Linux LibUsb v1.x)的列表。

使用此属性获取可以被 LibUsbDotNet 访问的 USB 设备列表。

如果您为鼠标和键盘使用标准 HID 驱动程序并且没有用 libusb.sys 驱动程序替换它,则 LibUsbDotNet 无法访问这些设备,因此不会列出它们。

【讨论】:

  • 感谢您的回答!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-13
  • 1970-01-01
  • 2019-05-06
相关资源
最近更新 更多