'Add these libraries in Manage Libraries:
'rCore
'rSerial
'rAsyncStreams
Sub Process_Globals
Public Serial1 As Serial
Private astream As AsyncStreams
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
astream.Initialize(Serial1.Stream, "astream_NewData", "astream_Error")
Log("Serial communication ready")
End Sub
Sub astream_NewData (Buffer() As Byte)
Dim receivedText As String
receivedText = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
Log("Received: ", receivedText.Trim)
' Echo back
Dim response As String = "Echo: " & receivedText.Trim & CRLF
astream.Write(response.GetBytes("UTF8"))
End Sub
Sub astream_Error
Log("Stream error")
End Sub