如何在Linux中使用libusb获取设备路径

LAS*_*LAS 5 c# linux usb libusb

我正在寻找一种跨平台的方式来获取C#中的usb到达和删除事件,我找到了"LibUsbDotNet C#USB Library"(http://sourceforge.net/projects/libusbdotnet/?source=navbar).

它应该工作,但在Linux中似乎我无法获得设备挂载点(路径).在Linux中它使用"libusb"库,它没有获取设备路径的方法.

这是一个检测设备事件的简单代码示例:

internal class DeviceNotification
{
    public static IDeviceNotifier UsbDeviceNotifier = DeviceNotifier.OpenDeviceNotifier();

    private static void Main(string[] args)
    {
        // Hook the device notifier event
        UsbDeviceNotifier.OnDeviceNotify += OnDeviceNotifyEvent;

        // Exit on and key pressed.
        Console.Clear();            
        Console.WriteLine();
        Console.WriteLine("Waiting for system level device events..");
        Console.Write("[Press any key to exit]");

        while (!Console.KeyAvailable)
            Application.DoEvents();

        UsbDeviceNotifier.Enabled = false;  // Disable the device notifier

        // Unhook the device notifier event
        UsbDeviceNotifier.OnDeviceNotify -= OnDeviceNotifyEvent;
    }

    private static void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
    {
        // A Device system-level event has occured

        Console.SetCursorPosition(0,Console.CursorTop);

        Console.WriteLine(e.ToString()); // Dump the event info to output.

        Console.WriteLine();
        Console.Write("[Press any key to exit]");
    }
}
Run Code Online (Sandbox Code Playgroud)

这是输出的示例:

[DeviceType:DeviceInterface] [EventType:DeviceArrival]名称:usbdev1.17 BusNumber:1 DeviceAddress:17长度:18 DescriptorType:Device BcdUsb:0x0200类别:PerInterface子类:0x00协议:0x00 MaxPacketSize0:64 VendorID:0x059F ProductID:0x1014 BcdDevice: 0x0000 ManufacturerStringIndex:1 ProductStringIndex:2 SerialStringIndex:3 ConfigurationCount:1

[按任意键退出] [DeviceType:DeviceInterface] [EventType:DeviceRemoveComplete]名称:usbdev1.17 BusNumber:1 DeviceAddress:17 Length:18 DescriptorType:Device BcdUsb:0x0200 Class:PerInterface SubClass:0x00 Protocol:0x00 MaxPacketSize0:64 VendorID :0x059F ProductID:0x1014 BcdDevice:0x0000 ManufacturerStringIndex:1 ProductStringIndex:2 SerialStringIndex:3 ConfigurationCount:1

我的问题是如何获取附加或删除设备的路径,或者如何将libusb返回的信息与实际设备路径绑定?

Jim*_*ack -1

USB设备文件通常存放在以下路径:

/dev/bus/usb
Run Code Online (Sandbox Code Playgroud)

该文件夹中的子目录应与上面的公交车号码相匹配。如果 USB 设备没有直接连接到计算机(例如通过集线器或其他外部设备),事情就会变得复杂。不要忘记从十六进制转换。