COM port communication with Virtual PC

[亡魂溺海] 提交于 2019-12-08 07:16:57

问题


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?


回答1:


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".



来源:https://stackoverflow.com/questions/4906784/com-port-communication-with-virtual-pc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!