Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a modem with 16 ports using for sending SMS.

When it's connected to my Linux machine, I get 16 ports from ttyUSB0 to ttyUSB15. Currently if I remove this modem and attached another it,I get it 16 ports from ttyUSB0 to ttyUSB15.

How can I reserve first 16 ports for specific vendor with creating udev file, so when I remove this modem it and insert another one, it is assigned from ttyUSB16 onwards?

Edit

My udev rule file Contents are as follows, which is working but port number changes everytime I replug

Name=="Future Technology Devices International,Ltd",SUBSYSTEMS=="usb", ATTRS{idProduct}=="6011", ATTRS{idVendor}=="0403", SYMLINK="Ketan%b", KERNEL=="ttyUSB[0-15]*", MODE="0666", SYMLINK+="ttyUSB1",

Output

ls -l /dev/K*
lrwxrwxrwx 1 root root 7 2013-01-08 15:09 /dev/Ketan-8.1 -> ttyUSB1
lrwxrwxrwx 1 root root 7 2013-01-08 15:09 /dev/Ketan-8.2 -> ttyUSB5
lrwxrwxrwx 1 root root 8 2013-01-08 15:09 /dev/Ketan-8.3 -> ttyUSB11
lrwxrwxrwx 1 root root 8 2013-01-08 15:09 /dev/Ketan-8.4 -> ttyUSB12

Here ports are 16 but they are divided in Group of four. ttyUSB 1,5,11,12 Values are changing every time I Plug modem

share|improve this question
    
Does unbuffer udevadm monitor --environment | grep 'ID_SERIAL=' output different serial numbers for both modems when detaching/attaching it? –  jippie Jan 4 '13 at 13:09
add comment

1 Answer

If you loosen the requirement for using ttyUSB0 - ttyUSB31, then you may just have a possibility. What I've done is let udev create symlinks to the device nodes assigned by the kernel. You cannot reliably hardwire a physical device to use ttyUSB0, you can however reliably add a symlink ttyUSB001 to point to whichever device node you want. The trick here is that the kernel will never assign a device node a name that starts with ttyUSB0.., except for exactly ttyUSB0 itself. This trick therefore works for max 99 devices, but it can easily be changed to 4 digits (and 999 devices), as long as the first digit remains 0.

For this to work, you have to be able to uniquely identify both modems. Check if they have unique serial numbers by running this command while unplug/plug the device:

unbuffer udevadm monitor --environment | grep 'ID_SERIAL='

I don't know your modem, but this is the /etc/udev/rules.d/60-persistent-serial.rules file that I have been using to uniquely identify each of my Arduino's:

ACTION!="add", GOTO="persistent_serial_end"
SUBSYSTEM!="tty", GOTO="persistent_serial_end"
KERNEL!="ttyUSB[0-9]*", GOTO="persistent_serial_end"

# This is old 11.10 style: IMPORT="usb_id --export %p"
IMPORT{builtin}="path_id"
ENV{ID_SERIAL}=="04fc_RS232C_to_USB_Adapter"    , SYMLINK="multimeter"                                       , OWNER="jhendrix"
ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_A800FERY" , SYMLINK="arduinoMega1280-001"       , SYMLINK+="ttyUSB001" , OWNER="jhendrix"
ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_A900F4EF" , SYMLINK="arduinoMega1280-002"       , SYMLINK+="ttyUSB002" , OWNER="jhendrix"
ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_A900f3Kr" , SYMLINK="arduinoDuemilanove168-003" , SYMLINK+="ttyUSB003" , OWNER="jhendrix"

LABEL="persistent_serial_end"

Of course you have to replace a few things like OWNER, which is the user to which the devices are assigned and ENV{ID_SERIAL} which can be found by:

unbuffer udevadm monitor --environment | grep 'ID_SERIAL='

And last but not least the various SYMLINKs should be replaced by the exact name you want to use. This file makes any of my Arduino's available under three names (eg.):

/dev/ttyUSB0             # dynamic, assigned by kernel upon plugging the device
/dev/arduinoMega1280-002 # static,  symlink -> ttyUSB0
/dev/ttyUSB002           # static,  symlink -> ttyUSB0 , this is what you are asking for.

Check my private wiki article on this for more details.

share|improve this answer
    
As I create my rule file SUBSYSTEMS=="usb", ATTRS{idProduct}=="2303", ATTRS{idVendor}=="067b", SYMLINK="Ketan%b", KERNEL=="ttyUSB*", MODE="0666", works but I am not getting fix ports, I used your trick not working. All is well in my conf. But The port number changes everytime. I need to fix it. –  K.K Patel Jan 8 '13 at 8:13
    
Please share your file in your question. –  jippie Jan 8 '13 at 8:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.