×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    2

    How do pys60 received data continuously?



    My platform is nokia n85, s60, 3rd edition.

    I tried to build an application, I build a bluetooh serial port communication. When mobile phone receive a data, let's say "THT", the application will pop up a note "receive data: THT".

    I use, socket module, socket.recv() to receive the data. It seems it is working.

    I need to receive the data all the time. Means when the client send a data, mobile phone should pop up the note.

    The problem A is I can not always run socket.recv() cause I have other functions. Problem B is when socket.recv() is always running, it halt when pys60 doesn't receive the data.

    import appuifw
    import e32
    import btsocket as socket

    appuifw.app.screen = "normal"


    #define a bluetooth connection
    def bt_connect():
    global sock
    sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
    target=''
    if not target:
    address,services=socket.bt_discover()
    print "Discovered: %s, %s"%(address,services)
    if len(services)>1:
    import appuifw
    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])
    print "Connecting to "+str(target)
    sock.connect(target)
    print "OK."

    def otherfunction():
    appuifw.note(u"Other function is running", "info")

    #difine exit function
    def exit_key_handler():
    sock.close()
    app_lock.signal()

    # create an Active Object
    app_lock = e32.Ao_lock()

    # set the title of the script
    appuifw.app.title = u'BLUE CONTROLL'



    appuifw.app.exit_key_handler = exit_key_handler

    bt_connect()

    #this section to receive the data, all the time
    while 1:
    # problem a
    data_recv = sock.recv(4)
    #problem B
    if data_recv=="THT":
    appuifw.note(u"receive data:"+str(data_recv), "info")

    #this function has no chance to run when problem a is not solved
    otherfunction()

    app_lock.wait()



    So, my questions,
    how pys60 knows when mobile receive a data?
    how to receive data continuslly when other functions are running, means without run socket.recv() all the time?

    many thanks in advance.

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    2

    Re: How do pys60 received data continuously?

    anyone who need this code, I can send by email. tks

  3. #3
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: How do pys60 received data continuously?

    I can see at least two approachs.

    1) You can add multitask capabilities to your program
    2) You can use non blocking sockets (single thread pragram). Using non blocking socket mode it is possible to pool the socket and check if some data has arrived or not. In this case, your loop could be something like:

    Code:
    def run():
        sock.setblocking(0)
        while running:
            # allows S60 execution
            e32.ao_yield()
            # check your sockets below
            try:
                data = sock.recv(1024)
            except:
                # do something, check exception type ...
                pass
            else:
                # some data arrived, do something
                pass
    Some tips about
    multitask in S60

Similar Threads

  1. PyS60 with Nokia S60 SDK
    By sam_bakki in forum Symbian
    Replies: 22
    Last Post: 2010-06-23, 09:19
  2. Replies: 9
    Last Post: 2010-06-10, 12:39
  3. New to Python for S60 (PyS60)? Read this first!
    By croozeus in forum Nokia N9
    Replies: 2
    Last Post: 2008-10-17, 19:23
  4. Replies: 1
    Last Post: 2007-04-17, 10:47
  5. Replies: 0
    Last Post: 2002-12-04, 15:46

Posting Permissions

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