简体   繁体   English

Python:即使检测到设备,也无法使用 PyBluez 扫描连接到蓝牙设备所需的信息

[英]Python: Can't scan for the info needed to connect to a bluetooth device with PyBluez, even though the device is detected

I am using the PyBluez library to try to connect my computer to a bluetooth speaker.我正在使用 PyBluez 库尝试将我的计算机连接到蓝牙扬声器。 I am running windows 10.我正在运行 windows 10。

When I use the discover_devices function, my speaker shows up just fine:当我使用 discover_devices function 时,我的扬声器显示正常:

import bluetooth as bt

devices = bt.discover_devices(10, flush_cache=True, lookup_names=True, lookup_class=True)

for d in devices:
   print d

output: output:

('BB:B8:6D:D2:C1:6C', u'OontZ Angle 3 16C', 2360324) // this is my speaker

However, when I try to get information such as the port needed to connect to the device, it doesn't return anything at all:但是,当我尝试获取连接到设备所需的端口等信息时,它根本不返回任何内容:

devices = bt.discover_devices(10, flush_cache=True, lookup_names=True, lookup_class=True)

for d in devices:
    print d
    addr = d[0]
    print bt.find_service(address=addr) // this function returns info such as port, protocol, etc about devices

Output: Output:

('BB:B8:6D:D2:C1:6C', u'OontZ Angle 3 16C', 2360324) // this is a speaker
[] // this should be a list of information about the device

Does anyone know what would cause this to happen?有谁知道什么会导致这种情况发生? Here's some more information:以下是更多信息:

  • If I just do a general bt.find_service() without specifying the mac address, the same thing happens如果我只是做一个一般的 bt.find_service() 而不指定 mac 地址,同样的事情会发生
  • Based on another post I saw, I am running pybluez-win10 instead of default pybluez.根据我看到的另一篇文章,我正在运行 pybluez-win10 而不是默认的 pybluez。 When running on the base version of pybluez, the code above gave the following error and stack trace:在 pybluez 的基本版本上运行时,上面的代码给出了以下错误和堆栈跟踪:

File "C:\Python27\lib\site-packages\bluetooth\msbt.py", line 243, in find_service文件“C:\Python27\lib\site-packages\bluetooth\msbt.py”,第 243 行,在 find_service

dresults = bt.find_service (addr, uuidstr) dresults = bt.find_service (addr, uuidstr)

IOError: A IO错误:一个

  • This error has never showed up with pybluez-win10, but instead the output of the function is, as mentioned, empty.这个错误从未出现在 pybluez-win10 中,但是 function 的 output 如前所述是空的。

Thank you.谢谢你。

you might need to install another version of Python, 3.5.4, and then download the wheel file specifically for this version of python.你可能需要安装另一个版本的Python,3.5.4,然后下载这个版本python专用的wheel文件。

wheel file URL and then use pip to install it: pip install PyBluez‑0.22‑cp35‑none‑win_amd64.whl wheel 文件URL然后使用 pip 安装它: pip install PyBluez‑0.22‑cp35‑none‑win_amd64.whl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM