socat two serial port together

Chris Smith picture Chris Smith · Nov 19, 2015 · Viewed 20.8k times · Source

I am writing a JUnit test to test my application. The application is written in Java and uses the purejavacomm library. To test the serial parser I want to setup a virtual serial port so the test can communicate with the parser. In addition to simply parsing, it also dynamically connects to the serial port when it becomes available so I do not want to use, say a PipedInputStream.

This library only looks for device files that start with ttyS, ttyUSB, or ttyACM. Because of this, I cannot do the regular (which would produce serial ports in /dev/pts/x):

socat -d -d pty,raw,echo=0 pty,raw,echo=0

I tried doing:

socat /dev/ttyS20 /dev/ttyS21

but it doesn't work. It doesn't exit, or print an error. I tried connecting to /dev/ttyS20 with screen, but it just says, [screen is terminating].

I looked at the user permissions for ttyS20 (and 21), and they both have the group, dialout (user: root), which my user is in (chris).

Am I overlooking something with the permissions? Is there a better way to do this all together?

Answer

Trevor Young picture Trevor Young · Nov 25, 2015

Then what I would suggest is to create a dev folder in your home directory and point the links there.

socat pty,raw,echo=0,link=/home/user/dev/ttyS20 pty,raw,echo=0,link=/home/user/dev/ttyS21

You should be able to access that without root. If it is a unidirectional communication I usually like to add the -u option.