I'm trying to speak to a device over bluetooth serial.. this works fine using Putty from my PC, but I am not getting any response on Android. If I remove the check for Ready, the whole thing hangs. It seems I am not getting any data across at all.
Also, since the device I'm talking to is an embedded controller, I am not able to see if the commands are seen on the other side. However, a commercial Android application that also talks to this controller, works fine, so I know the bluetooth-to-serial converter is working.
Any ideas?
B4X:
Sub SendCmd ( Txt As String, len As Int) As String
Dim ret As String
ret = ""
If connected = True Then
ToastMessageShow("Send: " & Txt, False)
TextWriter1.WriteLine(Txt)
TextWriter1.Flush
SleepMs(100)
' wait for response
If (len > 0) Then
If TextReader1.Ready Then
ret = TextReader1.ReadLine
' get rid of the trailing pound sign
ret = ret.Replace("#", "")
ToastMessageShow("Receive: " & ret, False)
Return ret
End If
End If
End If
End Sub
... even for serial emulators? the controller i'm talking to requires synchronous calls, e.g. if i send a command, i had better get a response. not sure how i can implement that with asyncstreams...
Android doesn't allow you to manage network communication on the main thread.
You need to use a process global variable to track the current state. This will allow you to understand which message you receive and send the correct response.