Closed thomaskioko closed 7 years ago
You need to control this because communication is asynchronous. Bluetooth does not depend on you sending information to return a response.
Every time the device sends a response it will be caught by the event onDataRead
.
service.setOnEventCallback(new BluetoothService.OnBluetoothEventCallback() {
@Override
public void onDataRead(byte[] buffer, int length) {
// If you want to convert to String
String text = new String(buffer, 0, length);
sendNextCommand();
}
...
});
private void sendNextCommand() {
bytes[] nextCommand = ...;
service.write(nextCommand );
}
Please, if you have no further questions, you can close the issue. 😄
@douglasjunior How can I wait for a response before running another command? I.e I have a list of 3 commands, before running the second command, I wait for a response from the first one.