How to create a virtual serial port?

Grant Edwards grante at
Sun Apr 12 03:45:09 CEST 2009

On 2009-04-11, Dennis Lee Bieber <wlfraed 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.  The tty layer
>> is what user applications talk to with open/close/read/write/ioctl
>> calls.
> Extending to the point of absurdity... Does the machine have a
> physical serial port from which the application could read?

I believe not.

> Does the machine have a USB port?

Definitely.  All Mac's have had USB ports for a long, long time

> What would setting a pair of serial ports (possibly one or
> both using USB<>Serial adapters) with a null modem between
> them give?

That should work as long as the application isn't trying to do
timing-critical tricks with the modem control and status lines.
Such tricks don't work well with USB attached serial ports.

> Could the application read from one, while Python is writing
> to the other?


> 	Yes, it IS an absurd klutz, but...

Sadly, if a pty won't work, that's probably the easiest
solution.  You can get USB-serial adapters from newegg for
under $10.  For a slightly less ugly kludge, you can get a
dual-port one for $25.

And when you need to test the effects of a high-latency,
low-bandwith WAN connection on something, you can plug them
together with a null-modem cable, set them up as PPP interfaces
running at 1200 baud, and route network traffic through them.


More information about the Python-list mailing list