the question isn't how to detect the end of a receive stream it is how do I stop a loop that sends commands to the TSA from incrementing on until I the eof from the NewData sub has been received.
If jSerial and Asynchstreams had the facility to detect an eof with a timeout such that the new data sub didn't fire until the eof or timeout then it would be simple, but it does not have this facility.
I'm perfectly willing to believe that I can't give you what you're after, but not that B4X can't

So let me have one more go:
[CODE lang="b4x" title="Main"]Sub Process_Globals
Private ast As AsyncStreamsText
Private ListOfCommands as List
End Sub
Sub Button1_Click
ast.Initialize(Me, "ast", socket.InputStream, socket.OutputStream)
For k = 0 To ListOfCommands.Size-1
Dim command as string = ListOfCommands.Get(k)
Dim cancel(1) As Boolean
Timeout(cancel, 2, "Reply_Complete")
ast.Write(command)
Wait For Reply_Complete
If cancel(0) Then 'command timed out.
Log("Time out: No valid reply received.")
Exit 'Exit the loop unless you want the next command send regardless'
Else
cancel(0) = True 'cancels the timeout
Log("Valid Reply Received. Continue to next command")
End If
Next
End Sub
'Text received here has been validated in AsyncStreamsText as a complete valid reply with the eof characters'
Private Sub ast_NewText (Text As String)
Log(Text)
CallSubDelayed(Me, "Reply_Complete")
End Sub
'https://www.b4x.com/android/forum/threads/b4x-b4xlib-waitforwithtimeout-timeouthandler.110703/post-690966'
Sub Timeout(Cancel() As Boolean, Duration As Int, EventName As String)
Do While Duration > 0
'lblCountdown.Text = Duration
Sleep(1000)
If Cancel(0) Then Return
Duration = Duration - 1
Loop
Cancel(0) = True
CallSubDelayed(Me, EventName)
End Sub[/CODE]
[CODE lang="b4x" title="Modified AsyncStreamsText Class"]#Event: NewText (Text As String)
#Event: Terminated
'version: 1.00
'Class module
Sub Class_Globals
Private mTarget As Object
Private mEventName As String
Private astreams As AsyncStreams
Private sb As StringBuilder
End Sub
Public Sub Initialize (TargetModule As Object, EventName As String, In As InputStream, out As OutputStream)
mTarget = TargetModule
mEventName = EventName
astreams.Initialize(In, out, "astreams")
sb.Initialize
End Sub
'Sends the text. Note that this method does not add end of line characters.
Public Sub Write(Text As String)
astreams.Write(Text.GetBytes("ASCII"))
End Sub
Private Sub astreams_NewData (Buffer() As Byte)
sb.Append(BytesToString(Buffer, 0, Buffer.Length, "ASCII"))
Dim s As String = sb.ToString
Dim endFound As Boolean = s.EndsWith("ch> ") 'Or use regex to make sure you've got a suitable, complete reply as far as possible.
If endFound Then
CallSubDelayed2(mTarget, mEventName & "_NewText", s) 'callback to ast_NewText in the calling module'
sb.Initialize 'clear the buffer ready for the next command's reply
End If
End Sub
Private Sub astreams_Terminated
CallSubDelayed(mTarget, mEventName & "_Terminated")
End Sub
Private Sub astreams_Error
astreams.Close
CallSubDelayed(mTarget, mEventName & "_Terminated")
End Sub
Public Sub Close
astreams.Close
End Sub[/CODE]