Hi Guys,
I'm having a problem where I am connecting my phone via BT to an external device. If I power down my phone, and then run the script it works perfectly however when I try to run the script again I get an error:
This happens when the discovery starts on the mobile. Closing the python shell does not help, neither does turning off and on the bluetooth module.address,services = socket.bt_discover()
error: (13, 'Permission Denied')
It happens when the script gracefully closes as well as when it crashes.
Any ideas????
Below is the relevant code:
Code:import appuifw import e32 import socket def bt_connect(): print "starting to 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 bt_send_data(string): #send data to BT module. sends raw strings. global sock sock.send(string) #print string def bt_receive_data(): #return from bt. global sock i = 0 buffer = [] while(i <= 60): data = sock.recv(1) print str(ord(data)) buffer.append(data) i = i + 1 return buffer bt_connect() # connect to bt module. def bt_close(): #close the bt sock when exiting global sock sock.close() print "BTconnection closed" def format_bt(type,number): number_string = str.zfill(str(number),4) type = type[0] output = type + number_string return output def send_bt(type, number): stringtosend = format_bt(type, number) bt_send_data(stringtosend) def stop_controller(): send_bt('S',1) def flush_controller(): send_bt('S',2) initialise_controller() def exit_key_handler(): bt_close() app_lock.signal() def singleshot(): send_bt("C",1) # create an Active Object app_lock = e32.Ao_lock() # create the tabs with its names in unicode as a list, include the tab handler appuifw.app.set_tabs([u"Single Shot", u"Fast Shot", u"Intervalometer", u"Pano",u"Config"],handle_tab) # set the title of the script appuifw.app.title = u'Canon 400D V2.011' # set app.body to app1 (for start of script) appuifw.app.body = app1 #exit key handler appuifw.app.exit_key_handler = exit_key_handler #wait for lock app_lock.wait()

Reply With Quote

