简体   繁体   English

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

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

I am working on a Windows CE application which involves using the serial ports of the machine. 我正在使用Windows CE应用程序,该应用程序涉及使用计算机的串行端口。 However when I try to open a port it gives an IOException. 但是,当我尝试打开端口时,它给出了IOException。 Below is the example code: 下面是示例代码:

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

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

I have tried to close the connection before the open statement and also checked the IsOpen status before opening it (which is actually false before opening). 我试图在open语句之前关闭连接,并在打开之前检查过IsOpen状态(在打开之前实际上为false)。 The SerialPort.GetPortNames function gives back: COM1 / COM2 / COM5 / COM7. SerialPort.GetPortNames函数返回:COM1 / COM2 / COM5 / COM7。 I tried all including in a diffrend way like this: COM1: / COM2: / COM5: / COM7:. 我尝试了所有类似的尝试,包括:COM1:/ COM2:/ COM5:/ COM7:。 I can't seem to get it to work. 我似乎无法正常工作。

My first thought would be that I forgot to add something in the Windows CE image. 我首先想到的是,我忘记在Windows CE映像中添加一些内容。 But I can't seem to find anything in the catalog which would seem important for serial communication. 但是我似乎在目录中找不到任何对串行通讯似乎很重要的东西。

Does anyone have a thought on this? 有人对此有想法吗?


at System.IO.Ports.SerialStream.WinIOError() at System.IO.Ports.SerialStream.WinIOError() at System.IO.Ports.SerialStream.CheckResult() at System.IO.Ports.SerialStream.SetBufferSizes() at System.IO.Ports.SerialPort.Open() at commtest.Form1.button2_Click() at System.Windows.Forms.Control.OnClick() at System.Windows.Forms.Button.OnClick() at System.Windows.Forms.ButtonBase.WnProc() at System.Windows.Forms.Control._InternalWnProc() at Microsoft.AGL.Forms.EVL.EnterMainLoop() at System.Windows.Forms.Application.Run() at commtest.Program.Main() 在系统的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())

I don't know if you already have the answer to this yet but make sure you are using latest .NET CF version which is 3.5. 我不知道您是否已经对此有了答案,但是请确保您使用的是最新的.NET CF版本3.5。 There was a bug in the .NET CF 2.0 version that IOException created upon opening the serial port. 在打开串行端口时,IOException创建了.NET CF 2.0版本中的一个错误。 if you look up the bug fixed under .NET CF 2.0 SP you will see these mentioned. 如果您查找.NET CF 2.0 SP中修复的错误,则会看到这些错误。

Try the exact port name as you get it from GetPortNames() - including the colon 从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);

If that doesn't work, try "\\\\.\\COM7" 如果那不起作用,请尝试“ \\\\。\\ 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