问题描述
我正在测试使用COM端口的应用程序.该应用程序正在Virtual PC中运行.我已经设置了Virtual PC设置,以将命名管道\.\ pipe \ mypipe用于COM1-Port.
现在,我正尝试使用C#与该命名管道进行通信.
using (var pipe = new NamedPipeServerStream(@"\\.\pipe\mypipe"))
{
pipe.WaitForConnection();
using (var reader = new StreamReader(pipe))
{
// Do some communication here
}
}
尽管Virtual PC正在运行,但程序正在等待WaitForConnection(),但我正在尝试与COM-Port通信.
我还尝试了以下操作,因为不确定是否必须在程序中创建命名管道,还是由Virtual PC创建了命名管道.
var p = new NamedPipeClientStream(@"pipe\mypipe");
p.Connect();
我在做什么错了?
将Virtual PC设置为使用命名管道作为COM端口时,它将充当服务器(如果是客户端,则VPC必须持续轮询新服务器,例如您的服务器崩溃了.
除了应该使用"mypipe"作为管道的名称而不是"pipe \ mypipe"作为管道的名称之外,您的第二种方法几乎可行.
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?
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".
这篇关于与Virtual PC的COM端口通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!