| Reply | « Previous Thread | Next Thread » |
|
Hi,
finally I'm able to reproduce the failure which I have mentioned in my last thread! I have written the following remote control module which works with accelerometer! The idea is to turn different callback methods over to the sensor method, to control a menu of an application on the pc. In this example I've just implemented one callback (send_direction)! Note: As I have assigned the directions, I have holded the mobile phone across! Code:
import appuifw, e32, socket, sensor
from sensor import orientation
acc_listener = ""
acc_listener_data = ""
app_lock = ""
temp_direction = ""
def choose_service(services):
names = []
channels = []
for name, channel in services.items():
names.append(name)
channels.append(channel)
index = appuifw.popup_menu(names, u"Choose service")
return channels[index]
def initialize():
global address, services, channel, conn, to_peer
address, services = socket.bt_discover()
channel = choose_service(services)
conn = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
conn.connect((address, channel))
print "connection established"
def set_Sensor(callback):
global acc_listener, acc_listener_data, app_lock
acc_listener_data = sensor.sensors()['AccSensor']
acc_listener = sensor.Sensor(acc_listener_data['id'], acc_listener_data['category'])
acc_listener.set_event_filter(sensor.OrientationEventFilter())
acc_listener.connect(callback)
print "sensor active"
app_lock =e32.Ao_lock()
app_lock.wait()
def send_direction(direction):
global conn, acc_listener, acc_listener_data, app_lock, temp_direction
if temp_direction <> direction:
if direction == 0:
temp_direction = direction
acc_listener.disconnect()
conn.send("Down" + "\r\n") # Down
set_Sensor(send_direction)
elif direction == 1:
temp_direction = direction
acc_listener.disconnect()
conn.send("Up" + "\r\n") # Up
set_Sensor(send_direction)
elif direction == 3:
temp_direction = direction
acc_listener.disconnect()
conn.send("Left" + "\r\n") # Left
set_Sensor(send_direction)
elif direction == 2:
temp_direction = direction
acc_listener.disconnect()
conn.send("Right" + "\r\n") # Right
set_Sensor(send_direction)
else:
return
def quit():
global conn, app_lock
print "closing application"
conn.close()
app_lock.signal()
initialize()
set_Sensor(send_direction)
appuifw.app.exit_key_handler = quit()
After 40 sended strings the application closes itself! My assumption is a buffer overflow or something like that, caused by creating new sensor objects permanently! Can anybody give me a hint why that happens or how to deal with it? THX! Greets Slomo! |
|
Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Rafael T.
Offline
Forum Nokia Champion
|
|
Can't assure you that this is the problem, but you really are creating too many instaces inside set_Sensor(). Actually set_Sensor() shouldn't exist! All the content from that function should be global (outside any functions). I will not give you too many details about doing this because we have a good example already: Sensor Sample by Jouni Miettunen
![]() Hope it helps, Rafael. |
|
Hi,
I have read the example and its just the same as I have done, with the exclusion of creating the sensor object in a mothod. Besides I use global variables for the reference, so the the sensor is "global"! Thats not the problem I think! The main point is, that I have to write/read (sequential) a socket parallel to listening the sensor. There for I tried to create time gapes by restarting the sensor so often. I've thought about another solution with a sensor in a thread, but this doesn't really work too. ![]() Code:
import appuifw, e32, socket, sensor, thread
from sensor import orientation
acc_listener = ""
acc_listener_data = ""
app_lock = ""
temp_direction=""
sensor_result=""
count=0
def choose_service(services):
names = []
channels = []
for name, channel in services.items():
names.append(name)
channels.append(channel)
index = appuifw.popup_menu(names, u"Choose service")
return channels[index]
def initialize():
global address, services, channel, conn, to_peer
address, services = socket.bt_discover()
channel = choose_service(services)
conn = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
conn.connect((address, channel))
print "connection established"
def set_Sensor(callback):
global acc_listener, acc_listener_data, app_lock
acc_listener_data = sensor.sensors()['AccSensor']
acc_listener = sensor.Sensor(acc_listener_data['id'], acc_listener_data['category'])
acc_listener.set_event_filter(sensor.OrientationEventFilter())
acc_listener.connect(callback)
print "sensor active"
app_lock =e32.Ao_lock()
app_lock.wait()
def print_Direction(direction):
global temp_direction
if direction == 5: #Back
temp_direction = direction
if temp_direction <> direction:
if direction == 0: # Down
print "Down"
elif direction == 1: # Up
print "Up"
elif direction == 3: # Left
print "Left"
elif direction == 2: # Rigth
print "Right"
else:
return
def send_Ping():
global conn, count
conn.send(str(count) + "\r\n")
count = count +1
e32.ao_yield()
def quit():
global conn, app_lock
print "closing application"
conn.close()
#app_lock.signal()
initialize()
thread.start_new_thread(set_Sensor(print_Direction), ())
while True:
send_Ping()
e32.ao_sleep(1)
appuifw.app.exit_key_handler = quit()
Running Sensor or sending string alone works without problems! |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| AutoStart My application at bootup | prakashs | General Symbian C++ | 7 | 2009-03-24 11:06 |
| Please Help! application runs on emulator but doesnt run on phone | qt_chenchen | General Symbian C++ | 37 | 2008-07-16 06:17 |
| Cannot run console application on S60 3rd gen (nokia 6110 navigator) | mcbure | General Symbian C++ | 4 | 2008-07-15 12:37 |
| BIO Message Parser Starting Application + Security Hole ? | Cr7pt0r | General Symbian C++ | 1 | 2008-05-08 13:32 |
| Not able to deploy an updated application on the mobile -it deploys a new application | kishban | Mobile Java General | 0 | 2005-05-28 11:20 |