Linux: serial port enumeration suggestion

Hello,

I'm running Arduino-008 on a Linux box (2.6 kernel), and as I have a number of USB serial devices I use local udev rules to manage the device naming. Without udev, I get a number of ttyUSB* devices, and I can't tell which is which (and worse they are renumbered whenever I plug/unplug them).

e.g. part of my /etc/udev/rules.d/10-local.rules

# BitScope DSO
#KERNEL=="ttyUSB*", SYSFS{serial}=="BSCVFO61", SYMLINK+="dso"
KERNEL=="ttyUSB*", SYSFS{serial}=="BSCVFO61", NAME="dso"

# Arduino(s) (only thing to go on is serial nos.)
KERNEL=="ttyUSB*", SYSFS{serial}=="A40014Oo", SYMLINK+="arduino0"
KERNEL=="ttyUSB*", SYSFS{serial}=="A5001afj", SYMLINK+="arduino1"

This sets the device name for my BitScope DSO, which uses an FTDI USB-serial device, to /dev/dso (thus it doesn't get accidentally picked up by arduino); it also creates symlinks from the default ttyUSB* name to arduino0 and arduino1 (no matter what order I plug them in).

~$ ls -l /dev/dso* /dev/ttyUSB* /dev/arduino*
lrwxrwxrwx 1 root root         7 2007-07-09 23:25 /dev/arduino0 -> ttyUSB0
crw-rw---- 1 root dialout 188, 1 2007-07-09 22:57 /dev/dso
crw-rw---- 1 root dialout 188, 0 2007-07-09 23:25 /dev/ttyUSB0

This is all good, except Arduino doesn't notice my symlinks - it only seems to detect devices named ttyS* or ttyUSB*. (I tried using NAME="arduino0" which renames the e.g. /dev/ttyUSB0 device to /dev/arduino0, but that didn't show up at all).

Anyhow, I don't know how arduino-0008 detects candidate serial ports, but under Linux a good way would be to look for character devices with appropriate major + minor device ids, e.g.
http://www.lanana.org/docs/device-list/

Major  Minor
  4    64-255    UAR serial ports
 188  0-255          USB serial

(there are others for multi-port serial cards, etc).

Thanks for the great work,
Ben

Arduino uses RXTX (http://www.rxtx.org/) for its serial communication and port enumeration, so it might be best to make this suggestion to them. We can always patch their code, of course, but that can get messy, especially for people on Linux who might be installing it themselves. It's definitely a good suggestion though - port enumeration (and detection of the Arduino) is one of those things that we should be doing better.

I've sent the suggestion to the rxtx mailing list.

Thanks,
Ben

Cool. I hope they take it.

In the mean time, maybe try an alias like "ttyUSBarduinoX"? It's a bit long, but it's unique to the arduino.

I really like the way the FTDI drivers on the mac operate - if the device has a serial number, the device special file is /dev/tty.serialnumber. Always unique, always ahow up with the same name no matter when or where you plug them in.

-j

Yea, although it would be nice if the serial numbers didn't have any non-printing characters in them.

it would be nice if the serial numbers didn't have any non-printing characters in them.

Yeah, that's no fun.

If you have access to a windows box, you can download a windows-only utility from FTDI to assign/change the serial number. It's not exactly straighforward, but I have used it to assign serial numbers to unserialized devices (that are completely unrelated to the Arduino, I should add).

-j

That's cool. Do you know the name of the utility or how to use it? That would be great for people having trouble talking to the Arduino with serproxy or other programs that need to know the name of the device. It would be cool have that written up on the playground.

The name of the utility is MProg. It's mentioned on this web page, the current download link is here. It isn't terribly straightforward, and IIRC required loading the FTDI "direct" driver, which is readily available but not the driver people generally use (the VCP - virtual com port - driver is more common.)

When I get the current project out of the way I'll try to make time to assign a new serial number to my Arduino just for fun, and document it along the way. I can't take a chance on bricking it just now. :slight_smile:

-j

Awesome, thanks for the info, it'd be great if you can try it out when you have a chance.