0

I am trying to write a script, which will connect a device (radiomodem), that have a bluetooth with my Nexus 7 (Android 4.4) The task is to send a command via bluetooth, and then get an answer from radiomodem. After sending a command I don't get an answer from device (or I get it, but cannot read bluetooth buffer), and my script stops while reading. It doesn't send me any mistakes, just stops. I've tried to send commands from Nexus to PC, and I've seen them in virtual COM on PC. I've tried to send from PC to Nexus, and from radiomodem to Nexus long lines and read them. it was fine, too. But writing-reading doesn't work. What I'm doing wrong?

Here is my code:

import sl4a
import time

droid = sl4a.Android()
uuid = '00001101-0000-1000-8000-00805F9B34FB'
adr = '6B:E2:00:DA:18:01' 
droid.toggleBluetoothState(True)      # connection is always successful
droid.bluetoothConnect(uuid,adr)
time.sleep(2)

i = 0

while i < 3:                     

  res = droid.dialogGetInput().result
  res = res + '\r'
  droid.bluetoothWrite(res)
  time.sleep(0.6)                  # here I've tried different timeouts
  ans = droid.bluetoothRead(4096).result
  if ans is None:
    print('no answer')
  else:
    w = str(ans)
    droid.dialogCreateAlert("+", w)
    droid.dialogSetPositiveButtonText('OK')
    i += 1
astridsnus
  • 31
  • 1
  • 6

1 Answers1

0

Half a year ago I did a small app with PY4A and I had trouble with connecting to my Bluetooth heart rate monitor from a galaxy S2. To solve the connection issue's I switched to pybluez. Using the Bluetooth device worked from there. See the working example that helped me here.

http://cuu508.wordpress.com/2011/02/21/hxm-t-display-heart-rate-from-zephyrs-hxm/

I hope this helps.

Regards.

  • Please don't post answers that are little more than a link to an external web page. What happens if, six months from now, that site gets taken down? Someone who finds this question through Google will see your answer, click your link, and get left with nothing but irritated disappointment. It's best to give a reasonably complete answer in the answer itself, and then throw the link in if there's more details there, or just to give credit. – user1618143 Dec 11 '13 at 21:44