方法" DefaultAdapter"签名""在接口" org.bluez.Manager"在树莓派3中不存在

时间:2018-02-21 05:02:01

标签: python bluetooth raspberry-pi raspbian bluez

我想用这个简单的脚本在树莓派中使用dbus

bus = dbus.SystemBus()
obj = bus.get_object('org.bluez', '/')
print "object"
print obj
manager = dbus.Interface(obj,'org.bluez.Manager')
obj = bus.get_object('org.bluez',manager.DefaultAdapter())
print "Manager"
print manager
print "object"
print obj

但是当我尝试运行该代码时,我正在

Traceback (most recent call last):
  File "/home/pi/Desktop/hangul-recog/tools/DisableICT.py", line 350, in <module>
    ge = Paint()
  File "/home/pi/Desktop/hangul-recog/tools/DisableICT.py", line 125, in __init__
    self.test()
  File "/home/pi/Desktop/hangul-recog/tools/DisableICT.py", line 280, in test
    obj = bus.get_object('org.bluez',manager.DefaultAdapter())
  File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 70, in __call__
    return self._proxy_method(*args, **keywords)
  File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 145, in __call__
    **keywords)
  File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 651, in call_blocking
    message, timeout)
DBusException: org.freedesktop.DBus.Error.UnknownMethod: Method "DefaultAdapter" with signature "" on interface "org.bluez.Manager" doesn't exist

我正在使用 bluez 5.43 版本。我已经检查了解决方案,但没有运气。

我该怎么办?

提前致谢。

1 个答案:

答案 0 :(得分:4)

我和org.bluez.Manager有同样的问题

还有org.freedesktop.DBus.ObjectManager。这应该得到那些对象(来自https://github.com/Douglas6/blueplayer/blob/master/blueplayer.py):

import dbus

SERVICE_NAME = "org.bluez"
OBJECT_IFACE =  "org.freedesktop.DBus.ObjectManager"
ADAPTER_IFACE = SERVICE_NAME + ".Adapter1"
DEVICE_IFACE = SERVICE_NAME + ".Device1"
PROPERTIES_IFACE = "org.freedesktop.DBus.Properties"
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.freedesktop.DBus.ObjectManager")
objects = manager.GetManagedObjects()
for path, ifaces in objects.iteritems():
    adapter = ifaces.get(ADAPTER_IFACE)
    if adapter is None:
        continue
    obj = bus.get_object(SERVICE_NAME, path)
    adapter = dbus.Interface(obj, ADAPTER_IFACE)