On 5/20/07, Jon Hylands <jon@huv.com> wrote:

Hi everyone,

On my current robotics project, I'm using a gumstix verdex to talk over a
USB to serial converter chip (FT232) to a serial bus.

My brother Dave made up a new kernel driver for the gumstix, and when I
plug in the chip it registers itself as ttyUSB0.

For work I've done previously on Squeak on the gumstix, I've used standard
serial ports, which map to ttyS0, ttyS1, ttyS2, etc, which correspond to
port 0, 1, and 2 when I open the Serial Port in Squeak. However, I have no
idea which port number ttyUSB0 corresponds to...

Anyone got any idea?


I have to scratch this itch :-). This is something I should know but don't.

At a guess, I'd say this is your answer, from usb-serial.c in the Linux kernel:

static struct usb_serial *get_free_serial (struct usb_serial *serial, int num_ports, unsigned int *minor)
{
    unsigned int i, j;
    int good_spot;

    dbg("%s %d", __FUNCTION__, num_ports);

    *minor = 0;
    for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
        if (serial_table[i])
            continue;

        good_spot = 1;
        for (j = 1; j <= num_ports-1; ++j)
            if ((i+j >= SERIAL_TTY_MINORS) || (serial_table[i+j])) {
                good_spot = 0;
                i += j;
                break;
            }
        if (good_spot == 0)
            continue;

        *minor = i;
        dbg("%s - minor base = %d", __FUNCTION__, *minor);
        for (i = *minor; (i < (*minor + num_ports)) && (i < SERIAL_TTY_MINORS); ++i)
            serial_table[i] = serial;
        return serial;
    }
    return NULL;
}

I'm assuming that serial_table[] is a list of the ttyUSBn ports, and this just finds a free one starting from ttyUSB0, but somebody smarter than me is going to have to verify this.

Also mentioned somewhere is that the device allocation will appear in the system logs. That's a pretty disgusting way to find the device mappings. Another way would be to iterate through the /dev/ttyUSB*'s to find your device which I find equally disgusting. It's probably easiest to simply assume that it is always /dev/ttyUSB0 or /dev/usb/tts/0 if you're using devfs.

Did Dave write the code, or did he simply compile it? It sounds like he'd be the person to ask, and I'm surprised he didn't make a /dev/microraptor for you :-).

Michael.
p.s. I've seen a video of your raptor - it rocks!