Connecting multiple virtual serial ports together
Have you ever had the need to connect multiple programs that utilize serial ports? Or you tried to stream the data from single GPS device to multiple programs that needed the data? Then either you found out it can’t easily be done using the tools avalible on windows, or after some research online you stumbled upon com0com and hub4com which is part of com0com project (although distributed separately).
Com0Com is actually a null modem cable emulator, so it can be used to emulate pairs of serial ports that are virtually interconnected.You can get it at at its sourceforge page. If you have one of newer windows versions that don’t allow installing unsigned drivers you should probably download the 2.2.2.0 version from the official site or you can get signed 3.0.0.0 at this page. The installer is pretty straightforward. During the installation you can also choose to add two example pairs of ports (one with Ports class and one without).
After installing Com0com you can configure it using the setup program (which has a very descriptive name – Setup :P, but you can distinguish it by the port icon). Here is the setup screen, which is pretty intuitive by itself (except for Ports class meaning and signal routing).
Only ports with Port class checkbox checked will be available as “normal” serial ports to most programs. Ports without Ports checkbox checked can however still be used by utilities like hub4com. There are also additional checkboxes with more advanced features, which you probably won’t need to touch.
The serial port pair setup dialog also features advanced virtual cable setup, which allows you to choose which serial port signals from one port connect to which signals on the other port. Signal routing can be changed by clicking (and hodling mouse button) on one colored dot connector and dragging a signal to second colored dot connector. A negation of the signal can be obtained by doubleclicking on the green dot connector. On touchpad single click seems to disconnect the signal for me (but that does not seem to work with the mouse?). Up to current time I have not yet had the need to connect those extra signals on any of the programs I use.
Com0com creates virtual ports that are connected to each other, so you can use them to connect two programs to communicate using a pair of ports, for example GPS simulator (data source) and GPS client application (data client). Of course the communication can also be bidirectional like sinchronization of two programs.
(This is a multipage post. Read on for examples and using hub4com for connecting multiple ports >>)
Thanks for the article, a very nice read! However, I would like also to add, that there are also other pieces of software that can create virtual COM ports or let you connect a real device with a virtual port. All additional details can be found in the articles, like this one
https://www.eltima.com/create-virtual-serial-port.html
Software to connect real devices to a virtual serial cable
https://www.eltima.com/products/serialsplitter/
Please keep advercomments off this site. I’ve seen this comment, a lot, in different posts. com0com and hub4com are open source. These Eltima and the notorious “free serial monitor” program (which I will not list here) are not open source.
Is it possible to switch baud rate up to 57600?
Can you describe it?
The com0com emulation normally doesn’t care about the baudrate, so you can safely connect with 57600 baud on one virtual port and 9600 baud on other port (which would not be possible in physical word). Actually com0com won’t emulate the baudrate mismatch on virtual fable (wrong data you would get), however you can use the “enable baud rate” tick to emulate the timings/delays caused by sending at the chosen baudrate.
Hello I have had good success using com0com to practice with virtual serial before going to real hardware and I wired together a serial sniffer cable so that I could separately capture the outgoing byte stream each direction. Now I need to do the same thing with a USB GPS device which uses the Prolific chipset USB serial and hub4com looks like the perfect solution but I cannot make it work.
I have three virtual com port pairs setup:
command> list
CNCA0 PortName=-
CNCB0 PortName=COM#,RealPortName=COM20
CNCA1 PortName=COM#,RealPortName=COM16
CNCB1 PortName=COM#,RealPortName=COM14
CNCA2 PortName=COM#,RealPortName=COM18
CNCB2 PortName=COM#,RealPortName=COM19
and I launch hub4com in an admin cmd window with the command:
hub4com –octs=off –no-default-fc-route=All:All –route=0:1,3 –route=3:0,2 \\.\COM20 \\.\COM14 \\.\COM19 \\.\COM8
but I cannot open a connection to any of the com ports.
The GPS software returns:
“Error.. Cannot create UART handle. Comm port is not available or may be in use”
and PuTTY returns:
“Unable to open connection to COM? Unable to open serial port”
I tried to connect to COM8, COM14, COM19 & COM20 I did not expect COM8 to work. I also tried the same hub4com as a standard user.
Can you see what I’m doing wrong?
Hi, it’s been quite some time since I used this. The error seems to indicate that you probably have a handle open somewhere to that port. This may be due to other software trying to access it (eg. open in terminal or by system – legacy mouse and bt drivers may sometimes take over) or it being already in use. You can use RealTerm in sniffer mode (Echo port tab, Echo on, Monitor) with a single com0com port to do the bidirectional logging, however it will not work for high data troughput and is not as fast, so for some applications it may not work. There are also software solutions that enable you to examine tx/rx data at the driver level. I mainly still use a hardware 4 port cable or the above RealTerm solution. Regards,
Dejan
You might try a cable with an FTDI chip; some of those Prolific cables are counterfeit and don’t work.