LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-23-2013, 01:11 PM   #1
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Rep: Reputation: Disabled
Question catching a hot plug event linux


hie everyOne,

I have one device having (cypress)FX2LP for usb connectivity. and i have developed one code using cypress's CyUSB utility (which uses libusb wrapper) in Linux which displays the device descripotor of the device and logs it in log file.


but for this i have run the code. to get this. Actually i wanted to do like whenever i plug my device the code i have written should run automatically n logs the descriptors in file.

i know this can be done with kind of daemon process i am trying but i am not able to understand the things how to do this



please do rply i want to make it happen (i am working in linux)

regards
Rohan
 
Old 05-23-2013, 01:36 PM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

Not an expert on this, but it sounds like you want to make some udev rule.

http://www.linuxforu.com/2012/06/som...-and-examples/

Not sure how you can identify your device from others, but looking at dmesg after plugging it in can give a clue.
 
1 members found this post helpful.
Old 05-24-2013, 12:01 AM   #3
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Original Poster
Rep: Reputation: Disabled
Unhappy

Quote:
Originally Posted by Guttorm View Post
Hi

Not an expert on this, but it sounds like you want to make some udev rule.

http://www.linuxforu.com/2012/06/som...-and-examples/

Not sure how you can identify your device from others, but looking at dmesg after plugging it in can give a clue.
dear sir,

Thanks for your rply

i have one .config file and .rule file also so its detecting ma device n showing in dmesg but how can i run ma code whenever device gets connected. i know i am asking very specific ans but please do rply

here is ma .rule file

KERNEL=="*", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ACTION=="add", ATTR{idVendor}=="04b4", MODE="666", TAG="cyusb_dev", RUN+="/usr/bin/cy_renumerate.sh A"
KERNEL=="*", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ACTION=="remove", TAG=="cyusb_dev", RUN+="/usr/bin/cy_renumerate.sh R"

regards
rohan

Last edited by rohaanembedded; 05-24-2013 at 12:05 AM. Reason: added the .rule file for reference
 
Old 05-24-2013, 01:25 AM   #4
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Original Poster
Rep: Reputation: Disabled
helloOO everyone,

still need the help


regards
rohaan
 
Old 05-24-2013, 02:13 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
If you have an /sbin/hotplug program, the kernel might execute it, whenever something is plugged or unplugged (if not: echo /sbin/hotplug > /proc/sys/kernel/hotplug)
http://www.mjmwired.net/kernel/Docum...sb/hotplug.txt
 
1 members found this post helpful.
Old 05-24-2013, 02:39 AM   #6
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Original Poster
Rep: Reputation: Disabled
Question

Quote:
Originally Posted by NevemTeve View Post
If you have an /sbin/hotplug program, the kernel might execute it, whenever something is plugged or unplugged (if not: echo /sbin/hotplug > /proc/sys/kernel/hotplug)
http://www.mjmwired.net/kernel/Docum...sb/hotplug.txt
Dear sir,

i have written code using libusb n cyusb so right now i am not really working at kernel level

cant i run ma code(which diplays the device descriptors), using .rule file. taking event from there???

KERNEL=="*", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ACTION=="add", ATTR{idVendor}=="04b4", MODE="666", TAG="cyusb_dev", RUN+="/usr/bin/cy_renumerate.sh A"
KERNEL=="*", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ACTION=="remove", TAG=="cyusb_dev", RUN+="/usr/bin/cy_renumerate.sh R"

i tried to add another RUN+="usr/bin/run_code" in above rule like,

KERNEL=="*", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ACTION=="add", ATTR{idVendor}=="04b4", MODE="666", TAG="cyusb_dev", RUN+="/usr/bin/run_code.sh A"
KERNEL=="*", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ACTION=="remove", TAG=="cyusb_dev", RUN+="/usr/bin/run_code.sh R"

but the script didnt run on plugging of the device

script is
#!/bin/bash

echo "its running" > /home/ivb/cyusb_linux_1.0.3/rohan/log/desc_log.txt
~

please let me more about these RUN+= facility can i run multiple scripts thru this how?

thanking you for ur time n rply sir

Regards
rohan

Last edited by rohaanembedded; 05-24-2013 at 03:07 AM.
 
Old 05-24-2013, 03:26 AM   #7
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Original Poster
Rep: Reputation: Disabled
In need of your expert help

Anyone plz do help me

thanks & Regards
rohan
 
Old 05-24-2013, 04:52 AM   #8
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Original Poster
Rep: Reputation: Disabled
Unhappy need a help on this

i tried to run that script through lot of ways but it didnt work out. multiple use of RUN+= is very farr away its not even running my simple script shown above do help me about this

plzZZZZ sir anyone who knws this do rply
Thanks & Regards
Rohan
 
Old 05-24-2013, 05:34 AM   #9
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

How do you expect experts to solve your problem, when we can't even see what you're trying? What exactly are these udev rules? Post the rule files and use code tags.
 
1 members found this post helpful.
Old 05-24-2013, 05:54 AM   #10
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Original Poster
Rep: Reputation: Disabled
Unhappy

Quote:
Originally Posted by Guttorm View Post
Hi

How do you expect experts to solve your problem, when we can't even see what you're trying? What exactly are these udev rules? Post the rule files and use code tags.
sry sir i didnt mean only experts should solve my problem. i am learner so for me evryone is expert who shows me the way to try. i never meant it in a wrong way, sry again for my bad english.

i have one cypress USB controller device, and want run ma developed code on the plug of the device.

i am trying with .rule file in /etc/udev/rules.d/

Code:
KERNEL=="*", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ACTION=="add", ATTR{idVendor}=="04b4", MODE="666", TAG="cyusb_dev", RUN+="/usr/bin/Run_code.sh A"
KERNEL=="*", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ACTION=="remove", TAG=="cyusb_dev", RUN+="/usr/bin/run_code.sh R"
i want to run this script run_code.sh on every hot plug event
i know we can not run long execution program through this. so program has to detach itself but i am not getting sucuss in this

please consider my request n help me in this

Regards
rohan

Last edited by rohaanembedded; 05-24-2013 at 06:23 AM.
 
Old 05-24-2013, 07:20 AM   #11
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Original Poster
Rep: Reputation: Disabled
Smile

Thank you everybody for your replyz

i done with

ma device's vendorID got changed so it was not taking the plug event

thanks again

n thanks you Guttorm sir for advices me some points and udev rule
take care

Regards
rohan
 
  


Reply



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
catching wake-up event in C venu_s Linux - Software 1 09-15-2011 03:17 AM
catching the hibernate event sammy_aus Linux - Newbie 2 06-09-2010 09:11 AM
How to turn off hot plug?? msulik1 Linux - Laptop and Netbook 1 02-07-2006 01:42 PM
Hot plug mouse patch for Linux Ent 3 rooch84 Linux - Hardware 0 08-06-2004 04:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:13 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration