简体   繁体   English

python中的dbus发送版本

[英]dbus-send version in python

I have a working dbus-send invocation: 我有一个有效的dbus-send调用:

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

Now I am trying to do the same in python, but since pitful documentation and despite me trying all thinkable permutations all I get are errors on the last step. 现在,我尝试在python中执行相同的操作,但是由于文档不完整,尽管我尝试了所有可考虑的排列,但我得到的最后一步都是错误。

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')

Whatever I do, the error is: 无论我做什么,错误是:

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

I have not found a way to tell me what mathod with what signatures exist and besides this error message seemingly contradict with the inital dbus-send invocation, which proofs that "org.bluez.Adapter.SetMode(s)" exists. 我还没有找到一种方法来告诉我存在什么签名的数学方法,并且该错误消息似乎与最初的dbus-send调用相矛盾,后者证明了“ org.bluez.Adapter.SetMode(s)”的存在。

I found the solution by looking at the api: 我通过查看api找到了解决方案:

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

and here is the python code: 这是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)

I am still not sure why the initial dbus-send command even works. 我仍然不确定为什么最初的dbus-send命令甚至可以工作。 The only reference to SetMode I can find elsewhere is here: http://svn.openmoko.org/developers/erin_yueh/bt/bt_adapter.py . 我在其他地方只能找到SetMode的唯一参考: http ://svn.openmoko.org/developers/erin_yueh/bt/bt_adapter.py。

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

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