BackupGGCode / python-for-android

Py4A
Apache License 2.0
0 stars 1 forks source link

"Bluetooth not ready for this ConnID" Java.io.IOexception #73

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
1. Establish a connection with a Bluetooth device using bluetoothConnect()

2. Kill the power to that Bluetooth device (to simulate a failure)

3. Check bluetoothActiveConnections(), the device will still be listed there 
(for a while at least).

4. During this time, try to write data to that Bluetooth Device using 
bluetoothWriteBinary()

5.  The (attempted) write will not raise any exceptions in your python script, 
but you will see "Java.io.IOexception: Bluetooth not ready for this ConnID" on 
your screen.

Shouldn't this failed write be raising an exception in Python?

I'm using sl4a_r6.apk and sl4a_r6.apk on Android 4.0.3.

Original issue reported on code.google.com by bigmark...@gmail.com on 10 Apr 2013 at 1:13

GoogleCodeExporter commented 9 years ago
*cough* PythonForAndroid_r4.apk

Original comment by bigmark...@gmail.com on 10 Apr 2013 at 1:14

GoogleCodeExporter commented 9 years ago
I get the same error even without turning off the Device. Transmission of bytes 
works a few times but then fails with this error :-(

Android 2.3

Original comment by paulherweg on 23 Aug 2013 at 11:59

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
My work around was to check for a confirmation reply from my bluetooth device 
and if I did not receive a confirmation within a timeout period to attempt to 
automatically reconnect.

input_buffer = []
time_out = time.time() + .5
while('\n' not in input_buffer):
    while(droid.bluetoothReadReady().result == False):
        if(time.time() > time_out):
            raise Exception
    input_buffer.append(droid.bluetoothRead(1).result)

This code has a half second timeout.  It reads in data one character at a time, 
and if it doesn't receive a newline it assumes something went wrong and throws 
an exception.  My exception handler then would automatically reconnect, and try 
sending data again.

This may not work in your case if disconnections are extremely common, or if 
the device does not send a consistent acknowledgement of data received.

Original comment by bigmark...@gmail.com on 23 Aug 2013 at 12:40