日期:2014-05-17  浏览次数:21534 次

串口无故被关闭
程序从二次表上取重量数据,并将串口接收到的数据都显示到richtextbox中。但有时这些数据就自动不再更新了。查看异常日志发现


2012-07-20 12:03:38发生系统异常。
ThreadExceptionEventArgs
由于线程退出或应用程序请求,已放弃 I/O 操作。

  at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
  at System.IO.Ports.SerialStream.Dispose(Boolean disposing)
  at System.IO.Stream.Close()
  at System.IO.Ports.SerialPort.Dispose(Boolean disposing)
  at System.IO.Ports.SerialPort.Close()
  at GatherWeight.FrmGather.FrmGather_FormClosing(Object sender, FormClosingEventArgs e)
  at System.Windows.Forms.Form.OnFormClosing(FormClosingEventArgs e)
  at System.Windows.Forms.Form.WmClose(Message& m)
  at System.Windows.Forms.Form.WndProc(Message& m)
  at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
  at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
  at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


2012-07-20 12:03:38发生系统异常。
System.ObjectDisposedException: Safe handle has been closed
  at Microsoft.Win32.UnsafeNativeMethods.WaitCommEvent(SafeFileHandle hFile, Int32& lpEvtMask, NativeOverlapped* lpOverlapped)
  at System.IO.Ports.SerialStream.EventLoopRunner.WaitForCommEvent()
  at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
  at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
  at System.Threading.ThreadHelper.ThreadStart()


有这两个异常信息。但是以前程序一直运行正常的,怎么今天突然会出现这种情况呢?和二次表的连接线是正常的。今天发生过好几次这种异常了。串口自动关闭。。。
请问如何解决呢

------解决方案--------------------
也许和硬件有关系啊,这个你还是仔细跟跟吧,加一些错误输出