async streams and bluetooth ?

DrWave

Member
Licensed User
Longtime User
I have managed to communicate with a bluetooth device using serial (BTserial.zip). The sending device sends 6LOOPnnCRLF every second where nn goes from 10 to 99. 6 is the prefix (# of chars). But Erel says that we should use async streams instead of the timer. I cannot get the async program to run (main_activity_create java.lang.Nullpointerexception at line 218). The async program is BTasync.zip. As usual it is probably something stupid, but a nudge in the right direction would help.
 

Attachments

  • BTSerial.zip
    6.9 KB · Views: 308
  • BTAsync.zip
    6.9 KB · Views: 335

DrWave

Member
Licensed User
Longtime User
Update

I have solved part of the problem. You need to initialize the Async stream only after the connection has been established. Now I get the Astreams initialize to work but still issues with InitializePrefix.

My test string sent from the bluetooth device is LOOPnn where nn counts from 10 to 99 and then just loops back to start with 10 again. I put a 6 as number ahead of this test string (string length) and then I append a CRLF to the string so what I am getting from the bluetooth sender ( as shown in the edittext window using astream.initialize is 6LOOP10, 6LOOP11... etc.
But .initializeprefix just hangs up.
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Serial1_Connected (Success As Boolean)
   If Success Then
      ToastMessageShow("Connected successfully", False)
      Astreams.InitializePrefix(Serial1.InputStream,False,Serial1.OutputStream,"Astreams")
      connected = True
   Else
      connected = False
      ToastMessageShow("Error connecting."&LastException.Message,True )
   End If
End Sub

Setup your Astream in Serial1 Success connection. Try using the Astream without Prefix if necessary. I am not sure what device you are trying to communicate with. Will you be needing Serial1.Listen. Get rid of it if you do not need it.
 
Upvote 0
Top