gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 20:24:52 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com