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
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)