Sub AStream_NewData (Buffer() As Byte) 'Serial Receive interrupt routine
If RxEnabled = False Then
Return
End If
RxPacket = RxPacket & BytesToString(Buffer, 0, Buffer.Length, "UTF8")
'Since we arnt using Prefix mode, The entire packet may not have arrived when this event is triggered.
'Since we are doing length and checksummed packets, We test for a valid packet and length before releasing the packet.
If Len(RxPacket) > 4 Then
PacketLength = Len(RxPacket) / 2 'Length of packet
TestLength = HexString(Mid(RxPacket, 3, 2)) 'Send Length byte
TestLength = TestLength + 4 'Include header byte, Length byte, checksum byte, and character return (AVR Print) as part of the length. Ensure full data packet recpetion.
If TestLength = PacketLength Then
RxHandler
RxPacket = ""
End If
End If
Return
End Sub