开发者

COM port communication with Virtual PC

开发者 https://www.devze.com 2023-02-08 12:20 出处:网络
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 th开发者_运维技巧e named pipe \\.\\pipe\\mypipe for COM1-Port

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 th开发者_运维技巧e 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消