I found this out sometime last year....
My distribution, and recent Ubuntu have default UDEV rules that try to fill
in as many blanks as they can and then mount the device in the /dev subidr.

For example:
A UART is placed in /dev/serial, and these have by-id and by-path subdirs:
Example
/dev/serial/by-id/usb-Silicon_Labs_CP2105_Dual_USB_to_UART_Bridge_Controller_0129A43F-if01-port0
A USB storage device is in /dev/disk
Example
/dev/disk/by-id/usb-SanDisk_Cruzer_Glide_20051740101DA47317F4-0:0-part1

The rules are nice because they're extensive in the names they give.
They're not so nice if you want a much shorter, but consistent, name.

Johnathan Mantey

On Mon, Jan 22, 2024 at 1:58 PM Vince Winter <[email protected]>
wrote:

> I will need to test but this may work.
>
> On Mon, Jan 22, 2024, 12:50 PM Tomas Kuchta <[email protected]>
> wrote:
>
> > Correction: recent kernels > 2.6 do not have ..../power/level --> use
> > .../power/control
> >
> > Or something like:
> > echo 1.4 /sys/bus/usb/drivers/usb/unbind
> >
> > -T
> >
> > On Mon, Jan 22, 2024, 15:42 Tomas Kuchta <[email protected]>
> > wrote:
> >
> > > While not answering your question - this may solve your problem...
> > >
> > > You can cut power to usb device by something like this:
> > >
> > > echo suspend > /sys/bus/usb/devices/usb1/power/level
> > >
> > > That way, you could just make sure that nothing draws power regardless
> of
> > > plugged in or not. It could save you from unplugging stuff manually
> based
> > > on some message.
> > >
> > > Hope it helps,
> > > Tomas
> > >
> > > On Mon, Jan 22, 2024, 15:12 Vince Winter <[email protected]>
> > > wrote:
> > >
> > >> We are running power testing and we need to make sure their isn't USB
> > >> device plugged in it adds to the total system power by having the USB
> > port
> > >> activate.
> > >>
> > >> I am trying to do a automated is USB plugged.
> > >>
> > >> We are using multiple generations of systems that are regularly
> > >> reinstalled.
> > >>
> > >>
> > >> On Mon, Jan 22, 2024, 9:42 AM Russell Senior <
> [email protected]
> > >
> > >> wrote:
> > >>
> > >> > I don't quite understand. You are looking for a specific device? How
> > do
> > >> you
> > >> > identify the device?
> > >> >
> > >> > On Mon, Jan 22, 2024 at 9:35 AM Vince Winter <
> > >> [email protected]>
> > >> > wrote:
> > >> >
> > >> > > I need if USB device is plugged to not to continue the rest of the
> > >> script
> > >> > > across multiple devices. I can't change every device and I am
> trying
> > >> to
> > >> > > eliminate humans looking at which devices are plugged in.
> > >> > >
> > >> > > I do conceded that many laptop cameras are USB and Bluetooth
> > generally
> > >> > runs
> > >> > > on the USB bus.
> > >> > >
> > >> > > I have yet to find a good answer to this myself.
> > >> > >
> > >> > > On Fri, Jan 19, 2024, 3:54 PM Russell Senior <
> > >> [email protected]>
> > >> > > wrote:
> > >> > >
> > >> > > > Two things I will mention: lsusb and udev rules.
> > >> > > >
> > >> > > > I have a set of udev rules that match ttyusb devices by path
> (they
> > >> > don't
> > >> > > > implement serial numbers, which would be better) and give them a
> > >> > > > consistently named symlink. I use /dev/ttyRn, where n is a whole
> > >> > number.
> > >> > > > That means no matter what order they are enumerated in, I can
> find
> > >> the
> > >> > > > device.
> > >> > > >
> > >> > > > I don't know if that helps with your problem or not, but I have
> > >> found
> > >> > > them
> > >> > > > to be useful in adjacent problems.
> > >> > > >
> > >> > > > --
> > >> > > > Russell
> > >> > > >
> > >> > > > On Fri, Jan 19, 2024, 15:17 Vince Winter <
> > >> [email protected]>
> > >> > > > wrote:
> > >> > > >
> > >> > > > > Hello,
> > >> > > > >
> > >> > > > > I am trying to write a bash script to detect if USB device is
> > >> plugged
> > >> > > > into
> > >> > > > > a device and post a message with a device name that is plugged
> > to
> > >> > > stdout.
> > >> > > > >
> > >> > > > > Complications are USB webcams, USB controllers, and this is
> > going
> > >> to
> > >> > be
> > >> > > > > used on large number of systems, so I can't customize to each
> > >> system.
> > >> > > > >
> > >> > > >
> > >> > >
> > >> >
> > >>
> > >
> >
>

Reply via email to