×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    2

    Question Discover bluetooth device in Python 1.9.x [Help]

    Hi,

    I am doing a project which will connect bluetooth module to a development board .
    I am going to use mobile phone to discover that bluetooth module and control the development board .
    My code not work with python 1.9.x but work with python 1.4.5

    Please help me and edit my code .
    Thx you

    Code:
    import socket
    import appuifw
    import e32
    
    e32.ao_yield()
            
    def bt_socket_connect(target=''):
        if not target:
            address, services = socket.bt_discover()
        if len(services) > 1:
            choices = services.keys()
            choices.sort()
            choice = appuifw.popup_menu([unicode(services[x])+": "+x for x in choices], u'Choose port:')
            target = (address, services[choices[choice]])
        else:
            target = (address, services.values()[0])
        sock = socket.socket(socket.AF_BT,socket.SOCK_STREAM)
        sock.connect(target)
        return sock
    	
    def bt_connect():
        sock = bt_socket_connect()
    	
    def send_command(self, command):
        sock = self.sock
        sock.send(command + "\r\n")
    	
    def exit_key_handler():
    	print "socket closed"
    	sock.close()
    	app_lock.signal()	
    	
    app = appuifw.app
    app_lock = e32.Ao_lock()
    exit_flag = False
    app.title = u"Bluetooth"
    app.exit_key_handler = exit_key_handler
    bt_connect()

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Discover bluetooth device in Python 1.9.x [Help]

    Hi,

    It would help if you told us exactly how your code doesn't work on 1.9.x (does it throw an error? does nothing happen?). Also, which version of 1.9.x are you using?

    In newer releases the socket module has been renamed to btsocket.

  3. #3
    Nokia Developer Expert
    Join Date
    Apr 2007
    Posts
    131

    Re: Discover bluetooth device in Python 1.9.x [Help]

    Change this import statement in the code
    Code:
    import socket
    with

    Code:
    import btsocket
    and change all usages of socket module to btsocket.

    [OR] use this way of importing a module,

    Code:
    import btsocket as socket
    With this, you don't have to make any other changes.

  4. #4
    Registered User
    Join Date
    Mar 2007
    Posts
    2

    Re: Discover bluetooth device in Python 1.9.x [Help]

    Thanks for the reply.

Similar Threads

  1. There is no voice from any device when switch on bluetooth
    By liulihua in forum Bluetooth Technology
    Replies: 2
    Last Post: 2008-07-11, 09:06
  2. Unable to receive data from Bluetooth Device Via RFComm
    By kctan in forum Bluetooth Technology
    Replies: 0
    Last Post: 2008-06-15, 15:23
  3. Replies: 4
    Last Post: 2007-09-04, 17:14
  4. Canyon Bluetooth adapter not working with PC Suite?
    By sNNooPY in forum Bluetooth Technology
    Replies: 6
    Last Post: 2006-08-10, 08:43
  5. Connecting to Bluetooth SPP device
    By jameelh in forum Symbian
    Replies: 5
    Last Post: 2005-07-05, 12:16

Posting Permissions

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