serialport.Close()给出了System.IO.IOException

时间:2014-05-08 09:40:11

标签: c# serial-port avr virtual-serial-port

我有问题。使用此代码:

if (serialPort_avr.IsOpen) serialPort_avr.Close();

我收到错误:

> System.IO.IOException

如果端口已打开,那么为什么我无法将其关闭。 我的代码很长,没有必要粘贴它。 基本上我通过虚拟串口与AT90USBKEY通信(基于LUFA virtualserial示例)。我想在AVR拔出后再次自动重新打开连接,但是我无法关闭端口。 问题更详细:

System.IO.IOException was unhandled by user code
  HResult=-2146232800
  Message=The specified port does not exist.
  Source=System
  StackTrace:
       at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
       at System.IO.Ports.InternalResources.WinIOError()
       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 SefelecTester.MainWin.SetOnePort(Int32 port, Boolean state) in d:\9Backups\Dropbox\Loputoo\SefelecTester_DDC\SefelecTester\Form1.cs:line 394
       at SefelecTester.MainWin.TestEach() in d:\9Backups\Dropbox\Loputoo\SefelecTester_DDC\SefelecTester\Form1.cs:line 1665
       at SefelecTester.MainWin.TestWhile() in d:\9Backups\Dropbox\Loputoo\SefelecTester_DDC\SefelecTester\Form1.cs:line 1593
       at SefelecTester.MainWin.worker_test_DoWork(Object sender, DoWorkEventArgs e) in d:\9Backups\Dropbox\Loputoo\SefelecTester_DDC\SefelecTester\Form1.cs:line 1464
       at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
       at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
  InnerException: 

0 个答案:

没有答案