Virtual serial ports are commonly used in development of programs using serial connection as well as debugging existing applications - to check what kind of data is transmitted over a serial connection.

The idea of virtual serial port is to create two virtual serial ports linked with a null modem cable, attaching one end to tested application and the other end to (usually) serial terminal (e.g. Cutecom).

Installing prerequisites

To create a pair of ports you will need a utility called "socat". It is located in "universe" repository, so you should be able to find it in Synaptic. Alternatively install using

sudo apt-get install socat

Creating ports

After installing socat you have to execute following command:

socat PTY: PTY:

That should create and link the virtual port pair for as long as socat is running.

If you are like me and want a little more feedback on what is happening instead of a command line that is hanging, use verbose mode instead:

socat -d -d PTY: PTY:

You can put the -d argument up to four times, increasing the information fed back to you each time.

Checking file names

Using socat

The easiest way to tell which file names are assigned to these virtual ports is to tell socat to print information about opened pseudo terminals during initialization using following options (verbose mode):

socat -d -d PTY: PTY:

Your applicantion should connect to these files.

Using lsof

Another way is to list socat's open files:

lsof -c socat

You should notice file /dev/ptmx, that is pseudo terminal multiplexer and directly below each entry should be listed /dev/pts/X file, which are the ends of created pair.

External Links

VirtualSerialPort (last edited 2010-10-28 11:21:26 by pc-212-51-221-162)