How to create a virtual serial port?

Grant Edwards grante at
Sat Apr 11 19:56:44 CEST 2009

On 2009-04-11, Grant Edwards <grante at> wrote:

> You can write a port redirector in user-space in MS-Windows,
> but you can't in Linux/Unix.  On Unix systems you have to
> write a kernel module that sits below the tty layer.

Perhaps I should elucidate further.

That's what the "pty" driver on Unix is: a kernel module that
sits underneath the tty layer where the "normal" serial-port
UART drivers sit.

However, Unix pty drivers only handles a subset of the normal
serial-port API.  [I'm not sure why pty drivers have never been
"finished" so that they fully emulate a serial port, but it's
been that way for 20+ years].

If RouteBuddy doesn't try to do things like get/set modem
control/status lines, then the OP might be able to use a pty.

Each pty consists of two devices: a master end and a slave end.
RouteBuddy would be told to use the slave end, and the OP would
write a program that would transfer data between a network
connection and the master end.

A pty devices is what is used by programs like xterm to run
programs like bash.  Xterm transfers data between a network
connection and the master end of a pty.  Bash is connected to
the slave end of that pty and "thinks" it's connected to a
serial port.  Bash uses little of the serial port API, so it's
happy with the limited API provided by a pty slave-end.


More information about the Python-list mailing list