Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

socat two serial port together

Tags:

linux

unix

socat

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?

like image 841
Chris Smith Avatar asked Nov 19 '15 17:11

Chris Smith


1 Answers

You will want to link the newly created ptys to another location

socat -u -u pty,raw,echo=0,link=/dev/ttyS20 pty,raw,echo=0,link=/dev/ttyS21

After you create the virtual ports with socat, try changing the ownership of both ends of the pipe to allow easier access.

sudo chown user:user /dev/ttyS20
sudo chown user:user /dev/ttyS21

You could also change the permissions with chmod to 777.

like image 183
Trevor Young Avatar answered Nov 16 '22 14:11

Trevor Young