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.


Reply With Quote


