×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Aug 2008
    Location
    Bergen, Norway
    Posts
    8

    Why does my code quit pys60?

    Originaly posted at http://discussion.forum.nokia.com/fo...859#post504859


    Strange problem with my code. Instead of doing what it is supposed to (fetch position and post in url) it just quits python completely.
    This is the code i'm trying to get to work:
    Code:
    import httplib, e32, positioning, urllib, appuifw, positioning, sysinfo
    
    
    
    
    def gps_init():
    	try:
    		positioning.select_module(positioning.default_module())
    		positioning.set_requestors([{"type":"service","format":"application","data":"test_app"}])	
    		positioning.position(course=1,satellites=1,callback=gps,interval=500000,partial=0)
    		e32.ao_sleep(3)
    	except:
    		appuifw.note(u'Problem med GPS','error')
    
    
    
    def gps_stop():
    	try:
    		positioning.stop_position()
    	except:
    		appuifw.note(u'GPS stoppet','error')
    
    		
    def gps_print():
    	lokasjon = str('Min GPS posisjon er (Lengdegrad/Breddegrad) : %s, %s, %i' % (pos_lat, pos_long) )
    	print lokasjon
    	e32.ao_sleep(10)
    
    
    def open_browser(url):
    	url = "%s?%s" % ('http://www.example.com/mobil/upload.php', urllib.urlencode({'lat': pos_lat, 'lon': pos_long}),)
    	e32.start_exe('BrowserNG.exe', ' "4 %s 1"' % url, 1)
    	
    
    gps_init()
    count = 0
    while True:
    	count = count + 1
    	sat = gps_data['satellites']['used_satellites']
    	pos_lat = gps_data['position']['latitude']
    	pos_long = gps_data['position']['longitude']
    	if pos_lat > 0:
    		gps_print()
    		print 'Fant GPS posisjon, åpner Lokanytt...'
    		open_browser(url)
    	e32.ao_sleep(1)

  2. #2
    Regular Contributor
    Join Date
    Jan 2004
    Location
    Helsinki
    Posts
    376

    Re: Why does my code quit pys60?

    positioning module is difficult due to its asynchronous nature.

    Disable code line by line and see what line causes the actual malfunction. Then we can help more.
    Mikko Ohtamaa

    http://mfabrik.com
    http://blog.mfabrik.com

  3. #3
    Regular Contributor
    Join Date
    Jul 2007
    Location
    Eindhoven, the Netherlands
    Posts
    187

    Re: Why does my code quit pys60?

    Quote Originally Posted by Chrispinius View Post
    Originaly posted at http://discussion.forum.nokia.com/fo...859#post504859


    Strange problem with my code. Instead of doing what it is supposed to (fetch position and post in url) it just quits python completely.
    Code:
    def gps_print():
    	lokasjon = str('Min GPS posisjon er (Lengdegrad/Breddegrad) : %s, %s, %i' % (pos_lat, pos_long) )
    	print lokasjon
    	e32.ao_sleep(10)
    Probably not causing the failure, but that %i should not be there, or an extra parameter should follow pos_long...
    Also I suggest put str() around pos_lat and pos_long if you want them to be used as strings (they are probably of type float).

    Mark.

  4. #4
    Regular Contributor
    Join Date
    Jul 2007
    Location
    Eindhoven, the Netherlands
    Posts
    187

    Re: Why does my code quit pys60?

    Quote Originally Posted by Chrispinius View Post
    Originaly posted at http://discussion.forum.nokia.com/fo...859#post504859


    This is the code i'm trying to get to work:
    Code:
    	if pos_lat > 0:
    		gps_print()
    		print 'Fant GPS posisjon, åpner Lokanytt...'
    		open_browser(url)
    I am also sure if pos_lat is always a proper value, it may very well contain NaN, and I'm not sure if that compares well with 0.
    Note also that pos_lat may also be a negative number (if you are west of Greenwich).


    Mark.

  5. #5
    Registered User
    Join Date
    Aug 2008
    Location
    Bergen, Norway
    Posts
    8

    Re: Why does my code quit pys60?

    Thanks for help. I tried your suggestion with the str, but that gave a invalid syntax error.

    I see your point with the values in latitude and longitude, and changed the while argument. But it still just quits completely, this is very frustrating since I doesn't get the error message of what causes it. Does this quit on your phone as well or may it be something wrong with mine? I'm running pys60 3ed with the self-signed shell, on a n82.

  6. #6
    Regular Contributor
    Join Date
    Jan 2004
    Location
    Helsinki
    Posts
    376

    Re: Why does my code quit pys60?

    See this example how to escape callbacks, which are not executed in the main thread when the main exception handler is not effective, so that exception tracebacks are printed instead of silent application exit:

    http://bazaar.launchpad.net/~pys60co...7in81mt9gmhv-6
    Mikko Ohtamaa

    http://mfabrik.com
    http://blog.mfabrik.com

  7. #7
    Regular Contributor
    Join Date
    Jul 2007
    Location
    Eindhoven, the Netherlands
    Posts
    187

    Re: Why does my code quit pys60?

    Quote Originally Posted by miohtama View Post
    See this example how to escape callbacks, which are not executed in the main thread when the main exception handler is not effective, so that exception tracebacks are printed instead of silent application exit:

    http://bazaar.launchpad.net/~pys60co...7in81mt9gmhv-6
    Indeed, using this code to generate an exception trace would be extremely helpfull.

    Looking at your code again, I see two more problems:
    You use a 'gps' callback in gps_init, which doesn't seem to exist.
    Also you seem to reference a 'gps_data' global variable, which I can't find in your code (which should probably be set by the non-existing callback).
    Note that it may take some time before the callback is called, and so it would make sense to set gps_data to something sensible prior to starting your application main loop (and not depend on the callback alone to set it).


    Mark.

    b.t.w. if str(pos_lat) doesn't work, it is likely that u"%s" % pos_lat doesn't work either.

  8. #8
    Regular Contributor
    Join Date
    Jan 2004
    Location
    Helsinki
    Posts
    376

    Cool Re: Why does my code quit pys60?

    Quote Originally Posted by hurenkam View Post
    ain, I see two more problems:
    You use a 'gps' callback in gps_init, which doesn't seem to exist.
    If you want to learn how to master GPS this would be a good place to start:

    http://bazaar.launchpad.net/~pys60co...7in81mt9gmhv-6

    Next I will show you how to code Chuck Norris in Python.

    Mikko Ohtamaa

    http://mfabrik.com
    http://blog.mfabrik.com

Similar Threads

  1. Replies: 3
    Last Post: 2008-11-06, 16:19
  2. Replies: 2
    Last Post: 2007-10-05, 20:40
  3. Replies: 3
    Last Post: 2006-02-02, 10:12
  4. Link errors when trying to Display bitmap
    By Bkc82 in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2006-01-16, 22:46
  5. Replies: 0
    Last Post: 2003-09-26, 15:07

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×