RE: Signals

Discussion in 'Python' started by Robert Rawlins - Think Blue, Apr 18, 2007.

  1. Thanks Carsten,

    Sorry for not mentioning the dbus before, I thought that the signals were a general python thing, I didn’t realize it was a specific dbus thing.

    I've now modified the code so it looks like this.

    #!/usr/bin/python

    import dbus
    from gobject import MainLoop, idle_add
    from dbus.mainloop.glib import DBusGMainLoop

    def main_function():
    bus = dbus.SystemBus()
    manager = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'),'org.bluez.Manager')
    adapter = dbus.Interface(bus.get_object('org.bluez', manager.DefaultAdapter()),'org.bluez.Adapter')

    def remote_device_found(addr, class_, rssi):
    print 'Found:', addr

    adapter.connect_to_signal('RemoteDeviceFound', remote_device_found)

    adapter.DiscoverDevices()

    if __name__ == '__main__':
    idle_add(main_function)
    dbus_mainloop_wrapper = DBusGMainLoop(set_as_default=True)
    mainloop = MainLoop()
    mainloop.run()

    Which should implement the main loop and keep the application alive, however when running the program I get the following error thrown at me.

    File "./scan4.py", line 5, in ?
    from dbus.mainloop.glib import DBusGMainLoop
    ImportError: No module named mainloop.glib

    Any ideas what might be causing this? My guess is that I don’t have one of the dependency installed properly, but I have no idea which ones I need.

    Thanks for any more help you can offer, its greatly appreciated.

    Rob
    -----Original Message-----
    From: Carsten Haese [mailto:]
    Sent: 18 April 2007 13:43
    To: Robert Rawlins - Think Blue
    Cc:
    Subject: Re: Signals

    On Wed, 2007-04-18 at 08:39 +0100, Robert Rawlins - Think Blue wrote:
    > Hello Chaps,
    >
    >
    >
    > I posted about this the other day but I’m still struggling to get any
    > form of result from it. Basically I have the following piece of code,
    > and according to its API is produces singals when particular events
    > occur, but i have no idea how to list for events, I’ve tried all sorts
    > of combinations using the signal module but haven’t been able to get
    > it working.
    > [...]
    > import dbus, signal
    > [...]
    >
    > Now here is a copy of the API documentation that lists the signals
    > thrown by the API, this is the one I’m trying to listen for.
    >
    >
    >
    > void RemoteDeviceFound(string address, uint32 class, int16
    > rssi)
    >
    >
    >
    > This signal will be send every time an inquiry result
    >
    > has been found by the service daemon. In general they
    >
    > only appear during a device discovery.
    >
    >
    >
    > Basically I’m just looking to run a function that will print those
    > details to screen. Can anyone help with working out how to listen for
    > this signal?


    The signal module is for handling process signals the operating system
    sends to your python process. The API you're using (dbus, a crucial
    detail you neglected to mention before) doesn't send this kind of
    signal.

    Googling for 'python dbus documentation' brings up
    http://dbus.freedesktop.org/doc/dbus-python/api/ , which seems to
    explain everything you need. You need to get an instance of
    dbus.Interface, which you seem to have done, and call its
    connect_to_signal() method, which you don't seem to have done.

    > I’d also like to know how i can keep the application running until I
    > decided to stop it manually, as the DiscoverDevices() can take a while
    > to complete and send out several RemoteDeviceFound() signals in that
    > period.


    The very first section of the above mentioned documentation talks about
    needing a main loop for receiving signals, and it provides example
    boilerplate code for how to set up a main loop.

    Hope this helps,

    Carsten.
     
    Robert Rawlins - Think Blue, Apr 18, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas

    unused bits in signals

    Thomas, Jul 6, 2003, in forum: VHDL
    Replies:
    2
    Views:
    1,087
    Mario Trams
    Jul 6, 2003
  2. Ingmar Seifert

    Delay of control signals

    Ingmar Seifert, Aug 18, 2003, in forum: VHDL
    Replies:
    0
    Views:
    1,212
    Ingmar Seifert
    Aug 18, 2003
  3. Simone Winkler

    generate testbench for array signals

    Simone Winkler, Aug 31, 2003, in forum: VHDL
    Replies:
    1
    Views:
    770
    Pedro Claro
    Sep 2, 2003
  4. walala
    Replies:
    3
    Views:
    759
    Allan Herriman
    Sep 9, 2003
  5. Sajan

    Dumping real signals in VCD

    Sajan, Sep 19, 2003, in forum: VHDL
    Replies:
    8
    Views:
    7,191
    vlsi.engg27
    Jul 21, 2007
Loading...

Share This Page