{"id":214,"date":"2010-02-02T14:02:16","date_gmt":"2010-02-02T20:02:16","guid":{"rendered":"http:\/\/www.goodjobsucking.com\/?p=214"},"modified":"2010-02-02T14:27:31","modified_gmt":"2010-02-02T20:27:31","slug":"hyper-v-serial-ports-and-windows-2008","status":"publish","type":"post","link":"http:\/\/www.goodjobsucking.com\/?p=214","title":{"rendered":"Hyper-V Serial Ports and Windows 2008"},"content":{"rendered":"<p>Unlike many other virtualization solutions, it&#8217;s not particularly easy to connect a Windows 2008 Hyper-V guest to its host serial ports.\u00a0 Perversely, there are settings to connect the guest COM ports to &#8220;named pipes,&#8221; but there&#8217;s no way on the host to connect COM ports to named pipes.\u00a0 (It appears that this option is used primarily for debugging programs, rather than for using actual serial ports &#8212; it doesn&#8217;t appear to have been intended to be used to provide actual serial port access from the guest.)<\/p>\n<p>The Hyper-V Deployment guide contains little more than this:<\/p>\n<p>&#8220;Note:\u00a0 No access to a physical COM port is available from a virtual machine.&#8221;<\/p>\n<p>What follows is a recipe to access the physical COM ports on the host from a guest using <a title=\"com0com\" href=\"http:\/\/com0com.sourceforge.net\/\">com0com<\/a>, and its related utilities.\u00a0 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.<\/p>\n<p>First, on the guest, you&#8217;ll need an appropriate version of hub4com, and the batch file bundled with it, com2tcp-rfc2217.bat.\u00a0 Naturally, I&#8217;m running 64-bit Windows 2008, and there doesn&#8217;t appear to be a version compiled for 64-bit Windows, so I had to compile my own.\u00a0 This can be kind of a pain, especially if you&#8217;re using Visual Studio Express, so you&#8217;re welcome to download my 64-bit hub2com binaries <a title=\"64-bit hub2com\" href=\"http:\/\/www.houseofqueued.com\/hub2com.zip\">here<\/a>.<\/p>\n<p>My device is on COM3, and I can make it available on port 7000 using the following command line:<\/p>\n<pre>com2tcp-rfc2217 COM3 7000<\/pre>\n<p>This gives me a DOS Window that shows me what&#8217;s going on &#8212; this is handy for debugging, but hardly something I want to leave on my screen all the time.\u00a0 The simplest solution is to create a launcher script:<\/p>\n<pre>Set objShell = CreateObject (\"WScript.Shell\")\r\nobjShell.Run \"cmd \/K CD C:\\Program Files (x86)\\com0com &amp; com2tcp-rfc2217 COM3 7000\", 0, false<\/pre>\n<p>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.\u00a0 That&#8217;s best accomplished using the registry to create a new &#8220;Expandable String Value&#8221; under &#8220;HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run&#8221;.\u00a0 It doesn&#8217;t matter what the Name of the String Value is, but the Data should be the command line necessary to launch the script:<\/p>\n<pre>%WinDir%\\system32\\wscript \"C:\\Program Files (x86)\\com0com\\com3-listen.vbs\"<\/pre>\n<p>When done this way, the port is made available whether or not anybody is actually logged into the machine.<\/p>\n<p>The guest is only slightly trickier, requiring both com0com and hub2com binaries to be installed.\u00a0 Since my guest is 32-bit Windows XP, I could use the precompiled &#8220;i386&#8221; binaries directly from the <a title=\"com0com binaries and files\" href=\"http:\/\/sourceforge.net\/projects\/com0com\/files\/\">c0m0com sourceforge page<\/a>.<\/p>\n<p>The com0com installer wants to create a null modem pair from &#8220;cnca0&#8221; to &#8220;cncb0.&#8221;\u00a0 You&#8217;ll need this pair of virtual devices, and you&#8217;ll want to turn on &#8220;baud rate emulation,&#8221; and rename one end like a regular COM port. \u00a0\u00a0 This can be accomplished from the com0com command line setup:<\/p>\n<pre>install EmuBR=yes EmuBR=yes\r\nchange CNCA0 PortName=COM3<\/pre>\n<p>Once the virtual port pair is available, one end can be connected to the host, using the hub2com batch file com2tcp-rfc2217:<\/p>\n<pre>com2tcp-rfc2217 \\\\.\\CNCB0 host-hostname 7000<\/pre>\n<p>As before, this opens a DOS Window where you can see what&#8217;s going on.\u00a0 At this point, COM3 on the guest is communicating directly with COM3 on the host.\u00a0 As before, a small launcher script is created to hide this window:<\/p>\n<pre>Set objShell = CreateObject (\"WScript.Shell\")\r\nobjShell.Run \"cmd \/K CD C:\\Program Files\\com0com &amp; com2tcp-rfc2217 \\\\.\\CNCB0 skypiea 7000\", 0, false<\/pre>\n<p>And, as before, a registry string is added to the guest to launch this automatically in its own &#8220;HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run&#8221; key.<\/p>\n<pre>%WinDir%\\system32\\wscript \"C:\\Program Files\\com0com\\com3-client.vbs\"<\/pre>\n<p>Simple, eh?\u00a0 Well, perhaps not, but once it&#8217;s set up, the guest Hyper-V machine can communicate via COM3.\u00a0 Additional ports can be added in the same way.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unlike many other virtualization solutions, it&#8217;s not particularly easy to connect a Windows 2008 Hyper-V guest to its host serial ports.\u00a0 Perversely, there are settings to connect the guest COM ports to &#8220;named pipes,&#8221; but there&#8217;s no way on the host to connect COM ports to named pipes.\u00a0 (It appears \u2026 <a class=\"continue-reading-link\" href=\"http:\/\/www.goodjobsucking.com\/?p=214\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[113,114,111,115,112],"_links":{"self":[{"href":"http:\/\/www.goodjobsucking.com\/index.php?rest_route=\/wp\/v2\/posts\/214"}],"collection":[{"href":"http:\/\/www.goodjobsucking.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.goodjobsucking.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.goodjobsucking.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.goodjobsucking.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=214"}],"version-history":[{"count":4,"href":"http:\/\/www.goodjobsucking.com\/index.php?rest_route=\/wp\/v2\/posts\/214\/revisions"}],"predecessor-version":[{"id":217,"href":"http:\/\/www.goodjobsucking.com\/index.php?rest_route=\/wp\/v2\/posts\/214\/revisions\/217"}],"wp:attachment":[{"href":"http:\/\/www.goodjobsucking.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodjobsucking.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=214"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodjobsucking.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}