A few days ago a friend of mine asked me a few questions about how to test a COM1 device. The question sounds simple but think about that, sometimes you don’t have the needed COM1 device to test or your computer doesn’t have a COM1 port at all (for example, a laptop).
I think this is the kind of job for a Virtual Machine… Let’s try.
We would need a few things:
- A virtual machine (I will use VMWare, but VirtualBox would do the trick too)
- Putty (freeware you can download at http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)
- If possible, the protocol or messages send by your device (I would use a simple chat to do the sample)
The secret is to redirect the COM1 port from the virtual machine to a file (possible in VMWare) or a named pipe, for starters, a named pipe is an IPC mechanism for process intercommunication.
In the virtual machine settings add a new hardware device and then select Serial Port, Add to named pipe, Finish. Write somewhere the name of the named pipe, in my case would be \.\pipe\com_1
Now, just for this experiment, I will use putty in the virtual machine to connect to COM1 and in my guest to connect to the named pipe, in that way I will send messages from the virtual machine to COM1 (as any other application would do) and I would be able to receive those messages in the guest through putty, and of course I can answer back from the guest.
In your putty host session remember to select “serial” as the connection type and instead of COM1 select the named pipe created by vmware
In the putty guest session everything is normal, just select “serial” and the expected COM* port, in my case would be COM2:
Putty attention in vmware notification icons, even when your named pipe is “com_1” could be possible that in your virtual machine that virtual port is COM2 (not COM1 as you would expect).
Now when I type “hello” in my virtual machine putty instance it will echo in the host putty session and the same backwards. Now, the question is simple, how do I emulate correctly my weird device?
Well, a nice and easy way would be to “record” a common communication session between your device and a machine with a COM1 installed, and then “replay” that session back in your virtual environment using putty or a home made program. You know what, I found a program to do exactly that in CodeProject (Application to Debug Serial Port communication and Basic Serial Port Listening Application), go, give a try =)
I hope this would help you someway my friend.
