Connecting multiple virtual serial ports together
However many times you may want to connect a real device to a virtual serial cable. This can be done using program hub4com. While the com0com works on the “driver side” of the com port the hub4com works on the “software side” and can be used to connect mutliple com ports (virtual or real ports) together. Also more than two ports can be connected together and ports may be forwared thru internet.
With this utility also also more complicated connections are possible, such as connecting multiple output serial ports to a single data source or making a software serial port sniffer cable. Hub4com is a part of com0com project, but is distributed separately. It can be downloaded here. You could also check one folder up to see if there are any newer versions. Unless you want to compile the program yourself you should download the binary version which is packed in hub4com-220.127.116.11-386.zip. To install it just unzip the contents of the archive to com0com installation folder (you will probably find it in Program Files x86).
To get some help for the program you have to run it without any arguments. You can do this from command prompt. Just clicking on the executable will show the help, but will dissapear too fast for you to be able to read it. First open a command prompt (Win Button + R, enter cmd into text box and press ok).
Command prompt will start in your user directory so you have to navigate to the directory containing hub4com.exe In my case this can be done by entering “cd C:\Program Files (x86)\com0com” command into command prompt.
Now you can run the hub4com.exe program with “hub4com” command. This will show the help for the program.
hub4com [options] <port0> [options] [<port1> ...]
- load arguments (one argument per line) between
<begin> and <end> lines from a file <file> (use
standard input if empty) and insert them into the
command line. The syntax of <prms> is
<PRM1>[,<PRM2>...], where <PRMn> will replace
%%n%% in the arguments. Do loading since begining
if <begin> is empty. Do loading till end-of-file
if <end> is empty. Ignore arguments begining with
'#'. <file> will replace %%0%% in the arguments.
It is possible up to 256 recursive loads.
--help - show this help.
--help=* - show help for all modules.
--help=<LstM> - show help for modules listed in <LstM>.
The syntax of <LstM> above is <MID0>[,<MID1>...], where <MIDn> is a module
--route=<LstR>:<LstL> - send data received from any port listed in <LstR>
to all ports (except itself) listed in <LstL>.
--bi-route=<LstR>:<LstL> - send data received from any port listed in <LstR>
to all ports (except itself) listed in <LstL> and
--echo-route=<Lst> - send data received from any port listed in <Lst>
back to itself via all attached filters.
--no-route=<LstR>:<LstL> - do not send data received from any port listed in
<LstR> to the ports listed in <LstL>.
--fc-route=<LstR>:<LstL> - enable flow control route from any port listed in
<LstR> to all ports listed in <LstL>.
disable default flow control route from any port
listed in <LstR> to all ports listed in <LstL>
(default flow control route enabled from P1 to P2
if enabled data route from P1 to P2 and from P2 to
If no any route option specified, then the options --route=0:All --route=1:0
used by default (route data from first port to all ports and from second
port to first port).
- by using filter module with name <MID> create a
filter with name <FN> (<FN> is <FGID> by default)
and put arguments <Args> (if any) to the filter.
Add filter to the end of filter group <FGID>
(<FGID> is <MID> by default). Any filter can
accept described above option --load=[...].
- attach the filters listed in <LstF> to the ports
listed in <Lst>. These filters will handle the
data by IN method just after receiving from ports
listed in <Lst> or by OUT method just before
sending to ports listed in <Lst>.
The syntax of <LstF> above is <F1>[,<F2>...], where the syntax of <Fn> is
<FGID>[.<Method>][(<Lst>)], where <FGID> is a filter group, <Method> is IN or
OUT and <Lst> lists the source ports (the data only from them will be handled
by OUT method). The <FGID> w/o <Method> is equivalent to adding IN and OUT
for each filter from the group <FGID>. If the list of the source ports is not
specified then the data routed from any port will be handled by OUT method.
--use-driver=<MID> - use driver module with name <MID> to create the
following ports (<MID> is serial by default).
The syntax of <LstR>, <LstL> and <Lst> above is <P1>[,<P2>...], where <Pn> is a
zero based position number of port or All.
List of filter modules:
awakseq - Connect on awakening sequence filter
crypt - Encrypting/decrypting filter
echo - Echo filter (alternative to --echo-route option)
escinsert - Escaped datastream generating filter
escparse - Escaped data stream parsing filter
linectl - Baudrate and line control mapping filter
lsrmap - LSR mapping filter
pin2con - Connect or disconnect on changing of line or modem state filter
pinmap - Pinouts mapping filter
purge - Purge mapping filter
tag - Tag filter
tag-sync - Tag synchronization filter
telnet - Telnet protocol filter
trace - Trace filter
List of driver modules:
connector - Connectable fake port driver
serial - Serial port driver
tcp - TCP port driver
hub4com --route=All:All \\.\CNCB0 \\.\CNCB1 \\.\CNCB2
- receive data from CNCB0 and send it to CNCB1 and CNCB2,
receive data from CNCB1 and send it to CNCB0 and CNCB2,
receive data from CNCB2 and send it to CNCB0 and CNCB1.
hub4com --echo-route=0 COM2
- receive data from COM2 and send it back to COM2.
- the same as above.
blah blah blah
- the same as above.
For example a very basic setting would be to create a hub for three ports:
hub4com --route=All:All \\.\CNCB0 \\.\CNCB1 \\.\CNCB2
This will forward any data received on any port to both other ports. Note that CNC* ports are usually used with virtual only (not available to software) com0com driver and COM* are real or virtual comports. For running the above command you should have all the named ports set up as a com0com virtual pairs (for example CNCB0<>CNCA0, CNCB1<>CNCA1, CNCB2<>CNCA2).
If the communication devices don’t need any hardware flow control it is good to add the following modifiers to the hub4com to prevent issues with flow control:
Flow control is not necessary a bad thing, but if it is not used (and you don’t want to think / worry about it) it is better to just turn it off. The full command would be:
hub4com --octs=off --no-default-fc-route=All:All --route=All:All \\.\CNCB0 \\.\CNCB1 \\.\CNCB2
For example we could use the above command for monitoring a communication between a USB GPS device connected to COM8 and host PC GPS software. Note that one of the ports has been changed to COM8 to directly connect to hardware port. (You will probably also want to set the baudrate with –baud=… setting.)
hub4com --octs=off --no-default-fc-route=All:All --route=All:All \\.\CNCB0 \\.\CNCB1 \\.\COM8
Our host PC GPS software would now connect to one of the two com0com connectors, for example to CNCA0. Our “sniffer” software would connect to the other connector CNCA1. On the CNCA1 port you can receive the data from both sides, however this simple sniffing configuration will only work nicely for half duplex communication (only one device communicating at one time). When both devices are sending data at once you will get mixed characters from both sources. There is no way to directly tell which device sent the data and you can not inject data to both devices.
For a more elaborate sniffing cable connection you could use the following command:
hub4com --octs=off --no-default-fc-route=All:All --route=0:1,3 --route=3:0,2 \\.\CNCB0 \\.\CNCB1 \\.\CNCB2 \\.\COM8
With this command the data from COM8 is connected to CNCB0(CNCA0) and CNCB1(CNCA1). The data from CNCB0(CNCA0) is forwarded to COM8 and CNCB2(CNCA2). This way the COM8 and CNCA0 communicate bidirectionally while we have a receive only ports CNCA1 and CNCA2. Each of these ports will be used for receiving/sniffing data from one of the bidirectional ports. This configuration is actually equivalent to what you will usually find online as a hardware bidirectional serial port sniffer cable.
By adding additional data routes you could also make the ports CNCA1 and CNCA2 be able to inject data to each of the bidirectional ports. This is a feature that can only be implemented in software as there is no way you can combine two RS232 TX signals in hardware…
I have only touched some of the things you can do with hub4com, also additional functions such as multiplexing, serial over internet, internet server and many more modes are available. Actually with so many settings available in hub4com the possibilities are countless, so your imagination is the limit (or maybe the amount of time you want to spend playing with it) 😉