Geeks With Blogs

The Life and Times of a Dev Yes, we're really that weird

In the hardware world, much of the communication still happens over RS232 or RS485 serial ports.  Unit testing this can be a challenge.  To help with that, I’ve created a custom SerialPort wrapper, which, among other things, helps with multiple threads trying to hit the serial port at the same time.  When you’re iterating over actors, this is a key bit of functionality that needs to happen.

Because I have this class injected, I can easily substitute a mock to the things that actually do serial communication.  However, how do you unit test the serial component itself?  System.IO.SerialPort doesn’t have an interface, so it is challenging to test.

The solution I’m using is com0com, which is essentially a null modem emulator.

There are other solutions that are also great, but they aren’t free.  In particular, I was impressed by Eltima’s Virtual Serial Port Driver.  I almost bought it, but couldn’t rationalize it just for automated unit tests.

To use com0com, you’ll likely need to download the signed version, unless you have driver signing turned off on your computer.  Once installed, I use a simple batch file to install the desired com ports:

@echo off
cd\
cd "program files (x86)\com0com\"
"setupc.exe" --silent install PortName=COM181,EmuBR=yes,EmuOverrun=yes PortName=COM182,EmuBR=yes,EmuOverrun=yes

There are many more options, but what I needed was pretty simple.  Once this is done, SerialPort connects to the virtual com port just like it’s a real com port and does its thing.

One issue I ran into is that most unit test runners run multiple tests on different threads.  Since COM ports are strictly limited and only one thing can connect at a time, this can be a problem.  To get around, I just made a single massive test for my serial port component.

Posted on Thursday, December 11, 2014 5:36 PM Unit Testing , Serial Port | Back to top


Comments on this post: Virtual Com ports

# re: Virtual Com ports
Requesting Gravatar...
visit the website at www.geico.com with one click
Left by daniels danny on Dec 10, 2016 6:30 AM

# re: Virtual Com ports
Requesting Gravatar...
walmart offers you the walmart credit card login procedute to banking
Left by daniels danny on Dec 10, 2016 6:31 AM

# re: Virtual Com ports
Requesting Gravatar...
visit Dealersocketto login
Left by geek on Feb 10, 2017 12:17 AM

# re: Virtual Com ports
Requesting Gravatar...
If you are video lover and love to watch latest movies then showbox is the most easiest way to get latest collection of movies anytime showbox apk you need to follow just few simple steps.
Left by Rae Allison on Apr 04, 2017 3:01 AM

# Xmodgames APK
Requesting Gravatar...
Gaming is transformed completely with the collaboration of technology and android operating system. Games have been makeover by the android platform. In doing so, app developers come up with the idea of game mod. Download Game Mod mod is nothing but the bypassing of in-app purchases. In simple words, download game mod will enable the player to play the game without having to make any purchases in the game. Everything is for FREE!
Left by JesseJStarkey on Feb 23, 2018 11:48 PM

# XmodGmaes Apk AtaVist
Requesting Gravatar...
It’s not guaranteed that Xmod Apk android will always give you the equivalent pleasure of enjoying the tweak games so if you are among those who are unable to Xmodgames Apk or install Xmod games, then you are at the absolutely right page and is about to read the best apps like Xmodgames.You will find the best apps like Xmod in this post and we are sure that out of which at least one of the app will fit into your android phone.
Left by williamshockley on Feb 26, 2018 6:09 AM

Your comment:
 (will show your gravatar)


Copyright © Robert May | Powered by: GeeksWithBlogs.net