[<<][pool][>>][..]
Fri Dec 31 23:09:04 EST 2010

udev ttyUSB hack

Ok, I got it working.

Problem: somehow (on Debian?) the ID_SERIAL environment variable
that's available on the raw device doesn't get set for the
/class/tty/ttyUSB0 device that needs the symlink.

The following script will take a ttyUSB device path and traverse the
/sys tree to get at the serial number.  The rule:

KERNEL=="ttyUSB*", PROGRAM="ttyUSB_id %p", SYMLINK+="tty-%c"

EDIT: changes see [2].  Original script was:
----------------------------------------------------------------------------
#!/bin/bash

# This script is a helper for the following udev rule:
#
#   KERNEL=="ttyUSB*", PROGRAM="ttyUSB_id %p", SYMLINK+="tty-%c"
#
# It obtains the serial number associated to the raw USB device, which
# is not available from the ttyUSB device.  ( Original behaviour might
# be a bug, I don't know much about udev. )


# The device name is as it is passed to udev.
[ -z "$1" ] \
    && echo -e "usage:   $0 <device-name>\nexample: $0 /class/tty/ttyUSB0" \
    && exit 1

TTYDEV=$1
DIR1=/sys/$TTYDEV/device
DIR2=/sys/class/tty/$TTYDEV/device

if   [ -x $DIR1 ]; then cd $DIR1;
elif [ -x $DIR2 ]; then cd $DIR2;
else
    echo "Can't find $DIR1 nor $DIR2" >&2
    exit 1
fi

cd `pwd -P`
ID=`cat ../../serial`

echo $ID
exit 0


----------------------------------------------------------------------------
[1] http://zwizwa.be/darcs/pool/bin/ttyUSB_id
[2] entry://20110202-124334



[Reply][About]
[<<][pool][>>][..]