Date: Thu, 3 Oct 2019 16:26:37 +0930 From: "O'Connor, Daniel" <darius@dons.net.au> To: Oleksandr Rybalko <ray@ddteam.net> Cc: freebsd-usb@freebsd.org Subject: Re: USB serial ports by serial number Message-ID: <40CAFE90-B8F6-4A9B-A6D0-671D2DCEED52@dons.net.au> In-Reply-To: <CAJ1Oi8HeyBvn4UYSDAh8gGxj0hPv-vgFZ9ArNX95CTniuQa80g@mail.gmail.com> References: <CC980A9B-8F41-4C2A-A729-2CC690DFDA7E@dons.net.au> <CAJ1Oi8HeyBvn4UYSDAh8gGxj0hPv-vgFZ9ArNX95CTniuQa80g@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> On 3 Oct 2019, at 16:12, Oleksandr Rybalko <ray@ddteam.net> wrote: > Looks like you are lucky guy :) > Most of USB-serial devices have "very stable" serial number :) > more than 50% have S/N "0123456789". These are either FTDI (or possibly clones..) or a Micropython board so I = guess avoiding CH341s is paying off :) > So, sometime you change will do it's job. Yes, it should be possible but of course not if the manufacturer has = really cheaped out :( > IMO, better to track hub/port. No reason you couldn't do that (either instead or as well) with some = very basic script modifications. Perhaps I should have made /dev/usbserialbysn and put symlinks in that. > Thanks. >=20 >=20 > =D1=87=D1=82, 3 =D0=B6=D0=BE=D0=B2=D1=82. 2019 =D0=BE 05:56 O'Connor, = Daniel <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. >=20 > I wrote the following devd script and shell script to create symlinks = from cu.${sernum}/tty.${sernum} to the real device nodes. >=20 > I post it here in the hope other people find it useful. >=20 > [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 = $sernum $ttyname"; > }; >=20 > detach 100 { > device-name ".*"; > action "/usr/local/libexec/usbserialsn detach $device-name"; > }; > [maarsytest 2:49] ~> cat /usr/local/libexec/usbserialsn > #!/bin/sh >=20 > if [ $# -lt 2 ]; then > echo "Bad usage" > exit 1 > fi >=20 > mode=3D$1 > devname=3D$2 > sernum=3D$3 > ttyname=3D$4 >=20 > 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} > ;; >=20 > 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} > ;; >=20 > *) > echo "Unknown mode" > exit 1 > ;; > esac >=20 > It would be a lot simpler if devd reported the same things on detach = as it does on attach but I am not sure how difficult that would be to = achieve (presumably it would require caching them). >=20 > -- > Daniel O'Connor > "The nice thing about standards is that there > are so many of them to choose from." > -- Andrew Tanenbaum >=20 >=20 > _______________________________________________ > 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 >=20 > --=20 > WBW > ------- > Rybalko Aleksandr <ray@ddteam.net> >=20 -- Daniel O'Connor "The nice thing about standards is that there are so many of them to choose from." -- Andrew Tanenbaum
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?40CAFE90-B8F6-4A9B-A6D0-671D2DCEED52>