1

I am testing an application that uses the COM-Port. The application is running in Virtual PC. I have set up the Virtual PC settings to use the named pipe \.\pipe\mypipe for COM1-Port.

Now I am trying to communicate with this named pipe using C#.

using (var pipe = new NamedPipeServerStream(@"\\.\pipe\mypipe"))
{
    pipe.WaitForConnection();

    using (var reader = new StreamReader(pipe))
    {
       // Do some communication here
    }
}

The program is waiting at WaitForConnection() although Virtual PC is running and I am trying to communicate with the COM-Port.

I also tried the following, because I am not sure whether I have to create the named pipe in my program or the named pipe is created by Virtual PC.

var p = new NamedPipeClientStream(@"pipe\mypipe");

p.Connect();

What am I doing wrong here?

PetPaulsen
  • 3,442
  • 2
  • 22
  • 33

1 Answers1

2

When you set up Virtual PC to use a named pipe as a COM port, then it acts as the server (if it were the client then VPC would have to continuously poll for a new server if e.g. your server crashed).

Your second approach is almost on the mark, except that you should use "mypipe" as the pipe's name rather than "pipe\mypipe".

telewin
  • 1,102
  • 8
  • 17
  • Thank you! That did it. The communication is still not working though. Maybe you know the answer here, too? http://stackoverflow.com/questions/4907079/com-port-communication-with-virtual-pc-part-2 – PetPaulsen Feb 05 '11 at 13:24
  • @telewin Can you look into this then https://stackoverflow.com/questions/49715657/named-pipes-in-hyper-v-vm – user3552407 Apr 08 '18 at 09:45