Hi, I am getting a similar error. I am just trying to read from a serial COM port. It works fine. Then if I open and close the COM port a few times I get the following error when trying to open again:
The I/O operation has been aborted because of either a thread exit or an application request.
Starnagely enough the error is still tehre if I stop debugging (VisualStuio 2008, vb.net) and start again. The only way I can get it to work again is by opening and closing the port with hyperterminal! Here is my wrapper class:
Public Class clComPort
Private WithEvents comPort As System.IO.Ports.SerialPort
Private write As Boolean = True
Private bAllowSndRcv As Boolean = False
Private thRec As System.Threading.Thread
Public Event WroteData(ByVal msg As String)
Public Event DataRecieved(ByVal msg As String)
Public Event COMError(ByVal msg As String)
Public Function OpenPort(ByVal ComNum As Integer, ByVal baudRate As Integer, ByVal dataBits As Integer, _
ByVal parity As IO.Ports.Parity, ByVal stpBits As IO.Ports.StopBits) As Boolean
bAllowSndRcv = False
Try
'first check if the port is already open
'if its open then close it
If Not IsNothing(comPort) Then
Me.ClosePort()
End If
comPort = New System.IO.Ports.SerialPort()
'set the properties of our SerialPort Object
comPort.BaudRate = Integer.Parse(baudRate)
comPort.DataBits = Integer.Parse(dataBits)
comPort.StopBits = stpBits
comPort.Parity = parity
comPort.PortName = "COM" & ComNum
comPort.ReadTimeout = 500
comPort.WriteTimeout = 500
'now open the port
Dim b As Boolean = comPort.IsOpen
comPort.Open()
bAllowSndRcv = True
'return true
Return True
Catch ex As Exception
bAllowSndRcv = False
RaiseEvent COMError(ex.Message)
Return False
End Try
End Function
Public Sub ClosePort()
bAllowSndRcv = False
If IsNothing(comPort) Then Exit Sub
If comPort.IsOpen Then
RemoveHandler comPort.DataReceived, AddressOf comPort_DataReceived
comPort.Close()
End If
comPort.Dispose()
End Sub
Private Sub comPort_DataReceived(ByVal sender As Object, _
ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles comPort.DataReceived
'This event will Receive the data from the selected COM port..
If Not bAllowSndRcv Then Exit Sub
If e.Eve