繁体   English   中英

无法在Windows CE应用程序上打开Serialport

[英]Can't open serialport on Windows CE application

我正在使用Windows CE应用程序,该应用程序涉及使用计算机的串行端口。 但是,当我尝试打开端口时,它给出了IOException。 下面是示例代码:

SerialPort NewSerialPort = new SerialPort("COM7", 115200, Parity.None, 8, StopBits.One);
NewSerialPort.Handshake = Handshake.None;

//opening the serial port
NewSerialPort.Open();

我试图在open语句之前关闭连接,并在打开之前检查过IsOpen状态(在打开之前实际上为false)。 SerialPort.GetPortNames函数返回:COM1 / COM2 / COM5 / COM7。 我尝试了所有类似的尝试,包括:COM1:/ COM2:/ COM5:/ COM7:。 我似乎无法正常工作。

我首先想到的是,我忘记在Windows CE映像中添加一些内容。 但是我似乎在目录中找不到任何对串行通讯似乎很重要的东西。

有人对此有想法吗?


在系统的System.IO.Ports.SerialStream.SetBufferSizes()的System.IO.Ports.SerialStream.WinIOError()的System.IO.Ports.SerialStream.WinIOError()处.IO.Ports.SerialPort.Open()在commtest.Form1.button2_Click()在System.Windows.Forms.Control.OnClick()在System.Windows.Forms.Button.OnClick()在System.Windows.Forms.ButtonBase System.Windows.Forms.Control._InternalWnProc()(位于Microsoft.AGL.Forms.EVL.EnterMainLoop()位于System.Windows.Forms.Application.Run()(commtest.Program.Main())

我不知道您是否已经对此有了答案,但是请确保您使用的是最新的.NET CF版本3.5。 在打开串行端口时,IOException创建了.NET CF 2.0版本中的一个错误。 如果您查找.NET CF 2.0 SP中修复的错误,则会看到这些错误。

从GetPortNames()获得它时,尝试使用确切的端口名-包括冒号

SerialPort NewSerialPort = new SerialPort("COM7:", 115200, Parity.None, 8, StopBits.One);

// or

string[]   portNames     = SerialPort.GetPortNames()
SerialPort newSerialPort = new SerialPort(portNames[3], , 115200, Parity.None, 8, StopBits.One);

如果那不起作用,请尝试“ \\\\。\\ COM7”

SerialPort NewSerialPort = new SerialPort("\\.\COM7", 115200, Parity.None, 8, StopBits.One);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM