Mil*_*lan 7 c# libusb visual-studio 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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是代码中执行的第二行:
UsbRegDeviceList allDevices = UsbDevice.AllDevices;
Run Code Online (Sandbox Code Playgroud)
根本不返回任何设备,而我确实有我想要找到连接的设备,我的键盘和鼠标。
以前有人遇到过这个问题吗?和/或有人知道如何解决它吗?
提前致谢!米兰·范迪克
\n\n在 Windows 上,libusb 支持本机 Windows HID 驱动程序,但存在一些限制,例如无法访问 HID 鼠标和键盘,因为它们是系统保留的,以及无法直接读取 HID 报告描述符。除此之外,您应该像与任何其他 USB 设备一样与 HID 设备进行通信。
\n如果您的应用程序将围绕 HID 访问,我们鼓励您尝试使用 Signal 11 Software 的 \xe2\x80\x8bHIDAPI 库,该库也是跨平台的。它在 Windows 和 Mac OS X 下使用原生 HID API,在 Linux 下可以使用 libusb 或 hidraw 作为后端。
\n