faking serial ports using kplex ?

58 views
Skip to first unread message

Bigbloke

unread,
May 23, 2020, 6:45:49 PM5/23/20
to kplex
Hi all,

Long time linux user with a good understanding of rs232 serial but total newbie to Kplex'er  and /dev/ files. Currently migrating away from franson GPSgate /OpenCPN
on windows, onto an ESXi host running Lubuntu 18.04 / kplex /opencpn..

I understand that the /etc/kplex.conf can have a [Serial] directive like  /dev/usbtty0, direction=in,to receive NMEA  data and apparently although my
guest OS cannot access my hardware serial port, iI can access a USB serial adapter,

But could I also create a [file] directive like direction=out, filename =/dev/usbtty1  to create a virtual serial port for passive use by another 
application on the same host ?

Or can multiple applications share a common serial port under linux please ? making such a step redundant?

What triggered this need is to break feedback loops between OpenCPN and a remote shipplotter install when bi-directional sharing  NMEA data 
between hosts.

Many thanks in advance for your clarity!

regards

BB

Keith Young

unread,
May 25, 2020, 7:29:19 PM5/25/20
to kplex
Apologies for the delay in replying and brevity: late in my timezone and I'll reply in more detail tomorrow but...

* No, multiple applications can't share a serial port under Linux
* You can use kplex to open and read from your "real" serial port then feed the data to multiple "fake" serial ports (which should be usable by most applications which expect a "real" serial port).  See here: http://www.stripydog.com/kplex/configuration.html#pty (I'll expand and give an example tomorrow, although there should be a discussion somewhere on this group about it)
* There's other ways you can feed multiple applications, e.g. using a network interface
* It's years since I played with ESXi but I strongly suspect there will be a mechanism for passing through any device which esxi recognises

Again, apologies for the late and brief reply: more tomorrow

Keith Young

unread,
May 26, 2020, 4:02:04 PM5/26/20
to kplex
I understand that the /etc/kplex.conf can have a [Serial] directive like  /dev/usbtty0, direction=in,to receive NMEA  data and apparently although my
guest OS cannot access my hardware serial port, iI can access a USB serial adapter,

But could I also create a [file] directive like direction=out, filename =/dev/usbtty1  to create a virtual serial port for passive use by another 
application on the same host ?

To use kplex to create "virtual" serial ports (do please let me know if this doesn't work for any particular application):
Your example is "in only" so we'll go with that.
Let's assume your "real" device is /dev/usbtty1 and you're happy with the default 4800 baud (see the configuration guide for other settings)
Your stanza for this interface in kplex.conf might look like:
[serial]
filename=/dev/ttyusb1
direction=in

Now say you want to create a couple of "virtual" serial ports, /tmp/ocpnserial and /tmp/otherapp
[pty]
filename=/tmp/ocpnserial
direction=out
group=dialout
mode=640

[pty]
filename=/tmp/otherapp
direction=out
group=dialout
mode=640

See the configuration section for more details.  The "group" directive is the group to assign to the pty. and ability to use this assumes that kplex is running as root.  "dialout" is the linux group which generally gives access to serial port, an assumption used in the opencpn documentation.  mode 640 will give group read access, which is probably what you want. The user will then of course need to be in the "dialout" group.  Note that we don't *actually* need to set a baud rate for ptys.  You can: it just won't do anything because these aren't backed by real UARTs.

Now the above is fine if you have one instance of kplex whose only job is to fan out one serial input to two "pseudo terminals" ("fake serial ports").  If however kplex is doing other things and you only want data from your actual serial port to be distributed to the pseudo-ttys, first add a name directive to the serial port stanza, e.g.:
name=inputserial

Then add the following directive to each of the pty stanzas to only output data received on that input:
ofilter=+*****%inputserial:-all

It may of course just be easier to output data on a network interface (loopback if all on one host) if all applications you want to use support that: Let me know if you want more details.

Per this morning's post it's been years since I played with ESXi but assuming vmware has drivers and your serial port is recognised, google "ESXi serial port passthrough" or somesuch: there seems to be a few kb articles.


Reply all
Reply to author
Forward
0 new messages