无法注销 ble 通知的 dbus 信号

unable to unregister dbus signal for ble notifications

我正在使用 python dbus 库注册以从设备接收 ble 数据包。但是,在断开连接并重新连接后,我收到了多个回调。我尝试取消注册信号,但它似乎没有任何效果 - 以下是我目前正在做的 -

class Gatt(object):
dbus_if = 'org.bluez.GattCharacteristic1'

    def __init__(self, bus, char_path):
        self.char_path = char_path
        self.bus = bus
        prop_man = dbus.Interface(bus.get_object(BLUEZ_SERV_NAME, self.char_path),
                                  'org.freedesktop.DBus.Properties')
        props = prop_man.GetAll(self.dbus_if)
        self.uuid = props[dbus.String('UUID')]
        self.notifying = props[dbus.String('Notifying')]
        nom = dbus.Interface(bus.get_object(BLUEZ_SERV_NAME, char_path), 'org.freedesktop.DBus.Properties')
        self.signal_on_property_changed = nom.connect_to_signal('PropertiesChanged', self.on_char_property_changed)
        print('New Gatt Device {}'.format(str(self.uuid)))
        self.dbus_if_handle = dbus.Interface(self.bus.get_object(BLUEZ_SERV_NAME, self.char_path),
                       self.dbus_if)

def clear_signal(self):
    self.bus.remove_signal_receiver(self.on_char_property_changed, self.signal_on_property_changed)

在这一点上,我怀疑 remove_signal_receiver() 有错误的参数,因此在没有给我正确结果的情况下默默地失败了。

非常感谢任何建议。 TIA.

要删除由 self.signal_on_property_changed = nom.connect_to_signal(...) 创建的信号匹配,您需要保存由该函数创建的信号,然后对该信号调用方法 remove()

示例:

# Create signal
self.signal_on_property_changed = nom.connect_to_signal(...)
....
# Remove signal
self.signal_on_property_changed.remove()