Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I programmatically detect the attachment of a portable USB device?

Tags:

linux

usb

libusb

In Windows OS, when a USB device is attached or detached, WindowProc receives a WM_DEVICECHANGE message having parameters wParam and lParam in which I can find out which device is attached or detached.

How can I programmatically detect the connection of a portable USB device at any time when the program is already running on Linux in the same way? Preferably using libusb and without using udev and there should be no call to external utilities like lsusb.

I've looked thru similar questions in this forum and alas found no answer.

like image 946
Perikl Femidi Avatar asked Oct 25 '25 02:10

Perikl Femidi


1 Answers

I found the way. libusb_hotplug_register_callback saves me.

like image 170
Perikl Femidi Avatar answered Oct 26 '25 19:10

Perikl Femidi