I understand the B4A bridge uses a heartbeat approach to monitor whther bluetooth connection has been broken, so I'm wondering in knowledge of how that works can help me.
My handheld bluetooth product can be turned off at any time. The module inside it supports a 'Disconnect' packet, which I send just before the product powers down. Obviously when it powers down, the bluetooth radio turns off so the connection is well and truly interrupted.
I detect that the product has been powered down when I see I have not received a 'heartbeat' packet on the tablet for over 500ms. If I had to wait for the Astreams_Error to spring instead, that takes about 10 seconds - too long for me.
Anyhow, when I detect a lack of heartbeat what I do is try to disconnect everything in the comms path, disable then re-enable the bluetooth and re-init and listen again. Works well in practice on most tablets, but crashes the application on the newer HUDL tablet, which has bluetooth 4.0.
My de-init everything strategy (when heartbeat disappears) is like this:
I always get an exception when performing the first thing - Astream.Close. In the case of the HUDL, this is where the app stops working.
So my question is:
is there a logical order to the way I do those disconnects and things or some events I should wait for after doing any of them before proceeding to the next that would help me avoid the exception?
I think actually I do not need to disconnect the bluetooth and reboot it, I get the feeling that if I could just get Astream to close without throwing an exception, the thing would work optimally.
My handheld bluetooth product can be turned off at any time. The module inside it supports a 'Disconnect' packet, which I send just before the product powers down. Obviously when it powers down, the bluetooth radio turns off so the connection is well and truly interrupted.
I detect that the product has been powered down when I see I have not received a 'heartbeat' packet on the tablet for over 500ms. If I had to wait for the Astreams_Error to spring instead, that takes about 10 seconds - too long for me.
Anyhow, when I detect a lack of heartbeat what I do is try to disconnect everything in the comms path, disable then re-enable the bluetooth and re-init and listen again. Works well in practice on most tablets, but crashes the application on the newer HUDL tablet, which has bluetooth 4.0.
My de-init everything strategy (when heartbeat disappears) is like this:
B4X:
AStream.Close
admin.CancelDiscovery
serial1.Disconnect
admin.Disable
I always get an exception when performing the first thing - Astream.Close. In the case of the HUDL, this is where the app stops working.
So my question is:
is there a logical order to the way I do those disconnects and things or some events I should wait for after doing any of them before proceeding to the next that would help me avoid the exception?
I think actually I do not need to disconnect the bluetooth and reboot it, I get the feeling that if I could just get Astream to close without throwing an exception, the thing would work optimally.