App not terminating due to the function waitForConnection

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: roger, 99jonathan, imaqine

App not terminating due to the function waitForConnection

Postby tamasu » Sat Dec 01, 2012 11:28 pm

Hi,

I have set the NXT to wait for a bluetooth connection through the code connection = Bluetooth.waitForConnection(4000,NXTConnection.PACKET); Unfortunately I am having some issues to terminate the application due to this command.

The code is executed within a thread. If the cancel button is pressed the System.exit(0); code executed which should also terminate this thread however for a reason which I cannot identify, the application is not closing and it keeps showing a message on the LCD.

Any ideas what's wrong here?

Thanks
tamasu
New User
 
Posts: 7
Joined: Sun Nov 25, 2012 12:14 am

Re: App not terminating due to the function waitForConnectio

Postby gloomyandy » Sun Dec 02, 2012 3:40 pm

Hi,
A couple of things to try (note these are not really fixes, they will just help me work out what may be going on)...
1. Try making your connect thread a daemon thread.
2. Try calling Runtime.halt() rather than System.exit(). You will probably have to call getRuntime to obtain the Runtime object.

If you can create a short test program that demonstrates the problem I'll take a closer look at it. I suspect this may be an issue with shutdown hooks, but can't be 100% sure.

You should always be able to terminate a program using escape+enter (though if there is a problem with a shutdown hook you may have to press them more than once).

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3004
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: App not terminating due to the function waitForConnectio

Postby skoehler » Sun Dec 02, 2012 4:37 pm

@Andy: What does actually happen, if the program exits or is aborted (e.g. via enter+escape) and the Bluetooth module is left in some strange state. Does the startup menu perform some kind of reset of the bluetooth module? Does the possibility to perform a reset even exist? I suspect, this is not related as the user would probably see the screen going black and even the leJOS logo if the startup menu would hang on startup.
skoehler
leJOS Team Member
 
Posts: 1114
Joined: Thu Oct 30, 2008 4:54 pm

Re: App not terminating due to the function waitForConnectio

Postby gloomyandy » Sun Dec 02, 2012 5:01 pm

The first thing that the Bluetooth code does is to reset the hardware. If the hardware is in a good state this is pretty fast. But if it has crashed (which it can do for various reasons), then it takes a fair bit longer. That is why sometimes the menu takes longer to start up. So yes the menu will reset it and any program that uses Bluetooth will also reset it...
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3004
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

cron
more stuff