Android Question Serial connect

fernando.oliboni

Active Member
Licensed User
Longtime User
B4X:
Serial1.Connect(PairedDevices.Get(l.Get(Index)))

After I performed a connection, how do I know if the connection is active throughout the application?
I'm using BluetoothAdmin, Serial and asyncstreamstext
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
My serial classes generally have some global boolean that gets set in the connect/disconnect events. I then just add a ".IsConnected" property that returns that boolean value.
 
Upvote 0

fernando.oliboni

Active Member
Licensed User
Longtime User
My serial classes generally have some global boolean that gets set in the connect/disconnect events. I then just add a ".IsConnected" property that returns that boolean value.
Yes, I saw this in an example, but what if the connection was lost for some unknown reason? The connection is done manually, I could test if the connection is lost, then run connection, but it has to be done manually...I don't know how to solve this.
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
I'm not sure I understand your problem. If you're setting the boolean in the connected and disconnected events then it doesn't matter how the connection is created or terminated the boolean value should represent the current connection state.

There are times when those events may not fire, so in my "send" methods I always try/catch and if it fails I call the classes ".Disconnect" method which also sets the boolean to false. Is this what you mean?
 
Upvote 0

fernando.oliboni

Active Member
Licensed User
Longtime User
I'm not sure I understand your problem. If you're setting the boolean in the connected and disconnected events then it doesn't matter how the connection is created or terminated the boolean value should represent the current connection state.

There are times when those events may not fire, so in my "send" methods I always try/catch and if it fails I call the classes ".Disconnect" method which also sets the boolean to false. Is this what you mean?


Hi, first of all I wanted to thank you for trying to help me. Secondly, sorry for my bad English.

I will explain everything. I made a machine and who controls this machine is an esp3 with grbl. I connect to esp32 via bluetooth and send a command and it responds with an OK when it has finished executing the command.

But I can only send commands if the connection is active and I don't know how to know if it's active because the serial class doesn't return the status of the connection. It could also be that I didn't understand how a serial connection works, I'm starting now with this subject.
If you can explain to me or send me an example of something that shows how this connection dynamic works, I would be very grateful.

Thank you very much
Fernando
 

Attachments

  • 1627760588757.png
    1627760588757.png
    312 bytes · Views: 107
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Hi, first of all I wanted to thank you for trying to help me. Secondly, sorry for my bad English.

I will explain everything. I made a machine and who controls this machine is an esp3 with grbl. I connect to esp32 via bluetooth and send a command and it responds with an OK when it has finished executing the command.

But I can only send commands if the connection is active and I don't know how to know if it's active because the serial class doesn't return the status of the connection. It could also be that I didn't understand how a serial connection works, I'm starting now with this subject.
If you can explain to me or send me an example of something that shows how this connection dynamic works, I would be very grateful.

Thank you very much
Fernando

How you handle it really depends on your specific application. I would search the forum here, there are many examples with connect/reconnect. Start with asyncstreams tutorial:
Search Results | B4X Programming Forum
 
Upvote 0
Top