Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 3 Oct 2019 09:42:56 +0300
From:      Oleksandr Rybalko <ray@ddteam.net>
To:        "O'Connor, Daniel" <darius@dons.net.au>
Cc:        freebsd-usb@freebsd.org
Subject:   Re: USB serial ports by serial number
Message-ID:  <CAJ1Oi8HeyBvn4UYSDAh8gGxj0hPv-vgFZ9ArNX95CTniuQa80g@mail.gmail.com>
In-Reply-To: <CC980A9B-8F41-4C2A-A729-2CC690DFDA7E@dons.net.au>
References:  <CC980A9B-8F41-4C2A-A729-2CC690DFDA7E@dons.net.au>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi,

Looks like you are lucky guy :)
Most of USB-serial devices have "very stable" serial number :)
more than 50% have S/N "0123456789".

So, sometime you change will do it's job.

IMO, better to track hub/port.

Thanks.


=D1=87=D1=82, 3 =D0=B6=D0=BE=D0=B2=D1=82. 2019 =D0=BE 05:56 O'Connor, Danie=
l <darius@dons.net.au> =D0=BF=D0=B8=D1=88=D0=B5:

> Hi,
> I have several USB serial ports on a machine and I don't want to rely on
> attach order to get various programs to talk to the correct serial port.
>
> I wrote the following devd script and shell script to create symlinks fro=
m
> cu.${sernum}/tty.${sernum} to the real device nodes.
>
> I post it here in the hope other people find it useful.
>
> [maarsytest 2:49] ~> cat /usr/local/etc/devd/usbserialsn.conf
> attach 100 {
>         device-name             ".*";
>         match "ttyname"         ".+";
>         match "ugen"            ".+";
>         match "sernum"          ".+";
>         action "/usr/local/libexec/usbserialsn attach $device-name $sernu=
m
> $ttyname";
> };
>
> detach 100 {
>         device-name             ".*";
>         action "/usr/local/libexec/usbserialsn detach $device-name";
> };
> [maarsytest 2:49] ~> cat /usr/local/libexec/usbserialsn
> #!/bin/sh
>
> if [ $# -lt 2 ]; then
>   echo "Bad usage"
>   exit 1
> fi
>
> mode=3D$1
> devname=3D$2
> sernum=3D$3
> ttyname=3D$4
>
> case "$mode" in
>   attach)
>     if [ $# -ne 4 ]; then
>       echo "Bad usage"
>       exit 1
>     fi
>     ln -sf cua${ttyname} /dev/cu.${sernum}
>     ln -sf tty${ttyname} /dev/tty.${sernum}
>     echo ${sernum} >/var/run/usbserialsn.${devname}
>     ;;
>
>   detach)
>     if [ $# -ne 2 ]; then
>       echo "Bad usage"
>       exit 1
>     fi
>     if [ ! -e /var/run/usbserialsn.${devname} ]; then
>       exit 0
>     fi
>     sernum=3D$(cat /var/run/usbserialsn.${devname})
>     rm -f /dev/cu.${sernum} /dev/tty.${sernum}
> /var/run/usbserialsn.${devname}
>     ;;
>
>   *)
>     echo "Unknown mode"
>     exit 1
>     ;;
> esac
>
> It would be a lot simpler if devd reported the same things on detach as i=
t
> does on attach but I am not sure how difficult that would be to achieve
> (presumably it would require caching them).
>
> --
> Daniel O'Connor
> "The nice thing about standards is that there
> are so many of them to choose from."
>  -- Andrew Tanenbaum
>
>
> _______________________________________________
> freebsd-usb@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-usb
> To unsubscribe, send any mail to "freebsd-usb-unsubscribe@freebsd.org"
>


--=20
WBW
-------
Rybalko Aleksandr <ray@ddteam.net>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ1Oi8HeyBvn4UYSDAh8gGxj0hPv-vgFZ9ArNX95CTniuQa80g>