Error With Receiving Xml Strings Via Bluetooth In Android
i am developing an App which receives xml as String over bluetooth (from Arduino and android phones). I am getting invalid/incomplete strings from the bluetooth . the Bluetooth is
Solution 1:
I did this successfully with the following code...
byte[] buffer = newbyte[128]; // buffer store for the streamint bytes; // bytes returned from read()// Keep listening to the InputStream until an exception occurswhile (true) {
try {
bytes = mmInStream.read(buffer);
byte[] readBuf = (byte[]) buffer;
StringstrIncom=newString(readBuf, 0, bytes); // create string from bytes array
sb.append(strIncom); // append stringintendOfLineIndex= sb.indexOf("\r\n"); // determine the end-of-lineif (endOfLineIndex > 0) {
// add the current string to eol to a local stringStringsbprint= sb.substring(0, endOfLineIndex);
// get the start and end indexes of the headingintstartHeading= sb.indexOf("HE");
intendHeading= sb.indexOf("/HE");
// set the heading
blahblah.setCurrentHeading(sb.substring((startHeading + 2), endHeading));
....
Then after I retrieved all the information I wanted from the text sent by the arduino I called:
sb.delete(0, sb.length());
The string coming from my adruino looks like the following:::
void taskTransmitData(void)
{
// start the xml
Serial.print("HE");
Serial.print(pMyMemory->currentHeading);
Serial.print("/HE");
.....
Serial.println();
}
Hope this helps...
Solution 2:
Try to use something like the while(true) statement in line 92 given in the code here: http://code.google.com/p/android-arduino/source/browse/garduino/android/src/net/morrildl/garduino/CommThread.java
Post a Comment for "Error With Receiving Xml Strings Via Bluetooth In Android"