蓝牙发现

我正在做一个项目,连接一个蓝牙模块到开发板。不幸的是,我的python代码无法发现蓝牙设备。有人能帮我检查一下我的代码吗?谢谢你

选择 | 换行 | 行号
  1. import socket,appuifw,e32
  2.  
  3.  
  4. def bt_socket_connect(target=''):
  5. address, services= socket.bt_discover()
  6.  
  7. if len(services) > 1:
  8. choices = services.keys()
  9. choices.port()
  10. choice = appuifw.popup_menu([unicode(services[x])+": "+x for x in choices], u'Choose port:')
  11. target = (address, services[choices[choice]])
  12. else:
  13. target = (address, services.values()[0])
  14. sock = socket.socket(socket.AF_BT,socket.SOCK_STREAM)
  15. sock.connect(target)
  16. return sock
  17.  
  18. def recieve():
  19.     global sock
  20.     data=sock.recv(1)
  21.     if data=="1":
  22.         appuifw.note(u"LED on","info")
  23.     elif data=="0":
  24.     appuifw.note(u"LED off","info")
  25.  
  26. def recieve():
  27.     global sock
  28.     data=sock.recv(2)
  29.     if data=="1":
  30.         appuifw.note(u"Light on","info")
  31.     elif data=="0":
  32.     appuifw.note(u"Light off","info")
  33.  
  34.  
  35. def bt_send_data1():
  36.     global sock
  37.     sock.send("1")
  38.     receive()
  39.  
  40. def bt_send_data2():
  41.     global sock
  42.     sock.send("0")
  43.     receive()
  44.  
  45. def bt_send_data3():
  46.     global sock
  47.     sock.send("1")
  48.     receive()
  49.  
  50. def bt_send_data4():
  51.     global sock
  52.     sock.send("0")
  53.     receive()
  54.  
  55.  
  56. def exit_key_handler():
  57.     print"socket closed"
  58.     sock.close()
  59.     app_lock.signal()
  60.  
  61. app_lock=e32.Ao_lock()
  62.  
  63.  
  64. devices = [u"LED", u"Light"]  
  65. index = appuifw.selection_list(devices, 0)
  66.  
  67.  
  68. appuifw.app.exit_key_handler=exit_key_handler
  69. app_lock.wait()
# 回答1


请将您发布的代码放在[code][/code]标记中(请参见
如何提问
)。代码标签保留缩进并使用等宽字体。
这使得我们的专家更容易阅读和理解它。如果做不到这一点,就会给版主带来额外的工作,从而浪费原本可以用来回答成员问题的资源。
请在以后使用[code][/code]标签。
主持人

标签: python

添加新评论