USB serial ports by serial number
Hans Petter Selasky
hps at selasky.org
Thu Oct 3 10:42:18 UTC 2019
On 2019-10-03 10:13, O'Connor, Daniel wrote:
>
>
>> On 3 Oct 2019, at 17:41, Hans Petter Selasky <hps at selasky.org> wrote:
>>
>> On 2019-10-03 09:37, O'Connor, Daniel wrote:
>>>> On 3 Oct 2019, at 17:01, Hans Petter Selasky <hps at selasky.org> 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
More information about the freebsd-usb
mailing list