【问题标题】:dbus-send version in pythonpython中的dbus-send版本
【发布时间】:2015-09-02 17:14:21
【问题描述】:

我有一个有效的 dbus-send 调用:

#                                   OBJECT          INTERFACE        .MEMBER  CONTENT
dbus-send --system --dest=org.bluez /org/bluez/hci0 org.bluez.Adapter.SetMode string:discoverable

现在我正在尝试在 python 中做同样的事情,但是由于可怜的文档,尽管我尝试了所有可以想到的排列,但我得到的只是 last 步骤中的错误。

import dbus
bus = dbus.SystemBus()
hci0 = bus.get_object('org.bluez', '/org/bluez/hci0')
# everything good so far

# v1
hci0_setmode = hci0.get_dbus_method('SetMode', 'org.bluez.Adapter')
hci0_setmode('discoverable')

# v2
iface = dbus.Interface(hci0, 'org.bluez.Adapter')
iface.SetMode('discoverable')

# v3
iface = dbus.Interface(hci0, 'org.bluez.Adapter')
hci0_setmode =iface.get_dbus_method('SetMode', 'org.bluez.Adapter')
hci0_setmode('discoverable')

无论我做什么,错误是:

dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownMethod: Method "SetMode" with signature "s" on interface "org.bluez.Adapter" doesn't exist

我还没有找到一种方法来告诉我存在什么签名的方法,而且这个错误消息似乎与初始 dbus-send 调用相矛盾,这证明“org.bluez.Adapter.SetMode(s)”存在。

【问题讨论】:

    标签: python dbus


    【解决方案1】:

    我通过查看api找到了解决方案:

    dbus-send --system --dest=org.bluez --type=method_call --print-reply /org/bluez/hci0 org.freedesktop.DBus.Introspectable.Introspect
    

    这里是python代码:

    import dbus
    bus = dbus.SystemBus()
    hci0 = bus.get_object('org.bluez', '/org/bluez/hci0')
    props = dbus.Interface(hci0, 'org.freedesktop.DBus.Properties')
    props.Set('org.bluez.Adapter1', 'Discoverable', True)
    

    我仍然不确定为什么最初的 dbus-send 命令甚至可以工作。我可以在其他地方找到的对 SetMode 的唯一参考是:http://svn.openmoko.org/developers/erin_yueh/bt/bt_adapter.py

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-02
      • 2016-07-10
      • 1970-01-01
      • 2015-02-28
      • 2011-04-11
      • 2021-09-29
      • 2014-09-02
      • 1970-01-01
      相关资源
      最近更新 更多