Hey everyone, I'm having some pretty buggy results when passing data via JAVA to my arduino. This isn't my first rodeo with RXTX or anything and I have other working applications using effectively the same code. I might just be overlooking something small.
first things first -
I have the BAUD set to 9600 on both the application and the board.
What I am trying to do is pass 20 integer values over serial from java to the arduino, store the values into an array and use them later on.
Here's the data I am passing via JAVA
JAVA output (ignore the comma's each are separate integers)
317, 250, 251, 249, 250, 197, 249, 249, 182, 250
If you want to see the JAVA code I will send it, but here is the send function...
public void writeData(int data) {
try {
output.write(data & 0xFF);
output.write((data >> 8) & 0xFF);
output.flush();
} catch (Exception e) {
logTxt.append("\nCould not write to microcontroller...");
}
}
Then what I am getting via the arduino looks like this...
3197,249,249,182,250,0,0,0,0,0,0,0,0,0
It looks like blurred entries, and not all of the data was recieved.
Here is how I am reading the data via arduino.
while(recievingCmds){
if(Serial.available() > 2) {
byte lowByte = Serial.read() & 0xff;
byte highByte = Serial.read() & 0xff;
nextCoord = (int) (highByte << 8 | lowByte);
coords[index] = nextCoord;
index++;
//Check to see if we filled the command queae
if(index > 19){recievingCmds = false; inprogress = true;}
}//end if
}//end while
Any help would be hugely appreciated