【问题标题】:What is the cause of System.IO.IOException on windows XP embedded version?Windows XP 嵌入式版本上 System.IO.IOException 的原因是什么?
【发布时间】: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


【解决方案1】:

问题是在 SetCommState 的 DCB 中启用了 fAbortOnError,这解释了 SerialPort 对象抛出的大多数 IOExceptions。一些 PC / 手持设备具有默认启用错误中止标志的 UART - 因此串行端口的 init 例程必须清除它(微软忽略了这样做)。 SerialPort 对象在设计时并未考虑启用 fAbortOnError。

我最近写了一篇长文来更详细地解释这一点(如果你有兴趣,see this)。

【讨论】:

    【解决方案2】:

    这在很大程度上取决于您的 Windows 嵌入式配置。

    您可能知道 windows xp Embedded 具有很强的可扩展性,您可以从 1000 多个要包含的软件包中进行选择。

    我们曾经在公司遇到过哔哔声没有从 citrix-session 转发到本地客户端的问题。经过反复试验,我们发现我们忘记了“哔声驱动器”。是的,存在 ;o)

    您是否已经使用 com 端口在机器上测试过任何其他应用程序?您可能需要在设备管理器中检查驱动程序是否被系统正确识别。

    如果您的控制面板中没有可用的选项,则需要将 Sysdm.cpl 从另一台计算机的 system32 文件夹复制到嵌入式系统上的文件夹。

    希望有帮助。

    问候

    【讨论】:

    • 好吧,我的应用程序可以通信一段时间,然后我收到错误,所以我认为一切都应该到位。但是我会仔细检查。
    • 一个非常讨厌的麻烦,几乎不可能调试它。但如果您能够沟通,问题可能出在其他地方……您是否检查过事件日志中已记录的消息?如果是,请发布其中的一些......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 1970-01-01
    • 2011-03-09
    • 2017-04-10
    • 2021-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多