I have an USB modem that I use on Ubuntu. I have also a program which communicate with this device using its ttyUSBxx
number.
My problem is that every time I unplug/plug the device again, or when I reboot my PC, the device gets a new ttyUSB
number, for example: ttyUSB0
or ttyUSB1
.
How can I force this device to always use the same number (say: ttyUSB0
)?
ttyUSB means "USB serial port adapter" and the "0" (or "1" or whatever) is the device number. ttyUSB0 is the first one found, ttyUSB1 is the second etc. (Note that if you have two similar devices, then the ports that they are plugged into may affected the order they are detected in, and so the names).
ttyUSB0 is the device for the first USB serial convertor. If you have an USB serial cable you'd be using a ttyUSBn to connect to the serial port of a router. ttyAMA0 is the device for the first serial port on ARM architecture.
udev
is Linux's dynamic device manager. udev
persists information about devices you plug in, and you can modify this information so that it adds a specific 'symlink' in the directory for this device.
Now, your usb modem's definition should be inside the folder /etc/udev/rules.d/
, and the filename will be something like 50-udev.rules
. The file contains one line per device, (you can use a number of tools to help identify the correct line. See below link on using udevinfo
)
Now, you can edit the relevant line, or even better, create another file and copy the relevant line into it. The filename should start with a lower number (e.g. 49-my-modem.rules
), so that it gets loaded first. You need to add the following to the end of the line:
, SYMLINK="ttyUSBmodem"
Now, your device should come up as /dev/ttyUSBmodem
(aswell as the dynamically assinged /dev/ttyUSB[0-9])
For more help with identifying the correct line and the whole process, see here: http://noctis.de/archives/16-HowTo-fixed-name-for-a-udev-device.html
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With