Tomek
Tomek

Reputation: 386

OutputStream.write() never ends

I have a car with a bluetooth interface that I connect to using my android app. Robot is programmed so that when he gets a digit 1-5, he makes an action. 1 - drive forward 2 - drive backward 3 - turn left 4 - turn right 5 - stop I have 5 buttons in my app. Their events' look like this

public void button1(View view){
socket.write("1");
}

where socket is the class that holds BluetoothSocket and makes a connection and has write function:

public void write(String signal)
{
try
{
OutputStream.write(signal.getBytes());
Log.d("#Signal", " connected");
} catch (IOException e)
{
}
}

AND! When I connect, and press for example button that sends 2, robot starts moving backward but I don't get message from line

Log.d("#Signal", " connected");

So it looks like write(byte[] buffer) function never ends it's procedure. After pressing one button, when I try to press another one, it doesn't work. Like OutputStream.write() still tries to write something. I don't know why this happens, any solutions?

Upvotes: -1

Views: 713

Answers (1)

Lackberg
Lackberg

Reputation: 11

Try using flush() function after you call write() like this

OutputStream.write(signal.getBytes());OutputStream.flush();

Upvotes: 1

Related Questions