Hi,
I am developing a Class to control communications between 2 NXT bricks using Threads, but I have problems with my implementation.
The main Class, create 2 instance:
+ BT Listener
+ NXT Menu
I use to test the listener, the example BTConnectTest, and I notice that I receive in Sender data then BT Listener Thread runs. When that Thread finish to execute. I see a Java Exception Class 5, method: 1
Help me.
Main:
public class NXTCommTest {
/**
* @param args
*/
public static void main(String[] args) {
try{
NXTBotMenu NBM = new NXTBotMenu();
NXTCommsListener NCL = new NXTCommsListener(NBM);
NBM.start();
NCL.start();
}catch(Exception e){
}
}
}
Thread listener:
import lejos.nxt.*;
import lejos.nxt.comm.*;
import java.io.*;
public class NXTCommsListener extends Thread{
private String MESSAGE_AWAITING = "Awaiting";
private String MESSAGE_CONNECTED = "Connected";
//private Boolean NXT_CONNECTED = false;
private Thread _MENU;
private BTConnection btc;
public NXTCommsListener(Thread MENU)throws Exception{
_MENU = MENU;
}
private void showMessage(String message){
LCD.clear();
LCD.drawString(message,0,0);
LCD.refresh();
}
public void run()
{
while(true)
{
try
{
showMessage(MESSAGE_AWAITING);
btc = Bluetooth.waitForConnection();
showMessage(MESSAGE_CONNECTED);
_MENU.interrupt();
showMessage("Running LISTENER");
InputStream is = btc.openInputStream();
OutputStream os = btc.openOutputStream();
DataInputStream dis = new DataInputStream(is);
DataOutputStream dos = new DataOutputStream(os);
for(int i=0;i<100;i++) {
int ii = dis.readInt();
LCD.drawInt(ii,3,0,1);
LCD.refresh();
dos.writeInt(-ii);
dos.flush();
}
try {
dis.close();
dos.close();
btc.close();
} catch (IOException ioe){
//
}
}
catch(Exception ex)
{
//
}
}
}
}
Menu Thread:
import lejos.nxt.*;
public class NXTBotMenu extends Thread{
NXTBotMenu() throws Exception{
}
private void showMessage(String message){
LCD.clear();
LCD.drawString(message,0,0);
LCD.refresh();
}
public void run()
{
while(true)
{
try
{
showMessage("NXTMenu");
}
catch(Exception e)
{}
}
}
}
Thanks

