Hi, I need help. In the code below I send commands to ESP32 and I can only send a new command if ESP32 responded with an OK. I have the "ast_NewText" event that returns the response from ESP32, but I don't know how to include it in "FOR". can anybody help me?
B4X:
Dim cursor1 As Cursor
cursor1 = SQL1.ExecQuery("SELECT linha FROM gcode order by numerador")
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
Dim linha As String = cursor1.GetString("linha")
ast.Write(linha & Chr(13))
'I need to wait for an OK return from ESP32 to send a new command. What can I put here to wait for OK?
Next
cursor1.Close
You can do something like this, but it can cause other problems:
B4X:
ast.Write(...)
Wait For ast_NewText(Text As String)
This will work if the ESP can only send OK.
A more robust solution is to create a List with all the values that you need to send and send the next one in the ast_NewText event:
B4X:
Private Sub ast_NewText(Text As String)
If Text = "OK" Then
If Queue.Size > 0 Then
Dim linha As String = Queue.Get(0)
ast.Write(...)
Queue.RemoteAt(0)
End If
End Sub
You can do something like this, but it can cause other problems:
B4X:
ast.Write(...)
Wait For ast_NewText(Text As String)
This will work if the ESP can only send OK.
A more robust solution is to create a List with all the values that you need to send and send the next one in the ast_NewText event:
B4X:
Private Sub ast_NewText(Text As String)
If Text = "OK" Then
If Queue.Size > 0 Then
Dim linha As String = Queue.Get(0)
ast.Write(...)
Queue.RemoteAt(0)
End If
End Sub