LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Recognizing USB insertion/removal in Python (https://www.linuxquestions.org/questions/programming-9/recognizing-usb-insertion-removal-in-python-838269/)

J.Richardus 10-15-2010 08:47 AM

Recognizing USB insertion/removal in Python
 
Hi all,

How can I understand if a USB inserted or removed. I don't know where to start so any help would be appreciated.

Someone said I need to study HAL. Is it true? If so I need some links, source code etc. do you know any?

Thanks in advance...

PhantasyConcepts 10-15-2010 11:08 AM

Changes in hardware configuration are hardware based.
 
First of all, you cannot truly detect any hardware configuration through your scripting. You can probe for it, but the operating system kernel detects hardware changes like that. I would suggest probing /dev/usb for changes (or whatever your distro calls the usb device). Another thing to try is to execute an lsusb -v command, at the beginning and just pipe the output to grep for your search string. Python can execute system commands.

If you are, however, writing a device driver, write it in C first of all, and then you would want to take a look at the HAL API and the kernel source code.


All times are GMT -5. The time now is 08:04 AM.