Mr. Starck
Mr. Starck

Reputation: 232

Create and test virtual serial ports with com0com and hub4com

I'm working on sending datas via COM in C++ for ESPA 4.4.4. A program B connected on a COM port normally detects if the program A sends datas. To test this I have created two virtual ports pair with com0com, COM1/CNCB1, COM2/CNCB2. With hub4com I connected like explained here

But when I try to connect to COM1 or COM2 with A or B, it cannot be done because the port is already in use.

SO my problem is that I want the two ports to communicate. -> First question: is the architecture in the tutorial good to deal with. I mean is it ok to deal with COM1/CNCB1 and COM2/CNCB2? -> Second question: the command to connect the two ports is "hub4com options \.\input_COM \.\output_COM1" \.\output_COM2"... SO I tried to do: "hub4com -baud=9600 \.\COM1 \.\COM2". The command is valid and I get the following return:

Open("\\.\COM1", baud=9600, data=8, parity=no, stop=1, octs=off, odsr=off, ox=off, ix=off, idsr=off, ito=0) - OK
Open("\\.\COM2", baud=9600, data=8, parity=no, stop=1, octs=off, odsr=off, ox=off, ix=off, idsr=off, ito=0) - OK
Route data COM1(0) --> COM2(1)
Route data COM2(1) --> COM1(0)
Route flow control COM1(0) --> COM2(1)
Route flow control COM2(1) --> COM1(0)
Started COM1(0)
Started COM2(1)

So the road is established and the datas should communicate. But I can't connect on the COM ports with my programs. So I tried to connect on CNCB1 and CNCB2 instead. I can connect on the COM ports. But I don't know if the data have arrived.

-> So third question: is there a reliable way to know if COM1 sends datas to COM2? Just a little software would be great, to test the architecture

Upvotes: 1

Views: 8979

Answers (3)

Johan
Johan

Reputation: 257

You don’t need hub4com if you just have 2 programs communicating with each- other. Just use com0com to set up a port pair like : COM1<>COM2. Now select Com1 in Program A and Com2 in Program B, and that should work. (This is "One-To-One-Comms")


For "One-To-Many-Comms", you need hub4com:

Example 1:

Program A is your data- source, and both Program B and Program C needs to receive the data from A. Then you go like this :

com0com :  COM1<>CNCB0  ;  COM2<>CNCB1  ;  COM3<>CNCB2
hub4com --route=0:All \\.\CNCB0 \\.\CNCB1 \\.\CNCB2

Now Use: Com1, 2 and 3 in Program A, B and C.


Example 2:

COM7 is a real comport with an external data- source like a GPS receiver connected to it. Program A , B and C needs to receive the data from COM7. Then you go like this :

com0com :  COM1<>CNCB0  ;  COM2<>CNCB1  ;  COM3<>CNCB2
hub4com --octs=off --route=0:All \\.\COM7 \\.\CNCB0 \\.\CNCB1 \\.\CNCB2

Note: The “--octs=off” command is needed when working with real com ports. Also, if the real com port needs to work at say 4800 baud, you need to add the command: “--baud=4800”.


Example 3:

You need bidirectional comms between 3 programs: Program A sends to B and C; B sends to A and C; and C sends to A and B. Then you go like this :

com0com :  COM1<>CNCB0  ;  COM2<>CNCB1  ;  COM3<>CNCB2
hub4com --route=All:All \\.\CNCB0 \\.\CNCB1 \\.\CNCB2

Note: “Realterm” is a good free program to use to test your comms. (open it 3 times for this test)


Example 4:

Hub4com is also good for a "Com<>TCP<-->TCP<>Com"- network connection. Like this:

Server side:

com0com :  COM1<>CNCB0  
hub4com \\.\CNCB0 --use-driver=tcp 7000

Client side:

com0com :  COM1<>CNCB0  
hub4com \\.\CNCB0 --use-driver=tcp 192.168.20.3:7000

Note: Change the IP address to the address of your Server computer on your Ethernet or WiFi network. On both computers you can now use COM1 to send data to the other over your network.

Upvotes: 1

Rok T.
Rok T.

Reputation: 409

Portmon is discontinued and doesn't work in recent (x64) Windows versions...

So now, in Windows, you can use this nice program: Serial-Lab

I had a similar problem and also used com0com in combination with above mentioned SerialLab. When com0com got installed it created COM3 and COM4 ports and I used those two for testing. In your case it seems you have COM1 and COM2 created by com0com?

In my (Java) application I was then sending data to COM4 while in SerialLab I connected to COM5 and I was able to read the data sent from my Java application. You can also send data from SerialLab, so you can test an simulate communication in all directions.

Another similar program is also MyTerm.

Upvotes: 0

Jason Struckhoff
Jason Struckhoff

Reputation: 208

  1. It should be fine, they're just names. If you're going to have a man in the middle type of application, you'd want the data to flow like... (ProgramA -> COM1 -> CNCB1 -> ProgramB -> COM2 -> CNCB2 -> Destination.) So ProgramB should have ports open for both CNCB1 and COM2.

  2. I'm not too familiar with hub4com to give you an answer for that. It sounds like hub4com is opening the ports up and your application is also trying to open the port up. Only one application can have access to a port.

  3. Sounds like you need a port monitor. http://technet.microsoft.com/en-us/sysinternals/bb896644.aspx

Upvotes: 1

Related Questions