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.
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.
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.
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.
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.