0

I am confused.

I coded this code

if __name__ == '__main__':
    channel=None
    devices = finddevices()
    print 'devices %s'%devices
    for d in devices:
        print d[0]
        ser=findservices(addr=d[0],name=None,servicetype=OBEX)
        print ser
        for s in ser:
            print s
            if 'OBEX Object Push' in s[2]:
                channel=s[1]
    obex.sendfile(d[0], channel, '/home/mobile.jar')

If I write line by line in the python shell it works fine.

If I set a breakpoint and debug and with F6 key step by step execute all, it works fine.

But if I execute it normally in eclipse or terminal via python mycode.py the value of ser is None.

What is wrong?

Why findservices() wont work during the normal execution of the code?

Edit :

This is the output from service=findservices() in the python shell (in eclipse during a normal run it is always [])

>>> services=findservices()

services [('6C:0E:0D:3A:1F:90', 2, 'Serial Port 1'), ('6C:0E:0D:3A:1F:90', 1, 'Dial-up Networking'), ('6C:0E:0D:3A:1F:90', 10, 'OBEX SyncML Client'), ('6C:0E:0D:3A:1F:90', 25, 'Music Streaming Service'), ('6C:0E:0D:3A:1F:90', 23, 'Remote Control Target Service'), ('6C:0E:0D:3A:1F:90', 23, 'Remote Control Service'), ('6C:0E:0D:3A:1F:90', 2, 'SEMC Watch Phone'), ('6C:0E:0D:3A:1F:90', 15, 'PAN Network Access Point'), ('6C:0E:0D:3A:1F:90', 15, 'PAN user'), ('6C:0E:0D:3A:1F:90', 5, 'Hands-Free Gateway'), ('6C:0E:0D:3A:1F:90', 4, 'Headset Gateway'), ('6C:0E:0D:3A:1F:90', 6, 'OBEX Object Push'), ('6C:0E:0D:3A:1F:90', 7, 'OBEX File Transfer'), ('6C:0E:0D:3A:1F:90', 8, 'OBEX IrMC Sync Server'), ('6C:0E:0D:3A:1F:90', 17, 'HID Mouse & Keyboard'), ('6C:0E:0D:3A:1F:90', 61689, 'SEMC HLA'), ('6C:0E:0D:3A:1F:90', 11, 'Phonebook Access PSE')]

ρss
  • 5,115
  • 8
  • 43
  • 73
abbas-h
  • 392
  • 1
  • 4
  • 18
  • Have you tried adding more punctuation!!!!!!!! – wim May 07 '14 at 16:08
  • @user3585139 Do care about formatting your question. Your code is syntactically wrong, indenting after first line shall differ, correct it. – Jan Vlcinsky May 07 '14 at 16:08
  • Where is `findservices` defined? – dano May 07 '14 at 16:16
  • @user3585139 What is the `finddevices()`? What OS you are working on. Seing "jar" I will also ask for the python version you use. – Jan Vlcinsky May 07 '14 at 16:17
  • @JanVlcinsky method from lightblue library for scan devices in bluetooth protocol http://lightblue.sourceforge.net/ my OS : ubuntu 14.04 LTS python ver : 2.7.6 – abbas-h May 07 '14 at 16:24
  • `findservices()` is probably an async call, which means that the response might arrive only after you try to print it etc. See here: http://stackoverflow.com/questions/9110593/asynchronous-requests-with-python-requests – Nir Alfasi May 07 '14 at 16:35
  • @alfasin i add findservices() in a thread and start and join it ... same result .... – abbas-h May 07 '14 at 17:06
  • @user3585139 First, the last line in your script should be pushed one tab to the right. Second, without seeing `findservices()` or the full code you're running it'll be difficult to help you. – Nir Alfasi May 07 '14 at 17:10
  • @alfasin thanks ... last line position is correct . i edited main post ... please help and tell me all things that you want know from my script – abbas-h May 07 '14 at 17:33
  • From the link you posted: finddevices(), recvfile() and finddevicename() take a while to complete, and if they are called within a PyObjC app, the Cocoa UI will freeze until the method returns. If you want the normal Cocoa asynchronous behaviour that doesn't freeze, use the LightAquaBlue framework and Apple's IOBluetooth framework through PyObjC instead. – Nir Alfasi May 07 '14 at 20:37
  • @alfasin thanks ... how can i lock ser and wait for method findservices() finished ? – abbas-h May 08 '14 at 11:15

0 Answers0