Jinjinov / Usb.Events

Subscribe to the Inserted and Removed events to be notified when a USB drive is plugged in or unplugged, or when a USB device is connected or disconnected. Usb.Events is a .NET Standard 2.0 library and uses WMI on Windows, libudev on Linux and IOKit on macOS.
MIT License
95 stars 23 forks source link

Capture device number and bus number on Linux #21

Closed d79ima closed 2 years ago

d79ima commented 2 years ago

Is your feature request related to a problem? Please describe. I would like to have access to the Linux system attributes Device Num and Bus Num for usb devices.

Describe the solution you'd like Would you be able to add calls in UsbEventWatcher.Linux.c GetDeviceInfo(): udev_device_get_sysattr_value(dev, "devnum") udev_device_get_sysattr_value(dev, "busnum")

And add 2 new fields into the common UsbDevice class. I am not sure if these fields make sense on Windows and Mac also, they may not be available. In which case can just put a disclaimer in the comments

Jinjinov commented 2 years ago

You can get the Device Number and Bus Number from the Device Name:

Device Name: /dev/bus/usb/001/003

Bus Number is 1 Device Number is 3

string[] split = DeviceName.Split('/', System.StringSplitOptions.RemoveEmptyEntries);
string busNum = split[3];
string devNum = split[4];
d79ima commented 2 years ago

perfect thanks