Socat Serial Telnet
Every once in a while, I see people having a hard time accessing a RS232 or USB serial port from Java. There exist several solutions to do this in Java:.The looks awfully old and unmaintained. It is available for Solaris SPARC, Solaris x86, and Linux x86.is a mix between Java code and C code accessed through the Java native interface. It is hosted on a CVS server and it looks like the 2.2 release will never go out since it got stuck on version 2.2pre2 released in 2009. The last stable version is 2.1.7 from 2006.is a drop-in replacement for those two libraries, written in Java and using to interface with the system.
It is simpler to setup than RXTX, and is actively maintained.However, there exist at least one other solution which does not require the use of any external library. This is what I chose to interface a program with a module through a serial interface to interact with my students devices. I also use it to interface the with the same XBee module.Every language has a well-defined and well-maintained sockets library, right?
So why not simply use, a multipurpose relay which is able to bridge many protocols and interfaces such as, in our case, TCP and a serial port?I launch socat as. % socat TCP-LISTEN:4161,fork,reuseaddr FILE:/dev/ttyUSB0,b57600,rawand what I immediately get is a TCP server listening onto port 4161 and ready to relay any incoming connection to the /dev/ttyUSB0 serial port with a 57600 baud rate.
Linux Socat
And not only do I have no more concern about accessing the serial port properly, but also I can access a port located on a remote computer as easily by launching socat there instead of locally.But what if I want to spy on the TCP/serial relay to see that I send the right codes to the XBee module? Socat offers you a choice of command-line options to dump the data in various formats.What does the Scala interface look like? I have a XBee abstract class lacking an InputStream to receive the input from the XBee module and an OutputStream to send the output to it. This class is extended into a concrete class using simply.
Background: I want to useto control a telescope viarunning 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:4030and I see the new device here: $ ls -l /dev/virtualcom0lrwxrwxrwx 1 root root 10 2017-07-03 09:05 virtualcom0 - /dev/pts/6$ ls -l /dev/pts/6crw-w- 1 root tty 136, 6 2017-07-03 09:05 /dev/pts/6Trying 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 lfcrlfFATAL: cannot open /dev/virtualcom0: Permission deniedAny idea how to make the virtual com port accessable with standard user rights, maybe by defining a special udev rule for this? Edit #1Following the preferred approach of dirkt's answer, I'm now using: $ socat pty,link=/tmp/virtualcom0,raw tcp:10.0.0.1:4030Note, that this also works fine on macOS (after installed socat via homebrew). 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 yourusername /dev/virtualcom0or permissions sudo chmod o+rw /dev/virtualcom0EditDon'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.
Comments are closed.