5

Background: I want to use this Wifi-to-Serial adapter to control a telescope via Stellarium running on Kubuntu 16.04 (64 Bit).

I'd created a virtual com port using socat with this command line:

$ sudo socat pty,link=/dev/virtualcom0,raw tcp:10.0.0.1:4030

and I see the new device here:

$ ls -l /dev/virtualcom0 
lrwxrwxrwx 1 root root 10 2017-07-03 09:05 virtualcom0 -> /dev/pts/6
$ ls -l /dev/pts/6
crw--w---- 1 root tty 136, 6 2017-07-03 09:05 /dev/pts/6

Trying to use /dev/virtualcom0 e.g. with picocomm works as long as I run picosomm with root privileges. But when I try to use the port with standard user privileges, I got an error:

$ picocom /dev/virtualcom0 --baud 9600 --imap lfcrlf
FATAL: cannot open /dev/virtualcom0: Permission denied

Any idea how to make the virtual com port accessable with standard user rights, maybe by defining a special udev rule for this?

Edit #1

Following the preferred approach of dirkt's answer, I'm now using:

$ socat pty,link=/tmp/virtualcom0,raw tcp:10.0.0.1:4030

Note, that this also works fine on macOS (after installed socat via homebrew).

slm
  • 363,520
  • 117
  • 767
  • 871
Joe
  • 709
  • 2
  • 9
  • 12
  • Possible duplicate of [Read/Write to a Serial Port Without Root?](https://unix.stackexchange.com/questions/14354/read-write-to-a-serial-port-without-root) –  Apr 03 '19 at 13:50

2 Answers2

7

I found an answer after pouring through the man page for socat.

You can add mode and group to the attributes of your pty by adding a few more expressions to your command line. To follow your example, but with your new serial port owned by the dialout group and with read/write access for that group, do this:

$ sudo socat pty,link=/dev/virtualcom0,raw,group-late=dialout,mode=660 tcp:10.0.0.1:4030
Efpophis
  • 71
  • 1
  • 1
6

I don't fully understand why you need a virtual serial port at all. What happens if you just telnet 10.0.0.1 4030?

Next thing is to run socat without sudo as normal user and pick a path that's accessible, e.g. /tmp/vcom0 (or whatever).

If that doesn't work for some reason, and you obvious can do sudo, try changing owner

sudo chown your_username /dev/virtualcom0

or permissions

sudo chmod o+rw /dev/virtualcom0

Edit

Don't try to make udev rules for a particular pseudo tty. First, you don't know in advance which pseudo tty it is, second, pseudo tty's are used all over the place, and other programs will fail if they happen to create this pseudo tty for another user.

The cleanest solution is to use variant (1) (/tmp/vcom0).

If you insist on the other variants, make a short script that contains both the socat and the chmod/chown, and execute that script with sudo. You can follow symbol links with readlink, if necessary.

Another alternative is to write a short script that calls both socat as normal user, and stellarium with the link it made, and kills socat when it's done. Use that script to start stellarium.

dirkt
  • 31,679
  • 3
  • 40
  • 73
  • I need a virtual serial port for accessing it via Stellarium. – Joe Jul 03 '17 at 11:35
  • Great, all three solutions are working. For the `chown` and `chmod` approach it's finally that they change `/dev/pts/6` permissions from `crw--w---- root tty` to e.g. `crw--w---- joe joe` or `crw--w-rw- root tty` or `crw-rw---- root dialout`. – Joe Jul 03 '17 at 12:55
  • Did you have an idea how to apply `chmod` / `chown` automatically by using e.g. an udev-rule? I'd tried `SUBSYSTEM=="pty", MODE="0666"` and `SUBSYSTEM=="pts", MODE="0666"` both without success (permissions of `/dev/pts/6` stay at `crw--w---- root tty`). – Joe Jul 03 '17 at 13:04