使用java bluetooth连接到nxt

时间:2014-08-09 14:23:08

标签: java macos bluetooth nxt lejos-nxj

我想通过蓝牙与java连接到我的头脑风暴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);

2 个答案:

答案 0 :(得分:0)

简单的Google搜索会返回:http://www.lejos.org/nxt/nxj/tutorial/Communications/Communications.htm

我只使用了lejos,抱歉,我忍不住了:(

答案 1 :(得分:0)

如果您查看从http://www.lejos.org/nxj-downloads.php下载lejos时获得的文件夹,您将看到一个名为“samples”的.zip文件。提取并转到:“samples / pcsamples / src / org / lejos / pcsample / BTSend.java”获取您的电脑的一些测试代码和“samples / samples / src / org / lejos / sample / btreceive.java”您的NXT的测试代码。请记住在运行代码之前配对两个设备,否则不会发生任何事情(nxt的默认密码为:1234)。

据我所知,Mac OS不再支持用于此类通信的bluecove-library。这使得在较新的Mac和NXT之间无法使用蓝牙......但是无论如何你都可以试试。

USB可能是另一种选择,效果很好。