Python+;D总线&x2B;bluez5:can';不读取对象的属性?

Python+;D总线&x2B;bluez5:can';不读取对象的属性?,python,linux,dbus,bluez,Python,Linux,Dbus,Bluez,这是在GentooLinux上 我正在尝试让BlueZ 5告诉我我的蓝牙耳机是否已连接 我已经阅读并重新阅读了freedesktop.org上的D-Bus“文档”,但它似乎已经严重过时(或不完整,或两者兼而有之)。我也试着去理解bluez.org上那些微不足道的信息,但运气不好 我尝试了以下方法: Python 2.7.6 (default, Apr 26 2014, 11:38:54) [GCC 4.8.2] on linux2 Type "help", "copyright", "cred

这是在GentooLinux上

我正在尝试让BlueZ 5告诉我我的蓝牙耳机是否已连接

我已经阅读并重新阅读了freedesktop.org上的D-Bus“文档”,但它似乎已经严重过时(或不完整,或两者兼而有之)。我也试着去理解bluez.org上那些微不足道的信息,但运气不好

我尝试了以下方法:

Python 2.7.6 (default, Apr 26 2014, 11:38:54) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbus
>>> bus = dbus.SystemBus()
>>> obj = bus.get_object( "org.bluez", '/org/bluez/hci0/dev_00_18_91_D0_7A_24' )
>>> iface = dbus.Interface( obj, "org.bluez.Device1" )
>>> print iface.Connected
<dbus.proxies._DeferredMethod instance at 0x236e2d8>
Python 2.7.6(默认,2014年4月26日11:38:54) [GCC 4.8.2]关于linux2 有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。 >>>导入DBU >>>总线=dbus.SystemBus() >>>obj=bus.get_对象(“org.bluez”,“org/bluez/hci0/dev_00_18_91_D0_7A_24”) >>>iface=dbus.Interface(obj,“org.bluez.Device1”) >>>打印iface。已连接
我以为连接是设备的属性,但它是一种延迟的方法?那么如何获取该属性的值呢?

DBus属性是通过对get方法的DBus方法调用间接访问的。请参见以下介绍如何通过D-Bus API从蓝牙设备读取属性:

#!/usr/bin/env python3

import dbus

bus = dbus.SystemBus()
adapter_object = bus.get_object('org.bluez', '/org/bluez/hci0')
adapter = dbus.Interface(adapter_object, 'org.bluez.Adapter1')

device_object = bus.get_object("org.bluez", "/org/bluez/hci0/dev_FC_52_6E_8E_87_06")
device = dbus.Interface(device_object, "org.bluez.Device1")

device_properties = dbus.Interface(device, "org.freedesktop.DBus.Properties")
print(device_properties.Get("org.bluez.Device1", "Name"))
print(device_properties.Get("org.bluez.Device1", "Connected"))

似乎需要调用它:
print iface.Connected()