Unlike many other virtualization solutions, it’s not particularly easy to connect a Windows 2008 Hyper-V guest to its host serial ports. Perversely, there are settings to connect the guest COM ports to “named pipes,” but there’s no way on the host to connect COM ports to named pipes. (It appears that this option is used primarily for debugging programs, rather than for using actual serial ports — it doesn’t appear to have been intended to be used to provide actual serial port access from the guest.)
The Hyper-V Deployment guide contains little more than this:
“Note: No access to a physical COM port is available from a virtual machine.”
What follows is a recipe to access the physical COM ports on the host from a guest using com0com, and its related utilities. The idea is to make a COM port on the host available via TCP/IP, and then attach to it via the guest, then make this process automatic.
First, on the guest, you’ll need an appropriate version of hub4com, and the batch file bundled with it, com2tcp-rfc2217.bat. Naturally, I’m running 64-bit Windows 2008, and there doesn’t appear to be a version compiled for 64-bit Windows, so I had to compile my own. This can be kind of a pain, especially if you’re using Visual Studio Express, so you’re welcome to download my 64-bit hub2com binaries here.
My device is on COM3, and I can make it available on port 7000 using the following command line:
com2tcp-rfc2217 COM3 7000
This gives me a DOS Window that shows me what’s going on — this is handy for debugging, but hardly something I want to leave on my screen all the time. The simplest solution is to create a launcher script:
Set objShell = CreateObject ("WScript.Shell")
objShell.Run "cmd /K CD C:\Program Files (x86)\com0com & com2tcp-rfc2217 COM3 7000", 0, false
This script effectively hides the program so that it can run in the background, so all that remains is to have it launch when the system starts. That’s best accomplished using the registry to create a new “Expandable String Value” under “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run”. It doesn’t matter what the Name of the String Value is, but the Data should be the command line necessary to launch the script:
%WinDir%\system32\wscript "C:\Program Files (x86)\com0com\com3-listen.vbs"
When done this way, the port is made available whether or not anybody is actually logged into the machine.
The guest is only slightly trickier, requiring both com0com and hub2com binaries to be installed. Since my guest is 32-bit Windows XP, I could use the precompiled “i386″ binaries directly from the c0m0com sourceforge page.
The com0com installer wants to create a null modem pair from “cnca0″ to “cncb0.” You’ll need this pair of virtual devices, and you’ll want to turn on “baud rate emulation,” and rename one end like a regular COM port. This can be accomplished from the com0com command line setup:
install EmuBR=yes EmuBR=yes change CNCA0 PortName=COM3
Once the virtual port pair is available, one end can be connected to the host, using the hub2com batch file com2tcp-rfc2217:
com2tcp-rfc2217 \\.\CNCB0 host-hostname 7000
As before, this opens a DOS Window where you can see what’s going on. At this point, COM3 on the guest is communicating directly with COM3 on the host. As before, a small launcher script is created to hide this window:
Set objShell = CreateObject ("WScript.Shell")
objShell.Run "cmd /K CD C:\Program Files\com0com & com2tcp-rfc2217 \\.\CNCB0 skypiea 7000", 0, false
And, as before, a registry string is added to the guest to launch this automatically in its own “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run” key.
%WinDir%\system32\wscript "C:\Program Files\com0com\com3-client.vbs"
Simple, eh? Well, perhaps not, but once it’s set up, the guest Hyper-V machine can communicate via COM3. Additional ports can be added in the same way.
Related posts:
Great article. I will definitely give it a try.
Do you know if this, or something similar, would work for USB ports.
We are trying to virtualise our fax server but I would need to attach a USB modem to the VM?
It should work fine for USB devices that provide a COM-style interface, like most modems and USB-serial converters. The guest will see the device as a traditional COM port, which should work fine. More specialized USB devices will need an alternative solution.
Just a note; this works great with Lantronix-style serial port servers (i.e. UDS2100.) The Lantronix devices have no 64-bit drivers (or even 32-bit drivers that will function on a 64-bit system) so com2tcp is a great replacement. You want to use the plain com2tcp though, not com2tcp-rfc2217. Just make sure all your devices are on the same baud setting and it should fire up like a champ. I’d actually recommend using a serial device server like this as opposed to a desktop PC; they’re not very expensive and it’s a more elegant production solution (plus you can mount the modem + device server to your telecom board and get that mess out of the way.)
Thanks for the tips about starting it automatically!
Excellent Post!
I tried it and it works.
But it only works if I log on to the host.
I missed something?
In my host the script only works with the session started. how can I put the script always running?
works with a schedule task
cool!
Looks good but my client want connect to server.
Server:
com2tcp-rfc2217.bat \\.\COM1 9999
…
Socket(0.0.0.0:9999) = 778
Listen(778) – OK
CLient:
command> list
Maybe someone can help me out
CNCA0 PortName=COM3
CNCB0 PortName=-
CNCA1 PortName=-,EmuBR=yes
CNCB1 PortName=-,EmuBR=yes
command>
com2tcp-rfc2217.bat \\.\CNCB0 192.168.1.253 9999
Err Msg on Client:
ERROR No such file or directory (2)
ComPort::Init(): Invalid handle
The most likely problem is that you haven’t opened the firewall for port 9999.
firewall is open
can connect to server with telnet with port 9999
Server Response with telnet connect
Accept(778) = 748 from 192.168.6.10:1129
TCP(1) START
TCP(1) SEND: WILL 1
TCP(1) SEND: DO 44
TCP(1) RECV: DO 1
TCP(1) RECV: WONT 44
TCP(1) SEND: DONT 44
TCP(1) RECV: WONT 44
Hi,
this is just what i need, but the 64 bit binary zip is saying that its corrupted or invalid, is it possible for someone to send it to me, or re-publish it on the web?!
cheers
Lee
Hi,
Like Lee said please re-publish 64-bit hub2com binaries, its already corrupted.
Also neeed this things to work.
Thanks.
Devonpaul
The archive is fine, as far as I can tell. Are you getting an error message or failing to unzip it?
So that you can verify your download isn’t mangling it in some way:
MD5 (hub2com.zip) = 9097de515f0d395a7f906dd13c425a19
Thanks, i was able to download it now, when continuing to follow the instruction above, i got error in last command step in guest machine. See command step and error below. Note, that i use the hub4com.exe that i downloaded from this site, is that right? or i need another version of hub4com.exe that compatible to my guest machine (32 bit?). If i am right, do you have available hub4com.exe for 32bit that i can download?
D:\temp\hub2com>com2tcp-rfc2217 \\.\CNCBO host-hostname 7000
D:\temp\hub2com>”hub4com” –create-filter=escparse,com,parse –create-filter=
pinmap,com,pinmap:”–rts=cts –dtr=dsr” –create-filter=linectl,com,lc:”–br=loc
al –lc=local” –add-filters=0:com –create-filter=telnet,tcp,telnet:” –comport
=client” –create-filter=pinmap,tcp,pinmap:”–rts=cts –dtr=dsr –break=break”
–create-filter=linectl,tcp,lc:”–br=remote –lc=remote” –add-filters=1:tcp –
octs=off “\\.\CNCBO” –use-driver=tcp “*host-hostname:7000″
The image file D:\temp\hub2com\hub4com.exe is valid, but is for a machine type o
ther than the current machine.
Thanks again,
Devonpaul
You’re exactly right — you need the 32-bit version of hub4com, which is available from the project site here:
http://sourceforge.net/projects/com0com/files/
@Christian: I had the same problem. Hit the device manager and reinstall the drivers on the splatted serial ports.
Hi queued,
I’m having same problem as Lee and Devonpaul… hub2com archive is corrupt after download. Ran the md5checker and codes don’t match. Any ideas as to why it’s getting mangled?
Is it possible to access it via FTP?
thanks,
Kathy
queued,
the same problem with hub2com.zip – archive is corrupted after download. DownLoader-
Ms Internet Explorer 7. Archive program winrar 311. Any ideas ?
Thanks,
SevaN.
I must say I’m fairly baffled. I don’t think it’s the archive itself, which is simply built using Windows 2008′s built in capabilities. From the md5 mismatch, I can only speculate that it’s being mangled upon download for some reason. This same server delivers a great many files, and this is the only file that draws complaints.
At any rate, you can try the same file through this link:
http://www.megaupload.com/?d=XECMOSJL
the megaupload opens, the other link also comes up as corrupt 4 me 2.
queued,
thanks, I have download Your hub2com.zip from http://www.megaupload.com/?d=XECMOSJL correct.
I’ll try to make fax server on gest machine by MS Hyper-V v.2 host system with real com ports.
Hi,
I’m having this error on host:
Started COM1(0)
Socket(0.0.0.0:7000) = 2c
Listen(2c) – OK
Started TCP(1)
Error COM1(0): BREAK, total RXOVER=0 OVERRUN=0 RXPARITY=0 FRAME=0
Error COM1(0): BREAK, total RXOVER=0 OVERRUN=0 RXPARITY=0 FRAME=0
Any ideas?
Trying to get this going running on xp32bit as guest and win7 as host. when running
com2tcp-rfc2217 \\.\CNCB0 host-hostname 7000 on guest i get the following:
C:\comcom>com2tcp-rfc2217 \\.\CNCB0 host-hostname 7000
C:\comcom>”hub4com” –create-filter=escparse,com,parse –create-filter=pinmap
,com,pinmap:”–rts=cts –dtr=dsr” –create-filter=linectl,com,lc:”–br=local –l
c=local” –add-filters=0:com –create-filter=telnet,tcp,telnet:” –comport=clien
t” –create-filter=pinmap,tcp,pinmap:”–rts=cts –dtr=dsr –break=break” –cre
ate-filter=linectl,tcp,lc:”–br=remote –lc=remote” –add-filters=1:tcp –octs=o
ff “\\.\CNCB0″ –use-driver=tcp “*host-hostname:7000″
WARNING: Can’t load C:\comcom\plugins\filter-awakseq.dll
WARNING: Can’t load C:\comcom\plugins\filter-crypt.dll
WARNING: Can’t load C:\comcom\plugins\filter-echo.dll
WARNING: Can’t load C:\comcom\plugins\filter-escinsert.dll
WARNING: Can’t load C:\comcom\plugins\filter-escparse.dll
WARNING: Can’t load C:\comcom\plugins\filter-linectl.dll
WARNING: Can’t load C:\comcom\plugins\filter-lsrmap.dll
WARNING: Can’t load C:\comcom\plugins\filter-pin2con.dll
WARNING: Can’t load C:\comcom\plugins\filter-pinmap.dll
WARNING: Can’t load C:\comcom\plugins\filter-purge.dll
WARNING: Can’t load C:\comcom\plugins\filter-tag.dll
WARNING: Can’t load C:\comcom\plugins\filter-telnet.dll
WARNING: Can’t load C:\comcom\plugins\filter-trace.dll
WARNING: Can’t load C:\comcom\plugins\port-connector.dll
The files are there windows splash screen comes up for each line telling me that the eg posrt-serial.dll is not a valid windows image…
Can u help
\Ta
Doug
“Not a valid windows image” is kind of a catch-all, but the two most common causes are 1) using the wrong binary on the system (e.g., 64 bit binary on 32 bit system) or 2) simple corruption of the binary.
Might seem like a silly question
When the vbs script is running on the host. How do I stop it
TA
DT
Thank you for your article. I am going to try it on Win 2008 RS Hyper V