Linux usb ports

Linux specific questions.
Post Reply
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Linux usb ports

Post by speedfixer »

Windows tries to keep the same port name when a USB device is plugged in. Usually a good thing, sometimes not.

Linux just hands out a logical port assignment. Sometimes it isn't the one you expect. There are ways of locking down the port name, but it isn't worth the effort. And can be a pain later if you forget, AND forgot how you did this.

I use this to locate my USB device. In this case, the device is one of my Raspberry Pis.

Code: Select all

dim as string result
dim as integer fnum

fnum = freefile
open pipe "ls -l /dev/serial/by-id |grep FTDI" for input as #fnum
line input #fnum, result
close fnum

if instr(result, "FTDI_FT232R_USB_UART_A60275PX") <> 0 then
    fnum = instrrev(result, "tty")
    result = right(result,  len(result) - fnum - 2)
end if
print result
Result: USB0
or USB1, sometimes. My program can deal with info as I wish.


These commands are helpful to locate the info you need to do this.

lsusb
udevadm info -q all /dev/ttyUSB0 | grep DEVPATH
ls -l /dev/serial/by-id
udevadm info -q all /dev/ttyUSB* | grep DEVNAME


Either way, my program does not have to be recompiled/restarted or wait for a timeout and try an alternate to connect to the device.

david
Post Reply