LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-20-2012, 12:08 AM   #1
akash2happy
LQ Newbie
 
Registered: Jan 2012
Posts: 2

Rep: Reputation: Disabled
Problem Using Udev Rule


Hello,
I am using headless Ubuntu 11.04 running on BeagleBoard XM.
Everytime i reboot the system ttyUSB[x] port_number change i want to use that port number in my C program for particular device.
Is it possible in udev rule so that we assign (ttyUSB[x])
the value of x for particular device. Whenever I connect usb to any port it will assign the port number that i have given.
if it is possible please help me with the code......
 
Old 01-20-2012, 05:48 AM   #2
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 303

Rep: Reputation: 32
I suppose your /dev/ttyUSB* comes from minicom serial port, which will very from time to time.

And I fear we can't handle this from udev rules.
But you can initialte your code from some script:
Code:
Your script :
================
if [ -f /dev/ttyUSB0] then
./urcode /dev/ttyUSB0
else if [ -f /dev/ttyUSB1] then
./urcode /dev/ttyUSB1

In ur C-program:
=================
accept device node as argument (int main(int argc, char *argv) ).
there might be other ways to do so.
 
Old 01-20-2012, 08:31 AM   #3
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.
I'm not very familiar with udev, so there may be inaccuracies.
First you need to find a pair of numbers idVendor:idProduct which correspond to your usb device (such as usb-tty converter). Say, I have a Logitech usb mouse and I want udev to create /dev/logitech_mouse each time I plug it in.
To identify the device, type
Code:
$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 028: ID 064e:a102 Suyin Corp. Acer/Lenovo Webcam [CN0316]
Bus 003 Device 002: ID 138a:0001 Validity Sensors, Inc. VFS101 Fingeprint Reader
Bus 003 Device 007: ID 0a5c:2151 Broadcom Corp. Bluetooth
Bus 005 Device 004: ID 046d:c062 Logitech, Inc. 
So, for my mouse, idVendor=046d and idProduct=c062.

Now, to create udev rule I open /etc/udev/rules.d/99-local.rules and put there something like this
Code:
# Logitech mouse, example
SUBSYSTEMS=="usb", ATTRS{idProduct}=="c062", ATTRS{idVendor}=="046d", NAME="%k", SYMLINK+="logitech_mouse", MODE="0660"
To restart udev type
Code:
sudo /etc/init.d/udev restart
Hope this helps.

EDIT: Note that udev rules cannot span multiple lines.

Last edited by firstfire; 01-28-2012 at 01:14 AM.
 
1 members found this post helpful.
Old 01-23-2012, 01:44 AM   #4
akash2happy
LQ Newbie
 
Registered: Jan 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by barunparichha View Post
I suppose your /dev/ttyUSB* comes from minicom serial port, which will very from time to time.

And I fear we can't handle this from udev rules.
But you can initialte your code from some script:
Code:
Your script :
================
if [ -f /dev/ttyUSB0] then
./urcode /dev/ttyUSB0
else if [ -f /dev/ttyUSB1] then
./urcode /dev/ttyUSB1

In ur C-program:
=================
accept device node as argument (int main(int argc, char *argv) ).
there might be other ways to do so.
thanku barunparichha
 
  


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
problem with udev rule on fedora 15 blue_bob Linux - Hardware 5 05-10-2012 07:55 PM
udev rule problem with 12.2 conundrum07 Slackware 8 01-04-2009 12:04 PM
udev rule: need help DPenguin Linux - Hardware 0 08-04-2008 07:29 PM
Udev Rule Help Please Toods Slackware 1 11-23-2007 08:55 AM
need help with udev rule hussam Linux - Software 2 12-05-2006 03:30 AM

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

All times are GMT -5. The time now is 11:39 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