The device adhere to J1587/ J1708 protocol, there are no end delimiters like CR, ETX. However its message start with MID + data + checksum. MID should be 128. and checksum (2's sum of all bytes) should be equal to 0. How can I use the two conditions to build the telegram.
Private Sub ComPort_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles ComPort.DataReceived
Dim nbytes As Integer = ComPort.BytesToRead
Dim comBuffer(nbytes - 1) As Byte 'create a byte array to hold the awaiting data
Dim NumberOfBytesRead As Integer
NumberOfBytesRead = ComPort.Read(comBuffer, 0, nbytes) ' {128,254,179,25,170,12}
Dim i As Integer
If comBuffer(0) = 128 Then
Do While i < NumberOfBytesRead
InputStreamBuilder &= Hex(comBuffer(i))
i += 1
Loop
End If
Dim intChkSum As Integer = 0 'validate received data
For j As Integer = 0 To NumberOfBytesRead - 1
intChkSum = (intChkSum + comBuffer(j)) And &HFF
Next
If intChkSum = 0 Then
'RXArray = Bytes2Hex(comBuffer)
RXArray = BitConverter.ToString(comBuffer).Replace("-", " ").ToCharArray() '80 FE B3 19 AA 0C'
RXCnt = RXArray.Length
Else
Exit Sub
End If
Me.Invoke(New MethodInvoker(AddressOf Display))
End Sub