finding out which /dev/ttyUSBn device is which

I’m trying to set up a bash script which accesses a serial USB device. When
plugged in this device creates a /dev/ttyUSBn entry but, if I have multiple
/dev/ttyUSBn entries, is there any way of working out which USB device is
matched to which /dev entry?

Partly this is from trying to set up a USB modem on a laptop and then
connecting an old etrex GPS. The USB modem creates 3(!) /dev/ttyUSB entries
and the GPS 1 so I want to write a script which knows which one to access.

Alan

This is a good question. You want persistent naming for your usb device(s). This can be achieved by writing a custom rule for udev. You could create a rule in /etc/udev/rules.d, called 95-usb-modem.rules for example. It would look similar to this example

SUBSYSTEM=="tty", ATTRS{idVendor}=="12d01", ATTRS{idProduct}=="1001", SYMLINK+="modem"

Then whenever this particular device is plugged in, it will show up as /dev/modem (as well as /dev/ttyUSB*). You will need to identify the correct vendor and product codes for your device (with ‘lsusb’ or ‘lshal -m’ perhaps). The same principle applies for other devices. They all have unique attributes which can be used to identify them, and create a persistent name for them.

Useful references:

HintShop: Persistent names for usb-serial devices

FYI: persistent naming of USB serial devices

deano ferrari wrote:

>
> This is a good question. Say you want persistent naming for your modem.
> This can be achieved by writing a custom rule for udev. You could create
> a rule in /etc/udev/rules.d, called 95-usb-modem.rules for example. It
> would look like
>
>
> Code:
> --------------------
> SUBSYSTEM==“tty”, ATTRS{idVendor}==“12d01”, ATTRS{idProduct}==“1001”,
> SYMLINK+=“modem”
>
> --------------------
>
>
> Then whenever this particular device is plugged in, it will show up as
> /dev/modem (as well as /dev/ttyUSB*). You will need to identify the
> correct vendor and product codes for your device (with lsusb perhaps).
> The same principle applies for other devices. They all have unique
> attributes which can be used to identify them, and create a persistent
> name for them.
>
> Useful references:
>
> ‘HintShop: Persistent names for usb-serial devices’
> (http://tinyurl.com/27bd7cg)
>
> ‘FYI: persistent naming of USB serial devices’
> (http://mail.nl.linux.org/kernelnewbies/2008-06/msg00110.html)
>
>
Unfortunately the modem generate 3 tty devices :frowning:
If I used the code you suggest, which of the 3 tty devices gets symlinked to
modem?

Took me quite a while to set it up - it’s one of those modeswitching
thingies so I had to get usb_modeswitch to work on it. Then I found 3 ttyUSB
(0-2) devices and spent a while trying to get ttyUSB0 to work with wvdial.
Eventually I tried ttyUSB2 and that one did work.

The modem was on loan from my sister-in-law and it’s for use in Greece. I’m
back in the UK now and the modem has been returned to its owner but I’d like
to be able to set up some way of automating the connection which would mean
editing wvdial.conf with the correct ttyUSB device - if only I can work out
which one it is.

Alan

Unfortunately the modem generate 3 tty devices :frowning:
If I used the code you suggest, which of the 3 tty devices gets symlinked to
modem?

The custom udev rule will symlink the relevant modem device to /dev/modem, and the tty node may vary (dependent on what nodes have already been assigned). In reality, if the gps is not plugged in, then /dev/tty2 will probably be assigned to modem. This will let you see what /dev/modem is linked to:

ls -l /dev/modem

The very point of the udev rule is to have a unique persistent name (via symlink), so that software and scripts can point to that device only.

BTW, If you read man wvdial, you will see that /dev/modem is the default location the wvdial checks for modem presence. Thats why it makes sense to use udev to create the link automatically, based on detection of your modem hardware.

deano ferrari wrote:

>
>> Unfortunately the modem generate 3 tty devices :frowning:
>> If I used the code you suggest, which of the 3 tty devices gets
>> symlinked to
>> modem?
>
> The custom udev rule will symlink the relevant modem device to
> /dev/modem, and the tty node may vary (dependent on what nodes have
> already been assigned). In reality, if the gps is not plugged in, then
> /dev/tty2 will probably be assigned to modem. This will let you see what
> /dev/modem is linked to:
>
>
> Code:
> --------------------
> ls -l /dev/modem
> --------------------
>
>
> The very point of the udev rule is to have a unique persistent name
> (via symlink), so that software and scripts can point to that device
> only.
>
> BTW, If you read ‘man wvdial’ (http://linux.die.net/man/5/wvdial.conf),
> you will see that /dev/modem is the default location the wvdial checks
> for modem presence. Thats why it makes sense to use udev to create the
> link automatically, based on detection of your modem hardware.
>
>
Thanks - as the modem has gone back to its owner I can’t check all this out
ATM. I’ll keep hold of this info and try to implement it when I get access
to it again - now when can I go on holiday again :slight_smile:

Alan