Closed ghost closed 1 year ago
Signal handling is already built-in. See the example below which should point you in the right direction:
from dbus_next.aio import MessageBus
from dbus_next import Variant
def handler(uuid, moduleType, active, slotAddress):
print("Received message!")
print(uuid)
print(moduleType)
bus = await MessageBus().connect()
introspection = await bus.introspect('com.company.package', '/path/to/alarm/1')
proxy_object = bus.get_proxy_object('com.company.package', '/path/to/alarm/1', introspection)
interface = proxy_object.get_interface('com.company.package.AlarmInterface')
interface.on_alarm_signal(handler) # syntax is 'on_' plus signal name in snake case.
NB I've done this using the asyncio
version of the library.
Is there a short, complete minimal fully functional example showing how to receive a signal?
We spent over two hours trying to figure out how to use the python-dbus-next library to receive a signal. The signal written to D-Bus resembles:
In both Java and C, the solution is fairly trivial and there are numerous complete examples that show how to receive a signal.
Ideally, we'd like to:
In pseudo-python (replace with
async
code where appropriate):Save as
example.py
, then run as: