Receiving serial data from processing

Project background: I am controlling a stepper motor from the computer. The processing program is a GUI that allows the user to select the Arduino's COM port and send commands to it. The Arduino receives these commands and acts accordingly. It can rotate to a relative or absolute chosen degree. A sample command sent over the serial "R,45.0" would mean Relatively, rotate 45.0 degrees clockwise. "A,-45.0" would mean Absolutely, rotate 45 counter clockwise.

The problem is that I cannot get the processing to talk to the arduino. I see the TX and RX lights flashing on the arduino when I send commands which indicates that some sort of signal is being sent.

Here is a snippet from the processing code. I highlighted where the command is outputted. Ok highlighting isn't supported inside the code box. Any other suggestions? I put a *** near it.

if (button == btnUp_r) {
               try {
                    angleInput = Float.parseFloat(txfML_angleInput.getText()); // Convert the string from textbox to a float
                    if (angleInput > -361.0 && angleInput <361.0) {
                         if (rotType == 'r') { // if Relative rotate option is selected
                              System.out.print("R,");
                              System.out.println(str(angleInput)); //So I can see in console of processing
                              port.write("R,"); //***
                              port.write(str(angleInput));// Send over serial "R,angle"
                         }
                         if (rotType == 'a') { // if Absolute rotate option is selected
                              System.out.print("A,"); //***
                              System.out.println(angleInput);
                              port.write("A,");
                              port.write(str(angleInput)); // Send over serial "A,angle"
                         }
                    }
               } 
               catch (NumberFormatException e) {
               }
          }

On the Arduino side, here is the code for reading in the string. I am planning on integrating this code (once it is working standalone) into my existing motor code. The interesting thing is that this Arduino code works fine when manually typing into the Serial Monitor (See picture). So something is different between the way the processing write() function works and the way the Arduino Serial Monitor works, but the question is what?

// Subcode for string decoder. Decodes commands triggered via GUI and sent over serial
// expect a 2 piece string like A,180.152
// code for Absolute, 180.152 radians

String readString[2];
char copy[7];
int i = 0;
char absOrRel; // Angle relative or absolute? A = Absolute, R = Relative
float angle; // Angle inputted

void setup() {
     Serial.begin(9600);
     Serial.println("serial-delimit-command,angle"); // so I can keep track of what is loaded
}

void loop() {
     while (Serial.available()) {
          delay(10);  //small delay to allow input buffer to fill
          char c = Serial.read();  //gets one byte from serial buffer
          // if S, stop it
          if (readString[0] == 'S'){
               Serial.println("Stop All"); 
               digitalWrite(13,HIGH);
          }
          // If Z, calibrate it
          if (readString[0] == 'Z'){
               Serial.println("Calibrate it");
               digitalWrite(13,LOW);
          }
          if (c == ',') {
               i++;
               break;
          }  //breaks out of capture loop to print readstring
          readString[i]+=c; //builds the string readString char by char 
          if (c == '\r') {
               i = 0;
          }     
     }
     if (readString[0].length() >0) { //If there is a string built 
          // Set flags if A, R (Absolute, Relative)
          if (readString[0] == 'R'){
               absOrRel = 'R';
               Serial.println("absOrRel = 'R'");
          }
          if (readString[0] == 'A'){
               absOrRel = 'A';
               Serial.println("absOrRel = 'A'");
          }
          readString[0]="";
     }
     if (readString[1].length() >0) { 
          readString[1].toCharArray(copy,7);
          angle = atof(copy);
          Serial.println(angle,7);
          readString[1]="";
     }
}

EDIT
Ok I slopped together something that works, but I would like someone to comment on why it sometimes works and sometimes doesn't. I don't really understand what the \n and \r things are. My hypothesis is that the Arduino automatically puts either a \r or \n at the end of each line and that write() doesn't. write() puts out only what is inputted to it. Can you show me how to make this more robust?

if (rotType == 'a') { // if Absolute rotate option is selected
     System.out.print("A,");
     System.out.println(angleInput);
     port.write("A,");
     port.write(str(angleInput)); // Send over serial "A,angle"
     port.write(",");
     port.write("\r");
}

Capture.JPG

I don't really understand what the \n and \r things are.

The \n and \r are carriage return and line feed characters.

My hypothesis is that the Arduino automatically puts either a \r or \n at the end of each line and that write() doesn't. write() puts out only what is inputted to it.

The Arduino is not adding the carriage return/line feed. The Serial Monitor application might, if you have that option selected. If you don't, it doesn't. Only you know whether you have selected that option.

The SerialPort::write() function does not add anything to what you tell it to output.