Serial port (e.g., COM3) to named pipe (e.g., \\.\pipe\com2) connector
There are several projects that do similar thing:
However, they do not support running them as Windows Service or they have been abandoned by the maintainers.
Main use case for this connector is to run Home Assistant Operating System in Hyper-V VM and connect it to serial devices (e.g., Zigbee dongle) on the host.
Here is sequence diagram to illustrate how it works:
sequenceDiagram
autonumber
Zigbee dongle->>+Windows: USB Serial device (COM3)
Windows->>+SerialPort2NamedPipeConnector: Read from serial port
Note left of Hyper-V: Set-VMFirmware –Vmname "home assistant"<br/>–EnableSecureBoot Off
Note left of Hyper-V: Set-VMComPort -VMName "home assistant"<br/>-Number 2 -Path \\.\pipe\com2
SerialPort2NamedPipeConnector->>+Hyper-V: Write to named pipe<br/>\\.\pipe\com2
Hyper-V->>+Home Assistant OS: /dev/ttyS0
Home Assistant OS->>+Zigbee Home Automation: Read from serial port
Note right of Zigbee Home Automation: Home Assistant<br/>Integration
Zigbee Home Automation->>+Home Assistant OS: Write to serial port
Home Assistant OS->>+Hyper-V: /dev/ttyS0
Hyper-V->>+SerialPort2NamedPipeConnector: Read from named pipe<br/>\\.\pipe\com2
SerialPort2NamedPipeConnector->>+Windows: Write to serial port
Windows->>+Zigbee dongle: USB Serial device (COM3)
Create COM port for virtual machine and map that to named pipe:
Set-VMFirmware –Vmname "home assistant" –EnableSecureBoot Off
Set-VMComPort -VMName "home assistant" -Number 2 -Path \\.\pipe\com2
Validate the mapping:
Get-VMComPort -VMName "home assistant"
VMName Name Path
------ ---- ----
Home assistant COM 1
Home assistant COM 2 \\.\pipe\com2
sc.exe create "Serial port to named pipe connector" binPath="C:\Path\To\SerialPort2NamedPipeConnector.exe"
Note: COM 1 might be used for serial console, so safer to use use COM 2.
Create a Windows Service using BackgroundService
How to: Use Named Pipes for Network Interprocess Communication
How can I enable kernel debugging by using a COM port on a generation 2 virtual machine?
Configure UART/COM in Linux using Hyper-V Generation 2 VM