H Husain Ragib Member Licensed User May 3, 2018 #1 My application connects an Android device via bluetooth. The application works fine when the device is connected with the application start. But when, in between the connectivity is lost and is reconnected... eventhough the commands are being send, I am not able to receive any response back from the Async streams. Instead Async_error is received. Can you please help me to figure out the cause of the error. Below is my code for connecting with the device : Code: Copy Sub Reader_Connected (Success As Boolean) If Success Then ReaderStatus.IsConnected = True BStream.Initialize(BTConnection.InputStream, BTConnection.OutputStream, "BStreams") Else ReaderStatus.IsConnected = False End If End Sub Below is my code for Sending commands : Code: Copy Public Sub SendCommand(Cmd As String) Starter.RBuffer = "" Dim buf As String = Cmd & CRLF Dim by() As Byte = buf.GetBytes("UTF7" ) Starter.BStream.Write(by) End Sub Last edited: May 3, 2018
My application connects an Android device via bluetooth. The application works fine when the device is connected with the application start. But when, in between the connectivity is lost and is reconnected... eventhough the commands are being send, I am not able to receive any response back from the Async streams. Instead Async_error is received. Can you please help me to figure out the cause of the error. Below is my code for connecting with the device : Code: Copy Sub Reader_Connected (Success As Boolean) If Success Then ReaderStatus.IsConnected = True BStream.Initialize(BTConnection.InputStream, BTConnection.OutputStream, "BStreams") Else ReaderStatus.IsConnected = False End If End Sub Below is my code for Sending commands : Code: Copy Public Sub SendCommand(Cmd As String) Starter.RBuffer = "" Dim buf As String = Cmd & CRLF Dim by() As Byte = buf.GetBytes("UTF7" ) Starter.BStream.Write(by) End Sub
Erel B4X founder Staff member Licensed User Longtime User May 6, 2018 #2 You should expect the connection to be broken from time to time. Try to reconnect after the connection breaks. Upvote 0
You should expect the connection to be broken from time to time. Try to reconnect after the connection breaks.
H Husain Ragib Member Licensed User May 24, 2018 #3 Erel said: You should expect the connection to be broken from time to time. Try to reconnect after the connection breaks. Click to expand... Dear Erel, Many thanks for your reply. Eventhough I am trying to reconnect with the device, the connection is broken again. Sometimes, I could see that the device maintains the connection eventhough the application is closed. Then, if I again open the application it fails to connect. Once connected and then exiting from the application, do i explicitly need to disconnect the connection? Upvote 0
Erel said: You should expect the connection to be broken from time to time. Try to reconnect after the connection breaks. Click to expand... Dear Erel, Many thanks for your reply. Eventhough I am trying to reconnect with the device, the connection is broken again. Sometimes, I could see that the device maintains the connection eventhough the application is closed. Then, if I again open the application it fails to connect. Once connected and then exiting from the application, do i explicitly need to disconnect the connection?
Erel B4X founder Staff member Licensed User Longtime User May 24, 2018 #4 Husain Ragib said: do i explicitly need to disconnect the connection? Click to expand... No. As I wrote you should expect connections to be broken and your program should try to reconnect when needed. In fact in many cases it is simpler to make a connection, send something and close it. Similar to how http requests are sent. This way the state is simpler. Upvote 0
Husain Ragib said: do i explicitly need to disconnect the connection? Click to expand... No. As I wrote you should expect connections to be broken and your program should try to reconnect when needed. In fact in many cases it is simpler to make a connection, send something and close it. Similar to how http requests are sent. This way the state is simpler.