drowe67 / freedv-gui

GUI Application for FreeDV – open source digital voice for HF radio
https://freedv.org/
GNU Lesser General Public License v2.1
206 stars 52 forks source link

automatic detection of serial port permissions issues on Linux #29

Closed drowe67 closed 1 year ago

drowe67 commented 5 years ago

A common trap for PTT using a serial port (HamLib or Serial PTT) is lack of permissions. This fix is usually adding your user to the dialout group. It would be nice to automatically detect permissions issues and report by a pop up window during serial port configuration/testing.

tmiw commented 3 years ago

136 updates Linux serial port detection to use a combination of globbing /sys and stat() on /dev/tty* to determine whether the port is valid. Since stat() returns -1 for ports that aren't usable, is the port not appearing in the port list sufficient?

drowe67 commented 3 years ago

I think it's useful to know what physical ports are actually available :+1: BTW there are many variations in Linux serial port names, does #136 capture them all in the list?

:thinking: However I think the port not appearing (when a user knows it's there and connected to the PTT device) might be confusing to a user. Like the current situation, it would require a note in the documentation to explain, so is a sideways step/variation on this issue, rather than a solution.

The behavior above in OP above would be ideal - let the computer take the user straight to the problem.

tmiw commented 3 years ago

I'm not too familiar with serial ports in Linux but my understanding is that /dev/ttyS and /dev/ttyUSB should cover the vast majority (if not all) of the common ones. Those are definitely covered by /sys, IIRC.

Anyway, I tweaked the OK/Apply actions to test chosen ports and display a message: https://github.com/drowe67/freedv-gui/pull/136/commits/113c366dffb70640d10c5c99e5933426c9255d2e. The message right now is "Couldn't open serial port ___. This is likely due to not having permission to access the chosen port." but I'm open to suggestions.

drowe67 commented 3 years ago

Hi @timw, thanks for working on this. I took a look at https://github.com/drowe67/freedv-gui/commit/113c366dffb70640d10c5c99e5933426c9255d2e:

  1. The error message is presented on all operating systems, whereas this issue deals with a specific Linux gotcha. Hmm :thinking:, could it also occur on other operating systems? I don't know enough about them myself....
  2. It doesn't handle the permissions issue when encountered using a serial port with HamLib (I'll make that clearer in the problem description above).
  3. The error message that's been added could be misleading - as it doesn't specifically detect the permissions issue as described in OP, so it will be displayed for many other reasons.

@timw - it's actually OK not to solve this issue right now, it's just a minor one, we've documented it, and might be tricky to solve. If you're really keen, maybe address it in a future PR, and just use https://github.com/drowe67/freedv-gui/pull/136 to address the PTT in feature?

tmiw commented 3 years ago

@drowe67, works for me. Just reverted for the time being.

timw commented 3 years ago

Hi all

Can I note that @timw != @tmiw - getting a lot of tags for projects I'm not involved in as a result :)

drowe67 commented 3 years ago

Hi all

Can I note that @timw != @tmiw - getting a lot of tags for projects I'm not involved in as a result :)

Oops so sorry - that's probably me! Will be more careful in future .....

tmiw commented 1 year ago

@drowe67 et al, is this something that would still be useful to add? Doing some cleanup of the currently open GitHub issues at the moment.

drowe67 commented 1 year ago

Yes I've been caught by it several times (forgetting to add the dialout group thing). So if we could detect this it would be great.

tmiw commented 1 year ago

Yes I've been caught by it several times (forgetting to add the dialout group thing). So if we could detect this it would be great.

👍

I noticed that USB serial devices seem to be chmod 666 (-rw-rw-rw) on macOS whenever I plug them in. Additionally, permissions issues on Windows for serial ports seem to mostly be due to something else having access to the port and not necessarily that one isn't e.g. Administrator. This may impact what we show to the user (see below).

Anyways, this basically should be a dialog box that could display for the following scenarios:

  1. PTT input, when enabled and the Start button is pressed.
  2. Hamlib*/serial PTT usage:
    • When pushing Start.
    • Pushing the Test button (either in Easy Setup or in Tools->PTT Options).

* Checks will be performed prior to opening a connection to the radio using the Hamlib library (i.e. no changes to the Hamlib library itself will be required).

The check itself will basically be something like the following:

FILE* fp = fopen("/dev/ttyUSBx", "r+");
if (fp == nullptr)
{
    // Logic to display the dialog box
}

Considering the behavior above, there should probably be multiple different messages. I propose the following:

Linux: "Could not open serial port /dev/ttyUSBx. Please ensure that you have permission to access the port. Adding yourself to the dialout group (and logging out/back in) will typically ensure this." macOS/other Unix: "Could not open serial port /dev/tty.usbserialxxxxx. Please ensure that you have permission to access the port." Windows: "Could not open serial port COMx. Please ensure that no other applications are accessing the port."

Does the above sound reasonable?

tmiw commented 1 year ago

@drowe67, I haven't had a chance to try #348 yet. Does that seem to correctly detect permissions issues for you? I can test too when I get the time.