Connecting multiple virtual serial ports together

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-2.1.0.0-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).

2015-01-14 21_35_56-Zaženi

 

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.

2015-01-14 21_40_47-C__WINDOWS_system32_cmd.exe

Now you can run the hub4com.exe program with “hub4com” command. This will show the help for the program.

For example a very basic setting would be to create a hub for three ports:

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:

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.)

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:

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) 😉

7 Comments on “Connecting multiple virtual serial ports together

    • 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.

    • 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.

  1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*