7

I wish to do event handling in C/C++ monitoring USB activity-insertion and removal in Linux.Can you suggest me some resources where I can learn the same?

Jay
  • 187
  • 1
  • 3
  • 8
  • Surprisingly, there has been a similar question earlier with 4 votes, and no accepted answer: http://stackoverflow.com/questions/947267/how-to-detect-usb-device-disconnect-under-linux-qt-c – Ozair Kafray Jun 24 '11 at 11:49

3 Answers3

5

You can use

  • libusb - to scan the USB devices
  • libudev - to monitor devices
  • or add a rule to udev to monitor insertion/removal of devices
  • Work with USB HID programming
  • Or use the HAL Daemon ( ed: it seems this one is now an zombie, see:comments )
Reno
  • 33,594
  • 11
  • 89
  • 102
  • well I am doing this for an embedded system which supports only standard C library which triggers an event as soon as a removable drive is detected.Thus,I had to use usb.h not libusb or any other open source library.Actually I am just a student doing internship in a reputed company but having no idea about event handling.Anyway thanks for the links. – Jay Jun 24 '11 at 12:06
  • 1
    Don't use HAL, it's officially dead; some distribution still have it roaming the system as a zombie (not the process state). – datenwolf Jun 24 '11 at 13:30
  • well going through all the links, writing udev rules seems to be the best solution.Do you have any idea on how to combine a script and C executable prpogram? – Jay Jun 25 '11 at 04:08
1

http://www.linuxjournal.com/article/8093 - A small overview about the linux USB system.

A library to communicate with the USB devices: http://sourceforge.net/projects/libusb/

check123
  • 1,989
  • 2
  • 22
  • 28
0

I think you should start by analysing libudev.

Daniel Băluţă
  • 1,255
  • 11
  • 13