User Tools

Site Tools


howto:set_symlinks_for_usb_serial_ports

Why?

You might have multiple serial/USB converters connected to your box. And you would like to make sure that device focuser is at /dev/focuser, while filter wheel is at /dev/fwheel. Wild guesses of /dev/ttyUSBx will not work reliably once you will start to plug/unplug devices. And it is also nice to be able providing sensible names to serial ports, so you can debug your system quickly.

Recent Linux distributions uses udevd for assigning names to devices. There is a lot of documentation, but I found the following practical:

http://www.reactivated.net/writing_udev_rules.html

You do not read it fully, there are important parts in steps:

  • plug the device
  • run dmesg to see which port was created
  • run (as root, or using sudo):

<xterm2> root@host:~# udevadm info -a -p `udevadm info -q path -n <device>`

Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format. A rule to match, can be composed by the attributes of the device and the attributes from one single parent device.

looking at device '/devices/pci0000:00/0000:00:1a.7/usb1/1-5/1-5.3/1-5.3:1.0/ttyUSB0/tty/ttyUSB0':
  KERNEL=="ttyUSB0"
  SUBSYSTEM=="tty"
  DRIVER==""
looking at parent device '/devices/pci0000:00/0000:00:1a.7/usb1/1-5/1-5.3/1-5.3:1.0/ttyUSB0':
  KERNELS=="ttyUSB0"
  SUBSYSTEMS=="usb-serial"
  DRIVERS=="ftdi_sio"
  ATTRS{latency_timer}=="1"
  ATTRS{port_number}=="0"

</xterm2>

  • the text says all. Find some unique parameters in some parent device (but only one!). The good guesses are usually serial numbers etc. Then compose udev rule, and add it to /etc/udev/rules.d/10-tty-usb:
SUBSYSTEMS=="usb",ATTRS{serial}=="xxxx",SYMLINK+="focuser"

Of course change xxxx to what you get with udevadm.

  • You might need to restart udev, but just unplugging and replugging device should be enough.

When something fails

When you need to debug udev, the best to do is to run udevd in debug mode. As root, do

<xterm2> root@host:~# /etc/init.d/udev stop root@host:~# udevd –debug 1288130388.961886 [26940] udev_device_new_from_syspath: … </xterm2>

The udevd will print messages when you connect and disconnect devices - which rules are applied, … Most of them are easy to decode.

howto/set_symlinks_for_usb_serial_ports.txt · Last modified: 2011/08/04 00:00 (external edit)