Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support stable serial device IDs on linux and maybe netbsd? #12

Open
DanielJoyce opened this issue Jul 9, 2023 · 3 comments
Open

Support stable serial device IDs on linux and maybe netbsd? #12

DanielJoyce opened this issue Jul 9, 2023 · 3 comments

Comments

@DanielJoyce
Copy link

Many linux distros support /dev/serial/by-id which is stable on device plug/unplug. It would be nice to support this as well when enumerating devices.

@de-vri-es
Copy link
Owner

de-vri-es commented Sep 11, 2023

Hey! It could be nice indeed. The only thing I'm considering is how to structure the API.

Should the current API simply be adjusted to add stable devices? Or should it be a separate new API? Should that one also include devices that don't have a stable device path?

And I think that directory is populated by udev. What about systems that don't have that directory? Should we fall back to non-stable device paths?

@bofh69
Copy link

bofh69 commented Nov 24, 2023

For USB serial ports it is also possible to get stable names on macOS. A former colleague wrote this code in a script:

    ioreg -r -c IOUSBHostDevice -l -n "USB Device Name Here" | \
    grep -w 'IODialinDevice' | \
    awk -F'=' '{print $2}'| \
    sed -E -e 's/[ "]//g' | \
    sort | \
    head -n 1 | \
    tr -d '\n'

I don't have a modern mac so I can't really help with that though.

Anyway, I would go for a new API for this, returning a Result<Vec<(PathBuf, Option<String>)>>.

With the first being a normal "/dev/ttyACMx"/"COM0"/"/dev/ttyusb.123" etc and the second being the device name when available or None.

On my machine I have:

/dev/serial/by-id/usb-SEGGER_J-Link_emulator_001050286728-if00 -> ../../ttyACM1
...

I would expect something like Ok(["/dev/ttyACM1", Some("usb-SEGGER_J-Link_emulator_001050286728-if00"), ...]) as the result of that function call.

EDIT: Or maybe without the "usb-" prefix. It would be really nice if the device names could be the same on multiple platforms. I've got a program (otii-measurement) that talks to a Otii Arc energy analyzer. Currently I've got its usual linux device name (/dev/serial/by-id/usb-Qoitech_Arc-if00) as the default device parameter in my program, but it would be nice if I could find the right device on all platforms given the device name instead. There I suspect the "usb-" prefix is only available on linux.

@de-vri-es
Copy link
Owner

I like the idea of providing a path and additional information separately.

Maybe we should immediately use a SerialPortInfo struct for the information, so we can add more information in the future without breaking the API.

@de-vri-es de-vri-es mentioned this issue Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants