Problem with serial connection [solved]

Hello all together,

hope this is the right forum for my question.

Currently i'm working on a simple protocol to communicate through php_serial_class with the arduino.

This is my code so far:

int debug = 1;
String input = "";
String temp = "";
int Pin;
int Value;
char character;
char buf[10];

// Program start
void setup()
{
Serial.begin(115200);      // start communication at 115200bps
}

void loop()
{
if( Serial.available() > 0)// if connection is set
  input = "";
   while(Serial.available()) {
      character = Serial.read();
      input.concat(character);
      [b]if (debug == 1){Serial.println("Command: " + input);}[/b]
   }
  
  // Check and execute command
  // Allowed Input is Set|Get|Fun and Parameters seperated by |
  // example: Set|D13|1 Sets digital Pin 13 to High
  // Get|A05 reads and gives back Analog Pin 05
  // For PWM and Special use FUN|FunctionName|Parameter1|Parameter2...
 
  if (input.substring(0,3) == "GET") {
    temp = input.substring(5,7);
    Pin = iStringToInt(temp);
     [u]if (debug == 1){Serial.println("Command: " + input);Serial.print("Selected Pin: "); Serial.println(Pin);}[/u]
    //Get Typ of Pin
    if (input.substring(4,5) == "D") {
      Serial.print(digitalRead(Pin));}
    else if (input.substring(4,5) == "A") {
      Serial.print(analogRead(Pin));}
      input = "";
  }
  else if (input.substring(0,3) == "SET") {
    temp = input.substring(5,7);
    Pin = iStringToInt(temp);
    [u]if (debug == 1){Serial.print("Selected Pin: "); Serial.println(Pin);}[/u]
    temp = input.substring(8);
    Value = iStringToInt(temp);
    [u]if (debug == 1){Serial.print("Selected Value: "); Serial.println(Value);}[/u]
    pinMode(Pin, OUTPUT);
    //Get Typ of Pin
    if (input.substring(4,5) == "D") {    
      digitalWrite(Pin, Value);
      input = "";
    }
    else if (input.substring(4,5) == "A") {
      analogWrite(Pin, Value);
      input="";
    }
  }
  else if (input.substring(0,3) == "FUN") {
    if (input.substring(4,9) == "BLINK") {   
      //digitalWrite(Pin, Value);
      //input = "";
    }
  }  
}

// Functions
// iStringtoInt converts a String to an integer
int iStringToInt(String number){
  char buf[10];
  number.toCharArray(buf, 10);
  return atoi(buf);
}

This Code is working so far, for example if i enter SET|D13|1 in serial monitor, the led on Pin 13 turns on. BUT if i comment out the line in bold (or doesn't use the debug to check if its working correctly) it stops working. Even the other Lines (underlined) don't show up in serial Monitor. Where is my mistake?

Same issue as I outlined here:

http://forum.arduino.cc/index.php?topic=168894.msg1256811#msg1256811

The Serial.print is likely slowing it down enough to receive all the bytes.

Thanks for fast and right answer :slight_smile:
For now i solved it with a delay, i will have a closer look to your example later.