Linux usb ports

Linux specific questions.
Posts: 398
Joined: Nov 28, 2012 1:27
Location: California

Linux usb ports

Postby speedfixer » Aug 18, 2019 6:55

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.

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.


Return to “Linux”

Who is online

Users browsing this forum: No registered users and 2 guests