[IAEP] [Sugar-devel] Sugar Digest 2012-06-10
James Cameron
quozl at laptop.org
Tue Jun 12 21:15:01 EDT 2012
On Tue, Jun 12, 2012 at 06:25:09PM -0400, Kevin Mark wrote:
> [...]
> Thanks for writing notes for the XO-1/Launchpad. I think I noted
> some intermittent issues with the kernal/usb/Launchpad where it
> would create a /dev/TTYACM01 and then 02 (I dont recall the
> specifics) and when I tried to access the device via Python, my code
> was referrring to the wrong device node. And I had to disconnect
> the usb cable for it to work.
That reminds me. You can make your program resilient against this.
While people often say "plug in the device, then look for /dev/ttyACM0
or /dev/ttyUSB0", this is not necessarily the best device name to use
if you are writing a program.
There are alias device names that are more specific, and they don't
change as a result of suspend resume or the sequence in which the
devices are discovered, or plugged in.
For example, having plugged a USB serial adapter into an XO-1.75, I
see /dev/ttyUSB0, but I also see
/dev/serial/by-path/platform-pxau2o-ehci.0-usb-0:1.4:1.0-port0
which is an alias relating to what socket of the XO the device is
plugged into, and also
/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A4008sxO-if00-port0
which is an alias relating to what the device says about itself.
If a programmer wants their program to be resilient against the threat
of device name changes, then the program should be written to find the
alias and use that instead. A Python program can search /dev/serial
for a symbolic link that points to what it is given, so that if it
changes it can offer to the user the new device name.
These aliases are also very useful for scripts and configuration files.
For interactive use, the aliases are a bit long, but using tab at the
shell prompt will complete them if enough letters are typed.
e.g.
bash$ ls /dev/se <tab> by-i <tab> <tab>
is enough to select the only one there.
Hope that helps.
--
James Cameron
http://quozl.linux.org.au/
More information about the IAEP
mailing list