Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Private Sub SerialPort1_DataReceived(sender As Object, e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived

        Dim bytRxBuff(CurrentUserRqst.iRcvLength) As Byte


        Dim iRcvdLength As Integer = SerialPort1.Read(bytRxBuff, 0, CurrentUserRqst.iRcvLength)

        SerialPort1.DiscardInBuffer()
        SerialPort1.DiscardOutBuffer()


        'Debug.EvaluateStatement(iRcvdLength)

        'Cls_Error.WriteToErrorLog(iRcvdLength.ToString, iRcvdLength.ToString, "Error")

        ProcessFrame(bytRxBuff, iRcvdLength)

    End Sub

    Private Sub Send_Frame(ByVal bytFrame As Byte(), ByVal iRcvLength As Integer)
   

 
            If bytFrame(1) = &HC Then
                SerialPort1.ReceivedBytesThreshold = 7
            Else
                SerialPort1.ReceivedBytesThreshold = iRcvLength
            End If


         
            If SerialPort1.IsOpen Then
                SerialPort1.Write(bytFrame, 0, bytFrame.Length)
            End If


            System.Threading.Thread.Sleep(100)

      
    End Sub


    Private Sub LatestDownload_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed


        If SerialPort1.IsOpen Then
            'SerialPort1.DataReceived -= Receive
            SerialPort1.DiscardInBuffer()
            SerialPort1.DiscardOutBuffer()
            SerialPort1.Close()
        End If

    End Sub



Where i close my form den it will give an error

the i/o operation has been aborted because of either a thread exit or an application request. serial
Posted
Updated 26-Oct-13 2:54am
v2

1 solution

Had you simply Googled the error message you got you would have found that this is a known bug in the SerialPort class.

You also would have found this blog post[^] about why it's a problem and how to get around it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900