How to set up virtual testing environment for serial programming

Why

Despite its age, there are still some equipment and even robot use serial to connect to computer.

Serial communication allows two computers send data to each other. Or sometimes, one always sends and the other always receives. For example, a big equipment that send data to a PC for analysis.

Let’s you are writing a program that read data from serial port. But you don’t have the real equipment with you. What do you do?

You could use some tools to create virtual serial port and generate fake data for your testing.

(These are for Windows only, for Mac users, you could use a VM to run a Windows, eg. Parallels or Virtual Box)

Programs you will need

com0com download

This program create two (or more) fake serial ports on your Windows. Not only that, they are use a common setup called null-modem. From a functional point of view, if we input data to one port, the other port will receive the data.

COM PORT DATA EMULATOR

This program generates fake data and input it to one the fake port.

PuTTY

Allows you connect to a port and read data.

They are both free.

Next

Install com0com

After installing, we have two virtual ports on our system.

Install Com Port Data Emulator

Now, the 3 on the right of Serial port means COM3, not the third port, which is COM4. Press Start, the program will input data as COM3.

Install PuTTY

Choose Serial and type COM4, then we can see COM4 receives the data.

Now you can start writing your program and connect to COM4 to read those data!


Originally published at qimudev.wordpress.com on October 15, 2016.

Show your support

Clapping shows how much you appreciated Steve Mu’s story.