【发布时间】:2009-07-28 15:33:47
【问题描述】:
我在 Windows XP 嵌入式版本上运行 .Net 3.5 应用程序。此应用程序通过串行 (COM) 端口写入和读取一些数据。该应用程序在我的笔记本电脑(Windows XP Professional)上运行良好,但在 Windows XP 嵌入式上运行良好。我不断收到此错误:
System.IO.IOException:由于线程退出或应用程序请求,I/O 操作已中止。
可能是什么原因造成的?
一些附加信息:要阅读,我使用的是ReadExisting,而不是Readline。另外,在阅读之前,我要确保端口也已打开。
System.IO.IOException: The I/O operation has been aborted because of either a thread exit or an application request.
at System.IO.Ports.SerialStream.EndRead(IAsyncResult asyncResult)
at System.IO.Ports.SerialStream.Read(Byte[] array, Int32 offset, Int32 count, Int32 timeout)
at System.IO.Ports.SerialStream.Read(Byte[] array, Int32 offset, Int32 count)
at System.IO.Ports.SerialPort.ReadExisting()
at ScalesApp.Scales.handleDataReceived(Object sender, SerialDataReceivedEventArgs e)
at System.IO.Ports.SerialPort.CatchReceivedEvents(Object src, SerialDataReceivedEventArgs e)
at System.IO.Ports.SerialStream.EventLoopRunner.CallReceiveEvents(Object state)
at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
【问题讨论】:
-
您可以使用其他应用程序(如超级终端)的串口吗?
-
是的,我可以。我应该提一下这个问题,我的应用程序实际上可以通过串行端口进行通信,但一段时间后它会出现异常。
-
最好显示一些代码。
-
好吧,我不知道是代码的哪一部分导致了它。
标签: c# .net serial-port