Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python dbus额外参数,用于添加信号接收器_Python_Signals_Dbus - Fatal编程技术网

Python dbus额外参数,用于添加信号接收器

Python dbus额外参数,用于添加信号接收器,python,signals,dbus,Python,Signals,Dbus,我想传递额外的参数来添加信号接收器,或者以某种方式获得接收信号的路径。 现在它的定义如下: bus.add_signal_receiver(handle_signal, 'RemoteDeviceFound', 'org.bluez.Adapter', 'org.bluez', '/org/bluez/hci'+x) def handle_signal(address, cls, rssi): xxxx 我不希望同时有很多信号接收器,并且能够读取handle\u信号函数中的“x”。P

我想传递额外的参数来添加信号接收器,或者以某种方式获得接收信号的路径。 现在它的定义如下:

bus.add_signal_receiver(handle_signal, 'RemoteDeviceFound', 'org.bluez.Adapter', 'org.bluez', '/org/bluez/hci'+x)

def handle_signal(address, cls, rssi):
    xxxx
我不希望同时有很多信号接收器,并且能够读取handle\u信号函数中的“x”。

Python。它提供了以下示例以将发送方传递给处理程序函数:

def handler(sender=None):
    print "got signal from %r" % sender

iface.connect_to_signal("Hello", handler, sender_keyword='sender')

因此,不要使用
bus.add\u signal\u receiver
,而是先为信号提供对象创建一个接口,然后连接到信号,如示例所示。

要添加到Oben Sonne的答案中,
add\u signal\u receiver
采用相同的参数:

bus = dbus.SystemBus()
bus.add_signal_receiver(handler,
                        sender_keyword='sender',
                        destination_keyword='destination',
                        member_keyword='member',
                        path_keyword='path',
                        interface_keyword='interface')

如果需要接收信号的路径,请执行以下操作:

def handler(path=None):
    print("got signal with path %r" % path)

bus.add_signal_receiver(handler, path_keyword="path")
类似地,您可以传递其他人提到的“发件人”、“目的地”、“成员”和“接口”。但是,您不能转发任意回调信息