我正在寻找一种跨平台的方式来获取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)
{ …Run Code Online (Sandbox Code Playgroud)