简体   繁体   English

您如何使用Python与自定义DBUS对象对话?

[英]How do you talk to custom DBUS object with Python?

I have some custom applications that is using dbus to communicate... 我有一些使用dbus进行通信的自定义应用程序...

import dbus
bus = dbus.SystemBus()
obj = bus.get_object(
    "org.freedesktop.DBus",
    "/org/freedesktop/DBus"
)

def listNames(names):
    for name in names:
        print "%s" % name

listNames(obj.ListNames());

I'm getting something like this coming back, example: 我收到类似这样的信息,例如:

org.freedesktop.DBus
:1.7
test.helloworld
test.blahblah
test.customapp

At this point how do I listen or talk to those test.* applications? 此时,我该如何收听或交谈那些test.*应用程序? In fact, any application returned by the DBus's get_object . 实际上, get_objectget_object返回的任何应用程序。

I read https://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html but not helping for what I'm trying to do... 我阅读了https://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html,但对于我想做的事情没有帮助...

dbus-python is deprecated, pydbus is the modern Python binding for DBus. dbus-python已过时,pydbus是DBus的现代Python绑定。 With pydbus: 使用pydbus:

To get a proxy object: 要获取代理对象:

from pydbus import SystemBus
bus = SystemBus()
dev = bus.get('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager/Devices/0')

To see the API of a specific proxy object: 要查看特定代理对象的API:

help(dev)

To call a method: 调用方法:

dev.Disconnect()

To read a property: 要读取属性:

print(dev.Autoconnect)

To set a property: 设置属性:

dev.Autoconnect = True

To subscribe to a signal: 订阅信号:

dev.StateChanged.connect(print)
loop.run()

More information: https://github.com/LEW21/pydbus/blob/master/doc/tutorial.rst 更多信息: https : //github.com/LEW21/pydbus/blob/master/doc/tutorial.rst

Disclaimer: I'm the author of pydbus. 免责声明:我是pydbus的作者。

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

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