I am currently working on a team project trying to create a robot that will traverse a maze and report any obstacles back to the pc and display a GUI for the user. We have tried for a few days trying to get the BT connection to work and we are stumped and have yet to get any successful code to work on the PC side.
Were running a sample code of this on the NXT:
- Code: Select all
import java.io.*;
import lejos.nxt.*;
import lejos.nxt.comm.*;
/**
* sample of selecting channel at run time
*/
public class CommTest
{
public static void main(String[] args) {
LCD.drawString("right BT",0, 0);
NXTConnection connection = null;
if(Button.waitForAnyPress() == Button.ID_RIGHT){
LCD.drawString("waiting for BT", 0,1 );
connection = Bluetooth.waitForConnection();
} else {
LCD.drawString("waiting for USB", 0,1 );
connection = USB.waitForConnection();
}
DataOutputStream dataOut = connection.openDataOutputStream();
try {
dataOut.writeInt(1234);
} catch (IOException e ) {
System.out.println(" write error "+e);
}
}
}
However when it comes to the PC code we haven't really found anything that we could use. We were trying to use something like this:
NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
However it is not allowing us to compile anything with this line specificly. Some of the links I have read mentioned that you need to download a diffrent .jar file for the BT communication to work, but we aren't even at the baby steps. Can someone provide a link or some code or advice on how to actually connect the PC to the NXT and transfer some sample data?
On a side note is there a way to compile and run code in an ide for the pc side? (I tried eclipse but couldn't find a way to DL the plugin).
Thanks in advance!
