PROGRAMS

socat

Date Published:
Last Modified:

Overview

socat is a very powerful utility program for estabilishing bi-directional data streams between two data sinks/sources. It can be used for creating two virtual COM ports that relay information to each other.

Installation

On Debian-based operating systems (such as Ubuntu), you can type:

$ sudo apt-get install socat

Connecting Two COM Ports Together

You can use socat to connect two COM ports together. This means that any information sent to one will appear as input on the other, and vise-versa.

To set up the two-way communication, you type:

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

A little explanation: The -d -d instructs socat to print fatal, error and warning message. pty instructs socat to connect to a pseudo-terminal (e.g. /dev/pts/0, /dev/pts/1, …). raw instructs socat to do almost not processing on input/output, and just pass it untouched. echo=0 tells socat not to echo any input characters back to the same terminal (which is normally the desired behaviour when connecting two COM ports).

Once you type this and press enter, socat will report back with the COM ports it decided to use. The program will not return (the terminal will hang) until you wish to cancel the link (press Ctrl-C).

If you get a bash: /dev/pts/x: Permission denied error, run the following command:

$ sudo chmod a+rw /dev/pts/x

If you want to specify the device names of the two serial ports, you can use the following command:

$ sudo socat -d -d pty,raw,echo=0,link=/dev/ttyS10 pty,raw,echo=0,link=/dev/ttyS11

The above command still creates two arbitrarily named pseudo terminals in /dev/pts/, but it then links it to the two fixed device names provided in the command.


Tags:

    comments powered by Disqus