Method 2: Enable Serial Port via Native Hyper-V Modes
You can use native Hyper-V methods to enable serial port. This process doesn't involve any third-party software solutions.
Unlike other virtualization solutions, Hyper-V doesn't allow a physical COM port to pass through directly. So, if you want to establish connection between the serial port of a host machine and a VM, you have the option to use some built-in features, such as
Enhanced Session Mode and
Named Pipes. Let's see how this works step-by-step instructions to achieve this.
Prerequisites
- Host machine: It has Windows as its operating system with Hyper-V installed in it.
- Guest VM: It runs a compatible Windows-based operating system (especially for features like Enhanced Session Mode to work).
- Physical COM Port: It's available on your host machine.
- Administrative privileges: Enable admin privileges on both your guest and host machines.
Mode 1: Using Enhanced Session Mode
NOTE: The Enhanced Session Mode works with only those Windows-based guest machines supporting Remote Desktop Protocol (RDP). Here's how this method works:
Step 1: Enable Enhanced Session Mode on the Host
Go to the Start menu on the host computer. Search and open Hyper-V Manager.
Enable Enhanced Session Mode Policy:
- Choose your Hyper-V host machine from the left pane.
- Next, look for “Actions” in the right pane and find and click on the Hyper-V Settings located under it.
- Find Enhanced Session Mode Policy under Server settings. Click on it.
- Check the box that says "Allow enhanced session mode".
- Click on OK.
Enable Enhanced Session Mode for User:
- In the same Hyper-V Settings window, find the option Enhanced Session Mode. Click on it.
- Check the box that says "Use enhanced session mode".
- Click on OK.
Step 2: Configure COM Port Redirection Settings
In your VM, start Configuring serial ports in Hyper-V settings for redirection. Start the VM: Go to the Hyper-V Manager. Now, right-click on your VM and choose “Connect”. In the VM connection window, you'll see a “Start” button. Click on it.
Adjust resources: In the connection window, look for "Show Options”. Click on it before you log into the VM.
- Go to "Local Resources"
- Under Local devices and resources, find and click on "More..."
- Expand "Ports"
- For the COM ports you wish to redirect, you'll find boxes next to them. Check the boxes
- Click on OK.
Login to your guest machine.
Step 3: Verify the COM Port in the Guest OS
Open Device Manager: Press Windows Key + X together and choose Device Manager from it. Check for all the redirected COM ports by expanding "Ports (COM & LPT)". It should contain entries such as COM1, COM2, etc.
Test the COM Port: Test the COM port by using serial communication software, such as
Advanced Serial Port Terminal, PuTTY, etc.
Pros and Cons of Implementing Enhanced Session Mode
Implementing the Enhanced Session Mode features comes with certain pros and cons that you must be aware of before you choose this method.
Pros:
- Cost-effective
The method uses native Windows and Hyper-V features, eliminating additional software expenses.
- Straightforward configuration
You can configure it effortlessly via the Hyper-V Manager settings.
- Security
For secure resource redirection, it uses Windows security models.
Cons:
- Supports only Windows
It supports only Windows systems, thus, it won't work for you if you use other operating systems.
- Limited functionality
In non-RDP environments and during VM boot-ups, it doesn't allow serial communication. In addition, its functionality or performance may not be as good as direct COM port access.
Enhanced Session Mode is better for users with basic needs, relying on Windows, and looking for cost-free options.
Mode 2: Using Named Pipes
This Hyper-V serial port method uses Named Pipes and requires you to configure the settings manually. It works on both Linux and Windows guest computers. Here's how to use it:
Step 1: Use PowerShell to Add a COM Port
In your VM, you'll need to add a COM port. Open PowerShell as Administrator: Locate the Start menu and right-click on it. Choose Windows PowerShell with admin privileges.
Add a COM Port: On the VM, Run this command:
Add-VMComPort -VMName "YourVMName" -Number 1 -Path \\.\pipe\HyperVSerialPort
NOTE:
Replace your VM’s name in - "YourVMName", where:
• Number → COM port number (inside the VM)
• Path → Named pipe (connecting the VM's COM port)
Test if the new COM is added, run this command:
Get-VMComPort -VMName "YourVMName"
Also, make sure you add the port properly.
Step 2: Configure the Named Pipe on the Host
- On the host, connect to the named pipe by using the application - Hyper-V Virtual Machine Connection. It's because Windows doesn't have a native functionality to connect a physical serial or COM port to a named pipe.
- But if you want to redirect the physical COM port to the named pipe, you'll need a different approach. For example, you can perform physical redirection over TCP/IP - Windows doesn't offer native support for it without additional software or scripting.
- Alternatively, use a built-in tool or PowerShell scripts to create a Serial to TCP/IP bridge if the application supports connecting to a network socket. This however exceeds native functionalities.
Pros and Cons of Using Named Pipes for Serial Port Access in Hyper-V
Using named pipe for Serial Port Access in Hyper-V comes with some pros and cons:
Pros
- Saves costs
The tool offers native Windows features, so you don't have to buy extra software.
- Cross-compatible
It supports both Windows and Linux guest machines.
Cons
- Complexity
The tool can be complex to set up as you need to configure it manually and may add some additional scripts to be able to connect the physical COM port to the VM using a named pipe.
- Lacks native support
Connecting physical COM ports to named pipes is not natively supported. You'll need extra workarounds to achieve that.
- Stability
Built-in functions are more reliable and stable than customized solutions.
Named pipes method is preferable for those with technical expertise in coding, handling configurations, and troubleshooting. It's good for people who can dedicate enough time for these activities and are looking for cost-effective options.
Final Recommendation
Users looking for an easier, less complex, and more reliable way to connect your host and guest machines via COM ports can choose Serial over Ethernet Connector. Although it needs investment, the cost will balance the advantages you get in terms of time and money savings, effortless setups, and professional support when in need.
However, if you face budget constraints in purchasing the software, you may go for native Hyper-V methods. Consider this method if you've technical skills to deal with named pipe setup complexities and write additional scripts if needed. It's also a viable solution if you work in Windows-only environments.