Skip to content

Commit 99e7d21

Browse files
Trying to fix reading from Arduino Issue
1 parent f50e73a commit 99e7d21

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

btutillib/src/main/java/com/devpaul/bluetoothutillib/utils/BluetoothUtility.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -731,23 +731,19 @@ public ConnectedThread(BluetoothSocket socket) {
731731
}
732732

733733
public void run() {
734-
byte[] buffer; // buffer store for the stream
734+
byte[] buffer = new byte[1024]; // buffer store for the stream
735735
int bytes; // bytes returned from read()
736736
BufferedReader reader;
737737

738738
if(streamType == InputStreamType.NORMAL) {
739739
// Keep listening to the InputStream until an exception occurs
740740
while (true) {
741741
try {
742-
bytes = mInputStream.available();
743-
if(bytes > 0) {
744-
buffer = new byte[bytes];
745-
// Read from the InputStream
746-
bytes = mInputStream.read(buffer);
747-
// Send the obtained bytes to the UI activity
748-
bluetoothHandler.obtainMessage(BluetoothHandler.MESSAGE_READ, bytes, -1, buffer)
749-
.sendToTarget();
750-
}
742+
// Read from the InputStream
743+
bytes = mInputStream.read(buffer);
744+
// Send the obtained bytes to the UI activity
745+
bluetoothHandler.obtainMessage(BluetoothHandler.MESSAGE_READ, bytes, -1, buffer)
746+
.sendToTarget();
751747
} catch (IOException e) {
752748
break;
753749
}

0 commit comments

Comments
 (0)