2

I am working on an Application to Connect to virtual machines(using Hyper-V). (I am using Virtual Machines now for Development, but the end-product will be physical Serial Connected Machines. not VM's) I have created a named pipe with the COM adaptor like this.

Creating the Named Pipe in Hyper-V

I am able to connect with PuTTy Like so.

Connection Information for PuTTy

Running a CentOS Build on the Hyper-V

Custom CentOS Terminal

I then wrote a simple Application to connect to it with C#

my_Serial_Port = new SerialPort();
my_Serial_Port.PortName = @"\\.\pipe\ttyS0";
my_Serial_Port.BaudRate = m_BaudRate;
my_Serial_Port.DataBits = 8;
my_Serial_Port.Parity = Parity.None;
my_Serial_Port.StopBits = StopBits.One;
my_Serial_Port.Handshake = Handshake.None;
my_Serial_Port.DtrEnable = true;
my_Serial_Port.RtsEnable = true;
my_Serial_Port.WriteTimeout = 15000;
my_Serial_Port.ReadTimeout = 15000;

my_Serial_Port.ErrorReceived += my_Serial_Port_ErrorReceived;

The thing is when I open the connection, I get this Exception thrown.

Parameter Portname Cannot Start with /

A little searching, and I found this information but no work-around. msdn.microsoft.com/en-us/library/system.io.ports.serialport.portname I have also Tried running my application as Administrator (Putty Needed this too) And it did not work.

With Oystein's Suggestion I tried:

string[] ports = SerialPort.GetPortNames();

string result = "The following serial ports were found:" + Environment.NewLine;

// Display each port name to the console.
foreach (string port in ports)
{
    result += port + Environment.NewLine;
}

MessageBox.Show(result);

Unfortunately COM1 is on the Physical Machine.

Only Found COM1

Does any one know how I can get this to work? Thanks!

HgMerk
  • 71
  • 11
  • 1
    Try using SerialPort.GetPortNames (https://msdn.microsoft.com/en-us/library/system.io.ports.serialport.getportnames(v=vs.110).aspx) to find what format the application sees the serialports as. – Oystein Jun 16 '18 at 16:57
  • Unfortunately it only Lists, COM1. – HgMerk Jun 16 '18 at 17:05
  • I have also ran the Command in the PowerShell PS C:\WINDOWS\system32> [System.IO.Directory]::GetFiles("\\.\\pipe\\") And can confirm that the pipe is present. – HgMerk Jun 16 '18 at 17:06

2 Answers2

0

You can Automate PuTTy Connections with PLink.

I read on another website this Answer. USE Plink

There is a plus side to this solution. I will be able to automate Serial and SSH connections with the same tool/wrapper. Using functions like

"Send_Command(string command);" 

and

"Wait_For_Prompt(string prompt, int timeout);"

I found this on Stack Overflow, which helped me to complete the project. Answer

Additionnally, PLink comes with the full install of Putty, and more usefull applications if you look where you installed it.

  • pageant.exe
  • plink.exe
  • pscp.exe (windows to linux File transfer)
  • psftp.exe
HgMerk
  • 71
  • 11
0

Hyper-V connects virtual COM port on guest to Win32 named pipe on Host. On host you should connect to named pipe (NamedPipeClientStream), not serial port.

OwnageIsMagic
  • 1,949
  • 1
  • 16
  • 31