Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: Signals

Reply
Thread Tools

RE: Signals

 
 
Robert Rawlins - Think Blue
Guest
Posts: n/a
 
      04-18-2007
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 [(E-Mail Removed)]
Sent: 18 April 2007 13:43
To: Robert Rawlins - Think Blue
Cc: http://www.velocityreviews.com/forums/(E-Mail Removed)
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.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dumping real signals in VCD Sajan VHDL 8 07-21-2007 07:39 AM
Are all the signals read in the process should appear in the sensitivity list of the process? walala VHDL 3 09-09-2003 07:47 AM
generate testbench for array signals Simone Winkler VHDL 1 09-02-2003 04:00 PM
Delay of control signals Ingmar Seifert VHDL 0 08-18-2003 03:21 PM
unused bits in signals Thomas VHDL 2 07-06-2003 10:22 PM



Advertisments