Is it possible to hard code a USB component to a ttyUSB device?
FedoraThis forum is for the discussion of the Fedora Project.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is it possible to hard code a USB component to a ttyUSB device?
I have two USB devices, one a USB 3g modem and the other a GPS receiver.
On boot more often than not the modem will get ttyUSB0, which allows me to configure my wvdial.conf nicely for it. But every so often the GPS receiver gets ttyUSB0 instead and breaks my startup scripts.
Questions:-
1) Is it possible to hard code a USB device to a ttyUSB device rather than the system deciding?
2) Which process/application of Linux is responsible for deciding which device gets which tty device? From /var/log/messages it looks like its the kernel making the decision, but is it configurable?
Distribution: Distribution: RHEL 5 with Pieces of this and that.
Kernel 2.6.23.1, KDE 3.5.8 and KDE 4.0 beta, Plu
Posts: 5,700
Rep:
I would say it is possible. If your system is using say udev and hal then you can create a udev rule to point that specific ID of device to a patrialar device block. I am not sure on how to exactly but there are post on it and also googling for udev rules may help as well.
Thanks Brian, I created a udev rule as suggested that created a simple symlink for the USB device. This gave me a unique tty device to work with in my scripts.
My issue was, I had two USB devices that I needed to contact via scripts. The problem was, each time the machine boot'd I wasn't sure which device was given to what ttyUSB device and it changed quite often breaking my scripts.
The solution I used was to get udev to look for the device by its vendor and product id. You can view these with the command lsusb. In the example below, 067b would be the idVendor value and 2303 the idProduct value.
[root@simmo ~]# lsusb
Bus 001 Device 001: ID 0000:0000
Bus 002 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000
Bus 004 Device 002: ID 067b:2303
I then created a udev rule in /etc/udev/rules.d/99.anything.rules that contained the line below.
Check that ownership and permissions are the same as the other rules in this directory after you've saved it.
I had to reboot for this rule to be picked up correctly.
What this does is is create a device called /dev/gps which is actually a symbolic link to whichever /dev/ttyUSB device Linux gave the USB GPS device on boot. This allows me to use /dev/gps in my scripts and means I don't have to worry about working out which ttyUSB device each USB device uses.
This can of course be used for multiple devices by creating more udev rules.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.