Re: USB serial ports by serial number

2019-11-19 Thread Hans Petter Selasky

On 2019-10-08 16:20, Ed Maste wrote:

On Thu, 3 Oct 2019 at 02:43, Oleksandr Rybalko  wrote:


Hi,

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


cp210x USB-serial devices are ubiquitous and cheap and it's easy to
set the serial number.

I have a trivial port of the 'cp210x-cfg' tool at
https://github.com/emaste/cp210x-cfg.


Hi,

How about the following:

We can add a TUNEABLE search to every USB device attach, which if set, 
will serve as the base unit number for that device.


Then you could simply add to /boot/loader.conf :

hint.usb.0.1.1.1.0.unit=128
hint.usb.0.1.1.2.0.unit=129

These numbers can be printed by usbconfig for example, based on:

1) Host controller number [0..xxx]
2) Array of USB port numberr [1.255]
3) Interface index number [0..xxx]

To help setting up the system.

--HPS
___
freebsd-usb@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


Re: USB serial ports by serial number

2019-10-08 Thread Ed Maste
On Thu, 3 Oct 2019 at 02:43, Oleksandr Rybalko  wrote:
>
> Hi,
>
> Looks like you are lucky guy :)
> Most of USB-serial devices have "very stable" serial number :)
> more than 50% have S/N "0123456789".

cp210x USB-serial devices are ubiquitous and cheap and it's easy to
set the serial number.

I have a trivial port of the 'cp210x-cfg' tool at
https://github.com/emaste/cp210x-cfg.
___
freebsd-usb@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


Re: USB serial ports by serial number

2019-10-03 Thread Hans Petter Selasky

Hi,

Can you try this patch:

https://reviews.freebsd.org/D21886

--HPS
___
freebsd-usb@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


Re: USB serial ports by serial number

2019-10-03 Thread Hans Petter Selasky

On 2019-10-03 10:13, O'Connor, Daniel wrote:




On 3 Oct 2019, at 17:41, Hans Petter Selasky  wrote:

On 2019-10-03 09:37, O'Connor, Daniel wrote:

On 3 Oct 2019, at 17:01, Hans Petter Selasky  wrote:
On 2019-10-03 08:56, O'Connor, Daniel wrote:

Most of USB-serial devices have "very stable" serial number:)
more than 50% have S/N "0123456789".


It is also allowed to have no serial number.

Yes, that's why I match sernum to '.+' to skip those.

Maybe some kind of "lstty" would do.

-l  -  list all devices
-s  -  match by serial
-v  -  match by vendor
-p  -  match by product
-i  -  match by interface ID
-t  -  type [USB/PCI]

which simply output the tty number you need. Could be an API we could add to 
libusb.

The problem is you can't modify some program to call a new API a lot of the 
time but it is usually trivial to change which serial port it's configured to 
use.


You don't need to change any program:

cu /dev/cuaU`lstty -s SERIAL`


That doesn't work in a lot of cases, eg serial port is in some other 
configuration file.

Even in rc.conf it would be tricky since that file is read so often.



How about that we build the cuaX unit number by the location, and have a 
sysctl for that?


unit = 0;
while (hubdepth--) {
  unit *= numports;
  unit += portno - 1;
}
unit *= maxifaces;
unit += device_get_unit(x);

Typically this should fit into a 32-bit integer, but we could also use a 
64-bit integer.


--HPS
___
freebsd-usb@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


Re: USB serial ports by serial number

2019-10-03 Thread O'Connor, Daniel



> On 3 Oct 2019, at 17:41, Hans Petter Selasky  wrote:
> 
> On 2019-10-03 09:37, O'Connor, Daniel wrote:
>>> On 3 Oct 2019, at 17:01, Hans Petter Selasky  wrote:
>>> On 2019-10-03 08:56, O'Connor, Daniel wrote:
 Most of USB-serial devices have "very stable" serial number:)
 more than 50% have S/N "0123456789".
>>> 
>>> It is also allowed to have no serial number.
>> Yes, that's why I match sernum to '.+' to skip those.
>>> Maybe some kind of "lstty" would do.
>>> 
>>> -l  -  list all devices
>>> -s  -  match by serial
>>> -v  -  match by vendor
>>> -p  -  match by product
>>> -i  -  match by interface ID
>>> -t  -  type [USB/PCI]
>>> 
>>> which simply output the tty number you need. Could be an API we could add 
>>> to libusb.
>> The problem is you can't modify some program to call a new API a lot of the 
>> time but it is usually trivial to change which serial port it's configured 
>> to use.
> 
> You don't need to change any program:
> 
> cu /dev/cuaU`lstty -s SERIAL`

That doesn't work in a lot of cases, eg serial port is in some other 
configuration file.

Even in rc.conf it would be tricky since that file is read so often.

--
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-unsubscr...@freebsd.org"


Re: USB serial ports by serial number

2019-10-03 Thread Hans Petter Selasky

On 2019-10-03 09:37, O'Connor, Daniel wrote:




On 3 Oct 2019, at 17:01, Hans Petter Selasky  wrote:
On 2019-10-03 08:56, O'Connor, Daniel wrote:

Most of USB-serial devices have "very stable" serial number:)
more than 50% have S/N "0123456789".


It is also allowed to have no serial number.


Yes, that's why I match sernum to '.+' to skip those.


Maybe some kind of "lstty" would do.

-l  -  list all devices
-s  -  match by serial
-v  -  match by vendor
-p  -  match by product
-i  -  match by interface ID
-t  -  type [USB/PCI]

which simply output the tty number you need. Could be an API we could add to 
libusb.


The problem is you can't modify some program to call a new API a lot of the 
time but it is usually trivial to change which serial port it's configured to 
use.



You don't need to change any program:

cu /dev/cuaU`lstty -s SERIAL`

--HPS

___
freebsd-usb@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


Re: USB serial ports by serial number

2019-10-03 Thread O'Connor, Daniel



> On 3 Oct 2019, at 17:01, Hans Petter Selasky  wrote:
> On 2019-10-03 08:56, O'Connor, Daniel wrote:
>> Most of USB-serial devices have "very stable" serial number:)
>> more than 50% have S/N "0123456789".
> 
> It is also allowed to have no serial number.

Yes, that's why I match sernum to '.+' to skip those.

> Maybe some kind of "lstty" would do.
> 
> -l  -  list all devices
> -s  -  match by serial
> -v  -  match by vendor
> -p  -  match by product
> -i  -  match by interface ID
> -t  -  type [USB/PCI]
> 
> which simply output the tty number you need. Could be an API we could add to 
> libusb.

The problem is you can't modify some program to call a new API a lot of the 
time but it is usually trivial to change which serial port it's configured to 
use.

--
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-unsubscr...@freebsd.org"


Re: USB serial ports by serial number

2019-10-03 Thread Hans Petter Selasky

On 2019-10-03 08:56, O'Connor, Daniel wrote:

Most of USB-serial devices have "very stable" serial number:)
more than 50% have S/N "0123456789".


It is also allowed to have no serial number.

Maybe some kind of "lstty" would do.

-l  -  list all devices
-s  -  match by serial
-v  -  match by vendor
-p  -  match by product
-i  -  match by interface ID
-t  -  type [USB/PCI]

which simply output the tty number you need. Could be an API we could 
add to libusb.


--HPS
___
freebsd-usb@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


Re: USB serial ports by serial number

2019-10-03 Thread O'Connor, Daniel


> On 3 Oct 2019, at 16:12, Oleksandr Rybalko  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.
> 
> 
> чт, 3 жовт. 2019 о 05:56 O'Connor, Daniel  пише:
> 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 from 
> 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 $sernum 
> $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=$1
> devname=$2
> sernum=$3
> ttyname=$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=$(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 it 
> 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-unsubscr...@freebsd.org"
> 
> 
> -- 
> WBW
> ---
> Rybalko Aleksandr 
> 

--
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-unsubscr...@freebsd.org"


Re: USB serial ports by serial number

2019-10-03 Thread Oleksandr Rybalko
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.


чт, 3 жовт. 2019 о 05:56 O'Connor, Daniel  пише:

> 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 from
> 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 $sernum
> $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=$1
> devname=$2
> sernum=$3
> ttyname=$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=$(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 it
> 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-unsubscr...@freebsd.org"
>


-- 
WBW
---
Rybalko Aleksandr 
___
freebsd-usb@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


USB serial ports by serial number

2019-10-02 Thread O'Connor, Daniel
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 from 
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 $sernum 
$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=$1
devname=$2
sernum=$3
ttyname=$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=$(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 it 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-unsubscr...@freebsd.org"