我想用java通过蓝牙连接到我的mindstorms nxt机器人。还要记住,我已经安装了 lejos。Lejos 包括与机器人连接的类。非常感谢您,我花了数周时间试图解决这个问题,非常感谢您的帮助!
我希望我的 mac 启动连接。
感谢您发表评论,如果您不明白我在问什么。谢谢!
mac上运行的代码:
//package
package bluetoothtest;
//imports
import lejos.nxt.LCD;
import lejos.pc.comm.*;
import lejos.pc.*;
//main class
public class test {
//main method
public static void main(String[] args) throws Exception
{
//establish a connection...
NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
NXTInfo nxtInfo = new NXTInfo(NXTCommFactory.BLUETOOTH, "NXT", "00:16:53:0B:9C:CA");
}
}
机器人代码:
//package
package bluetoothrobottest;
//imports
import java.io.DataInputStream;
import java.io.DataOutputStream;
import lejos.nxt.comm.Bluetooth;
import lejos.nxt.comm.NXTConnection;
//main class
public class test {
//main method
public static void main(String[] args)
{
//wait for connection...
System.out.println("waiting for bluetooth connection...");
NXTConnection connection = Bluetooth.waitForConnection();
System.out.println("connected...");
//create streams
DataInputStream dis = connection.openDataInputStream();
DataOutputStream dos = connection.openDataOutputStream();
}
}
When I put this line of code in it gives me an error saying that the bluecove library isn't available:
nxtComm.open(nxtInfo,NXTComm.PACKET);