Click here to Skip to main content
15,907,913 members

Comments by AAhsan24 (Top 1 by date)

AAhsan24 28-Jan-21 8:21am View    
Thanks RickZeeland for help

After updating timer to event handler, my main Window Freeze while updating File.

Private Sub initCommPort()
If SerialPort1.IsOpen = False Then
SerialPort1.PortName = ListBox1.SelectedItem
SerialPort1.BaudRate = 115200
SerialPort1.Parity = Parity.None
SerialPort1.DataBits = 8
SerialPort1.StopBits = StopBits.One
SerialPort1.ReadTimeout = 100


'SerialPort1.ReceivedBytesThreshold = 100
SerialPort1.DiscardNull = True

Try
SerialPort1.Open()
rs232Timer.Interval = 1
rs232Timer.Start()
vcapMin1 = 9999
vcapMax1 = 0
vcapMin2 = 9999
vcapMax2 = 0
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
' ONCE PORT IS INITIALISED, RECEIPT OF DATA KICKS EVERYTHING OFF ...
End Sub

' This is the method to run when the rs232Timer is raised.
'Private Sub TimerEventProcessor(ByVal myObject As Object, ByVal myEventArgs As EventArgs) Handles rs232Timer.Tick
Private Sub SerialPort_DataReceived(sender As Object, e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
'rs232Timer.Stop()
Do
Try
Dim Incoming As String = SerialPort1.ReadLine()
If Incoming Is Nothing Then
Exit Do
Else
Dim packet As String = Incoming
Incoming = Nothing
If (RequestCmd > 0) Then
If SerialPort1.IsOpen = True Then
SerialPort1.Write(Chr(RequestCmd))
System.Diagnostics.Debug.WriteLine("CMD: " & RequestCmd)
RequestCmd = 0
Else
System.Diagnostics.Debug.WriteLine("CMD: " & RequestCmd)
End If
End If
Me.BeginInvoke(New StringSubPointer(AddressOf ProcessData), packet)

End If
Catch ex As Exception
Exit Do
End Try
Loop

'rs232Timer.Start()
End Sub

Private Sub ProcessData(ByVal Buffer As String)
Dim rawLine As String
If Buffer.Length > 0 Then
Select Case Mid(Buffer, 1, 1)
Case "P" 'PON registers
processPonRegs(Buffer)
If (Mid(Buffer, 2, 1) = "1") Then
If (p1Active = True) Then
rawLine = Mid(Buffer, 1, 2) & " " & Mid(Buffer, 3, 16) & " " & Mid(Buffer, 19, 16) & " " & Mid(Buffer, 35, 16) & " " & Mid(Buffer, 51, 16)
storeRawDataLine(rawLine, 2)
rawLine = " " & Mid(Buffer, 67, 16) & " " & Mid(Buffer, 83, 16) & " " & Mid(Buffer, 99, 16) & " " & Mid(Buffer, 115, 16)
storeRawDataLine(rawLine, 3)
End If
Else
If (p2Active = True) Then
rawLine = Mid(Buffer, 1, 2) & " " & Mid(Buffer, 3, 16) & " " & Mid(Buffer, 19, 16) & " " & Mid(Buffer, 35, 16) & " " & Mid(Buffer, 51, 16)
storeRawDataLine(rawLine, 4)
rawLine = " " & Mid(Buffer, 67, 16) & " " & Mid(Buffer, 83, 16) & " " & Mid(Buffer, 99, 16) & " " & Mid(Buffer, 115, 16)
storeRawDataLine(rawLine, 5)
End If
End If
Case "T" 'Trace Buffer Data
'saveTraceBufferLine(Buffer, TBConfiguration)
My.Computer.FileSystem.Writ