Android Question Timeout...

Cenny

Active Member
Licensed User
Longtime User
Hi,

I am working on an program that, in a certain stage, is waiting to receive incoming data via a bluetooth connection.
How can I impose a limit on the time that it keeps waiting.

Appreciate your help.

Cenny
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Use a timer with an interval set to the timeout value you require. Each time you receive data reinitialize the timer to prevent the tick event from firing. You can then choose to stop the timer once all the required data is received or when the tick event occurs that kicks in your timeout code.
 
Upvote 0

Cenny

Active Member
Licensed User
Longtime User
Use a timer with an interval set to the timeout value you require. Each time you receive data reinitialize the timer to prevent the tick event from firing. You can then choose to stop the timer once all the required data is received or when the tick event occurs that kicks in your timeout code.
Thanks for your help.
But how do I know that I am actually receiving data?
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
I have not used Bluetooth comms before but it looks like you need to check the TextReader.Ready status...
https://www.b4x.com/android/forum/threads/android-serial-tutorial.6908/
Therefore I purpose that you could modify my previous suggestion slightly and use the timer to poll the status of the incoming serial data at a fairly regular interval, maybe once a second. You could then use a global variable within the tick event for the timeout purpose. If TextReader.Ready is true, reset the timeout flag and read in the data. If not ready then increment the timeout flag. When the timeout variable reaches 30 a timeout has occurred, stop the timer and do what ever it is that you require.
 
Upvote 0

Cenny

Active Member
Licensed User
Longtime User
I have not used Bluetooth comms before but it looks like you need to check the TextReader.Ready status...
https://www.b4x.com/android/forum/threads/android-serial-tutorial.6908/
Therefore I purpose that you could modify my previous suggestion slightly and use the timer to poll the status of the incoming serial data at a fairly regular interval, maybe once a second. You could then use a global variable within the tick event for the timeout purpose. If TextReader.Ready is true, reset the timeout flag and read in the data. If not ready then increment the timeout flag. When the timeout variable reaches 30 a timeout has occurred, stop the timer and do what ever it is that you require.

Thank you for the suggestions.
Will try it immediately
 
Upvote 0
Top