Reputation: 11
Is there any way i can find out if a particular device is being plugged into a USB port and which USB port number is it plugged in, using C or Perl programming?
Upvotes: 1
Views: 963
Reputation: 3029
Yes. There are portable means like using libusb to enumerate all devices.
Also, you can use OS specific features, like devfs
or lsusb
on Linux, or the registry or WMI on Windows.
The command lsusb
shows you all connected devices. You can find the same information in the sysfs directory /sys/bus/usb/devices/
.
On Windows you can dig through the registry at HKLM\System\CurrentControlSet\Enum\USB
, or use WMI. WMI is accessible not only by Powershell, you can use Perl as well.
But, the preferred way is to use libusb
because of its portability.
Upvotes: 4