Hyper-V Serial Ports and Windows 2008

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.

Share
Tagged , , , , . Bookmark the permalink.

58 Responses to Hyper-V Serial Ports and Windows 2008

  1. Thom says:

    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?

  2. queued says:

    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.

  3. Ryan says:

    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!

  4. Jose says:

    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?

  5. Jose says:

    works with a schedule task 🙂
    cool!

  6. Christian says:

    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

  7. queued says:

    The most likely problem is that you haven’t opened the firewall for port 9999.

  8. Christian says:

    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

  9. Lee Hill says:

    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

  10. devonpaul says:

    Hi,

    Like Lee said please re-publish 64-bit hub2com binaries, its already corrupted.
    Also neeed this things to work.

    Thanks.

    Devonpaul

  11. queued says:

    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

  12. devonpaul says:

    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

  13. queued says:

    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/

  14. GregG says:

    @Christian: I had the same problem. Hit the device manager and reinstall the drivers on the splatted serial ports.

  15. KathyM says:

    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

  16. SevaN says:

    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.

  17. queued says:

    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

  18. Wu Jen Yokomoto says:

    the megaupload opens, the other link also comes up as corrupt 4 me 2.

  19. SevaN says:

    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.

  20. MP says:

    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?

  21. Doug Taylor says:

    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

  22. queued says:

    “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.

  23. Doug Taylor says:

    Might seem like a silly question

    When the vbs script is running on the host. How do I stop it

    TA

    DT

  24. Bob Springer says:

    Thank you for your article. I am going to try it on Win 2008 RS Hyper V

  25. KALRONG says:

    First thanks for the article.

    It worked after a lot of test, not your fault, the cable I was using wasnt working propertly, also the vbs script wasnt coming automatically on the client (I still need to test if it works with the server, but is not that easy to restart a server several times to see if it works) so what I did to fix this problem was to create a vbs script that just run a bat file hide, using the same line but instead of opening the software opening the bat file, and in the bat file I just put the command to run the hub4com, and it worked smoothly.

    And many thanks for the 64 bits version of the hub4com without it anything will work 🙂

  26. tvxlc says:

    Thank you for this article. Helped me a lot.

    Had a problem with the Digital Super Hybrid System which is connected via COM port to our company’s server. We have an application which logs information about the phone incoming/outgoing calls to a SQL database. It does that by using Telephony Service Provider (TSP) which is installed on a server.

    We recently upgraded server’s hardware and moved from Windows Server 2003 32bit to a Windows Server 2008 R2 64bit. I was unable to install the TSP on a new OS. Perhaps it lacked the 64bit support or maybe I did something wrong.

    Anyways, I added a Hyper-V role on server, installed a virtual Windows Server 2003 and run the application on it. With the help of your article and hub2com binary you compiled for a 64bit OS, I connected a physical COM port of the physical server to a virtual port of the virtual machine. I then used Schedules Tasks to run the commands mentioned in your VBS scripts at the system startup. Now the application works fine!

    Thanks again!

  27. Steve says:

    Dude, this saved my ass with a TimeTrax EZ RS232 time clock, thanks for posting this, I’m spreading the word!

  28. Pingback: Hyper-V Virtual Fax Server in SBS 2008

  29. Dmitriy says:

    Thx!!!! All work fine! 🙂

  30. KevinZ says:

    This article is very helpful, thanks.

    I managed to run com0com on 32bit xp as host and Server 2003 32bit as guest, everything is ok. But when I try to setup a server 2008 64bit as host with this error:
    C:\Program Files (x86)\com0com>com2tcp-rfc2217 COM1 10000

    C:\Program Files (x86)\com0com>”hub4com” –create-filter=escparse,com,parse –create-filter=purge,c
    om,purge –create-filter=pinmap,com,pinmap:”–rts=cts –dtr=dsr –break=break” –create-filter=line
    ctl,com,lc:”–br=remote –lc=remote” –add-filters=0:com –create-filter=telnet,tcp,telnet:” –compo
    rt=server –suppress-echo=yes” –create-filter=lsrmap,tcp,lsrmap –create-filter=pinmap,tcp,pinmap:
    “–cts=cts –dsr=dsr –dcd=dcd –ring=ring” –create-filter=linectl,tcp,lc:”–br=local –lc=local” –
    -add-filters=1:tcp –octs=off “COM1” –use-driver=tcp “*10000”
    ComIo::Open(): CreateFile(“COM1”) ERROR Input/output error (5)
    ComPort::Init(): Invalid handle

    Please help.

  31. queued says:

    This probably means there’s already a COM1 on the system. I’d suggest trying a different COM port.

  32. KevinZ says:

    The server has only one phisical COM1 port which the modem is connected to.

  33. queued says:

    Actually, I just looked more closely at your original comment, and I noticed you’re attempting to use the 32-bit com0com on a 64-bit platform. That won’t work. You can use the 64-bit version available for download above.

  34. JC says:

    Hello,

    Same problem than Christian:

    Server 2008
    com2tcp-rfc2217.bat \\.\COM1 7000
    All OK

    CLient:
    CNCA0 PortName=COM1
    CNCB0 PortName=-
    CNCA1 PortName=-,EmuBR=yes
    CNCB1 PortName=-,EmuBR=yes

    com2tcp-rfc2217 \\.\CNCB0 192.168.1.200 7000
    But Err Msg :
    ERROR No such file or directory (2)
    ComPort::Init(): Invalid handle

    What can I do ?

  35. Charlie says:

    I think this might be a typo since on these lines you mention the guest :

    “First, on the guest, you’ll need an appropriate vers..”

    “The guest is only slightly trickier, requiring bo…”

    but never say what to do on the host..

  36. numpa says:

    Unfortunately, it doesn’t work well for me. I need a dial-up connection from the guest. With the solution described here I was able to map COM port to the guest and establish a dial-up connection from there at 38.4 kbps. But the real speed was extremely slow, about 300 baud, and I don’t know why. So, I’m still searching for an appropriate solution.

  37. Daniel says:

    Thanks for the instructions, queued.

    Using this info I’ve set up a guest win2003r2 server under a Win2008r2 host.

    I’ve also installed the Microsoft fax server in the guest computer, connecting it to the physical COM ports of the host machine.

    However, this setup is VERY unreliable. Most faxes fail in the middle of the transmission and it’s very difficult to receive faxes that are longer than just 1 page.

    Has anyone managed to get Windows 2003 Fax Server working correctly under Hyper-V using this method??

  38. queued says:

    Unfortunately, FAXes are very subject to timing issues (e.g., jitter) – depending on the Class in which the modem is operating (1 or 2) your results may vary considerably as the guest OS will try to handle timing in Class 1, which may be tricky if it’s not getting enough CPU cycles or if TCP/IP isn’t delivered immediately. A bigger box might help, as might increasing the baud rate as much as possible (i.e., the baud rate between the computer and modem, not the bit rate of the FAX.) Ideally, switch to Class 2.

  39. jared says:

    Will this work on just a base core load of hyper-V or does the host have to be full blown windows 2008 that is also the hyper-v

  40. queued says:

    It will definitely work on a base core load of hyper-V — it will actually work on any VM host/guest combination.

  41. Daniel says:

    Thanks a lot for your comments, queued.

    Unfortunately, I’ve tried with various baudrates (also enabling baud-rate emulation on the guest), but the result is the same.

    My faxmodem supports class 2.0 (it’s an US Robotics 5630G faxmodem), and I’ve upgraded it to the latest available firmware.

    It has improved a little bit, but not enough. The vast majority of the faxes fail, only a small percentage arrive correctly.

    It’s a pity, because the faxmodem works very well when used directly in the physical host. No problems at all.

    It’s a shame that Microsoft crippled the fax server of Windows 2008 so severely. You cannot set different permissions for your users, and the administrator cannot even see the outbox folder from other users! It’s horrible and unusable for us.

    That’s why I thought that maybe running Win2003 under Hyper-V could be our salvation. The fax server of Windows 2003 worked very very well and was not deliberately crippled by Microsoft.

    I guess we’ll have no other option but to buy a 3rd party fax software… damn it!

  42. Pingback: Hyper-V Virtual Fax Server in SBS 2008 - Admins Goodies

  43. Imran says:

    I am trying to Redirect the Serial Mouse which is connected at COM1. When i try to access it on Remote Side, I am unable to Install it. What can be the problem? can we Redirect Serial Mouse?

    I get this error too.

    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

  44. queued says:

    There’s no inherent problem with a serial mouse that I know of, but I haven’t tried it … I believe the BREAK message happens when the pair is connected in telnet mode, which probably won’t work for a serial mouse, you’ll want to use baud rate emulation and peg it to what the serial mouse uses (usually 9600, as I recall.)

  45. imran says:

    queued,

    I appreciate your help. Here is Complete scenario. I
    want to Redirect my Serial Port (COM1) to the Remote PC. I just want that Physical Serial Port must be redirected to the Remote PC. I have Serial Mouse attached with COM1 and when i redirect my Serial Port i am unable to get this mouse installed on Remote PC.

    com2tcp-rfc2217 COM1 7000

    what i do on remote PC is
    com2tcp-rfc2217 \\.\CNCB0 host-hostname 7000

    How can it be done using Com0Com and Hub4com? Any help is highly appreciated. I used com2tcp, Com2tcp-esc, com2tcp-rfc2217, but nothing works the way it should.

    What can be the issue?

  46. Schubacka says:

    Hi Guys,
    where can i find a downloadable x64 version of hub2com? The link isn`t working… HELP!

  47. Shaun says:

    Hi queued

    Thanks for the great how to, all other alternatives invlove costs that not all of us are willing to or can afford.

    I need the 64bit binary for hub4com that you compiled. Im having the same problem getting the file from your blog site and well, megaupload has finaly been nailed by the feds.

    Could you upload to another file share? Or some other alternative?

    Thanks for the great work and sharing your knowlege and experience.

  48. queued says:

    I’ll have a download link working/restored by the weekend.

  49. Shaun says:

    Thanks, I’m sure it will help others but after I got going I realized that it’s completely unnecessary, the hub4com386 works just fine on server 2008 R2 SP1 x64 cause it’s only listening on a physical COM port, no driver installation necessary.

    The only time you would need different x86 or x64 packages would be for the actual com0com which emulates the COM port on the guest.

    I got my setup working in 15mins after I figured that out.

    Thanks again.

  50. Gerardo Marciales says:

    Hello, thank for the information, to me at the begin was so difficult, reading many moment I can understand, I try, work perfectly!

    Cheers!

Leave a Reply

Your email address will not be published. Required fields are marked *

By submitting this form, you accept the Mollom privacy policy.

This site uses Akismet to reduce spam. Learn how your comment data is processed.