LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 10-24-2006, 01:22 PM   #1
rhardy
LQ Newbie
 
Registered: Oct 2006
Posts: 2

Rep: Reputation: 0
user-space notification of USB device attached/detached


I have a user-space application that needs to be notified when a USB device has just been attached or detached (hot plugged/unplugged). Can someone tell me how to setup or register for such a notification? I'm running embedded linux 2.6.

I want to be notified of any type of USB device. But just for starters, I'm using a USB Memory Stick. I've loaded all of the necessary drivers:
modprobe ehci-hcd
modprobe usb-storage
modprobe sg
modprobe sd_mod
modprobe vfat
modprobe msdos
modprobe nls_iso8859-1
modprobe nls_cp437
and when I attach or detach the USB Memory Stick, I do see debug traces indicating the attachment/detachment. I can also manually mount the device (/dev/sda1) and read and write files on it. Now, I just need my user-space app to automatically get the attach/detach notifications so it knows when it can read and write the USB Memory Stick.

Thanks,
Ron

Last edited by rhardy; 10-24-2006 at 02:02 PM.
 
Old 10-24-2006, 03:17 PM   #2
studioj
Member
 
Registered: Oct 2006
Posts: 460

Rep: Reputation: 31
i'm just now trying to figure out how to do this the new way too but i think that hald exports some D-BUS signals like
void DeviceAdded(string udi)
void DeviceRemoved(string udi)

there appears to be wrappers for this stuff in lots of libs like glib and whatnot
i saw some python bindings that i coppied for further reference that looked loke this
Code:
hal_manager = dbus.Interface(hal_manager_obj,
                             'org.freedesktop.Hal.Manager')

hal_manager.connect_to_signal('DeviceAdded', device_added_callback)
you can also add signal recievers directly to the bus for services that are not registered already
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
getting the correct USB device for attached mobile phone drkstr Linux - Software 14 02-19-2008 04:14 AM
Retrieve write protect state of USB device in user space GeertPh Linux - Software 0 10-03-2006 01:25 AM
GMplayer Attached/Detached Skin sadarax Linux - Software 1 04-24-2006 07:15 AM
dm does not load if usb device attached grey man Mandriva 1 03-17-2006 10:48 AM
callback or notification from kernel to user space yhus Programming 5 09-18-2005 09:41 PM


All times are GMT -5. The time now is 10:44 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration