[Lejos] Bluetooth Communication Problems
Posted: 18 Dec 2013, 10:18
Hi,
I've got the problem that I can send data via Bluetooth from the PC to the NXT but not from the NXT to the PC.
I wrote a little programm to describe my problem:
NXT:
PC:
The NXT recieves the integer "1234" and sends it back but the PC doesn't recieve anything. It's waiting for input via bluetooth.
Can anybody help me please?
Thank you.
I've got the problem that I can send data via Bluetooth from the PC to the NXT but not from the NXT to the PC.
I wrote a little programm to describe my problem:
NXT:
Code: Select all
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.comm.BTConnection;
import lejos.nxt.comm.Bluetooth;
import lejos.nxt.comm.NXTConnection;
public class BluetoothTest {
public static void main(String[] args) {
LCD.drawString("waiting for BT", 0, 0);
BTConnection btc = Bluetooth.waitForConnection(10000,NXTConnection.RAW);
LCD.clear();
LCD.drawString("connected", 0, 0);
DataInputStream dis = btc.openDataInputStream();
DataOutputStream dos = btc.openDataOutputStream();
LCD.drawString("read...", 0, 3);
int i=-2;
try {
i = dis.readInt();
} catch (IOException e) {
e.printStackTrace();
}
try {
dos.writeInt(i);
dos.flush();
} catch (IOException e){
e.printStackTrace();
}
LCD.drawString("send", 0, 4);
Button.waitForAnyPress();
}
}
Code: Select all
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import lejos.pc.comm.NXTConnector;
public class BluetoothTest {
public static void main(String[] args) {
System.out.println("Connecting");
NXTConnector conn = new NXTConnector();
if (!conn.connectTo("btspp://"))
System.out.println("Connection failed");
DataInputStream dis = new DataInputStream(conn.getInputStream());
DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
System.out.println("send...");
try {
dos.writeInt(1234);
dos.flush();
} catch (IOException e) {
System.out.println("error while sending");
e.printStackTrace();
}
System.out.println("read...");
try {
int i = dis.readInt();
System.out.println(i);
} catch (IOException e) {
System.out.println("error while reading");
e.printStackTrace();
}
}
}
Can anybody help me please?
Thank you.