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

Scan machine port to /dev/serial/by-id/whatever if available (eg on Linux) #789

Closed
JasonWoof opened this issue Jul 26, 2017 · 3 comments · Fixed by #1510
Closed

Scan machine port to /dev/serial/by-id/whatever if available (eg on Linux) #789

JasonWoof opened this issue Jul 26, 2017 · 3 comments · Fixed by #1510
Milestone

Comments

@JasonWoof
Copy link

Classification: Feature (New)

This is a feature request for Linux, though there might be other systems that could benefit from this.

The issue: when I unplug my ErgoDox, then plug it in again, it gets a different path in /dev so I have to open Plover settings, go to the machine tab, scan and ok it every time.

Today I realized that there might be a path in /dev that is the same (always points to my ErgoDox) and there is, it's /dev/serial/by-id/usb-ErgoDox_EZ_ErgoDox_EZ-if03 in my case.

Now that I've put that in my settings, I'm hopefully all set.

My feature request is to have Plover use this path automatically when it scans, instead of the far more ephemeral /dev/ttyACM0 or whatnot.

P.S. The former path is a link to the latter, i.e.:

$ ls -l /dev/serial/by-id/usb-ErgoDox_EZ_ErgoDox_EZ-if03
lrwxrwxrwx 1 root root 13 Jul 26 00:01 /dev/serial/by-id/usb-ErgoDox_EZ_ErgoDox_EZ-if03 -> ../../ttyACM0
@benoit-pierre
Copy link
Member

I'd be interested to know what ports are listed after updating to pyserial 3.4 and applying the following patch:

 plover/gui_qt/machine_options.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git i/plover/gui_qt/machine_options.py w/plover/gui_qt/machine_options.py
index 63dbc3b9..ebe87daf 100644
--- i/plover/gui_qt/machine_options.py
+++ w/plover/gui_qt/machine_options.py
@@ -54,7 +54,7 @@ class SerialOption(QWidget, Ui_SerialWidget):
 
     def on_scan(self):
         self.port.clear()
-        self.port.addItems(sorted(x[0] for x in comports()))
+        self.port.addItems(sorted(x[0] for x in comports(include_links=True)))
 
     def on_port_changed(self, value):
         self._update('port', value)

@JasonWoof
Copy link
Author

Thanks for looking into this!

Here's my transcript:

$ python3
Python 3.5.4 (default, Sep  5 2017, 18:32:10)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> serial.__version__
'3.4'
>>> from serial.tools.list_ports import comports
>>> [[x[0], x[1], x[2]] for x in comports(include_links=True)]
[['/dev/ttyACM0', 'ErgoDox EZ', 'USB VID:PID=FEED:1307 LOCATION=2-1:1.3']]

Maybe comports/include_links doesn't recurse into the subdirs of /dev

I'm seeing three symbolic links to /dev/ttyACM0 in /dev:

$ find /dev/ -type l -print0 | xargs -0 ls -l | grep ACM0
[...] /dev/char/166:0 -> ../ttyACM0
[...] /dev/serial/by-id/usb-ErgoDox_EZ_ErgoDox_EZ-if03 -> ../../ttyACM0
[...] /dev/serial/by-path/pci-0000:00:1d.1-usb-0:1:1.3 -> ../../ttyACM0

I have no idea what that first one is.

The second one I like very much, and think should be the default.

The third one is interesting... It does seem to map to a particular USB port. I moved my ErgoDox to different USB ports and just the digit before "-usb" changed (and it changed back to "1-usb" when I put it back to where it was originally plugged in.) Somebody might like to configure their Plover to connect to "whatever is plugged into the that front/right USB port". But I'm not concerned with this use case.

@benoit-pierre
Copy link
Member

Yeah, the implementation of comports/include_links unfortunately looks only in /dev, no recursion.

I think the real issue is Plover not detecting the removal, keeping the device open, hence the new device name on re-plug.

Seeing as the information returned by comports for each port includes a description and hardware ID, maybe we should display this information as part of each of the items in the combobox (as this could make selecting the right port easier).

Additionally, when starting the machine, if the port does not match an existing port name, we could try to match on the description/hardware ID (pyserial includes a grep function to do that).

This way, since manual editing is allowed in the combobox, you could use something like .*ErgoDox_EZ_ErgoDox_EZ.* (untested, I don't have TX Bolt setup for my keyboard, so I can't test).

Note: the QMK firmware supports MIDI, and the MIDI plugin actually supports a glob, so you can use something like The Preonic Keyboard* (meaning clicking the reconnect button is all you need to do on unplug/replug).

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

Successfully merging a pull request may close this issue.

2 participants