user14132: This is my code but it doesn't work. I don't no why . I hope someone can explain the problem. Tks
unsigned char InTransfer;
char buffer;
void setup()
    {
  Serial.begin(9600);
}

void loop()
{
  /* when get the sentences and print it*/
   while ( Serial.available())
  { 
    buffer=Serial.read();
    Serial.write(buffer);
    InTransfer=1;    // detect 
  }
  /* After done enter one time */
  if (Serial.available()==0)
    if(InTransfer==1){
      Serial.println("");
      InTransfer=0;
  }
}


user4143: Your code works perfectly, I don't see a problem with it. It's doing exactly what you're telling it to.
The problem lies in a fundamental lack of understanding about how serial communications work on your part, so you are telling it to do the wrong thing.  Until you fix that aspect no program you try and write in this way will be a success.
You should start by learning how serial communication actually works.  A good starting point is an article I wrote ages ago: http://hacking.majenko.co.uk/reading-serial-on-the-arduino

14132: <p>This is my code but it doesn't work. I don't no why . I hope someone can explain the problem. Tks</p>

<pre><code>unsigned char InTransfer;
char buffer;
void setup()
    {
  Serial.begin(9600);
}

void loop()
{
  /* when get the sentences and print it*/
   while ( Serial.available())
  { 
    buffer=Serial.read();
    Serial.write(buffer);
    InTransfer=1;    // detect 
  }
  /* After done enter one time */
  if (Serial.available()==0)
    if(InTransfer==1){
      Serial.println("");
      InTransfer=0;
  }
}
</code></pre>
 4143: <p>Your code works perfectly, I don't see a problem with it. It's doing <em>exactly</em> what you're telling it to.</p>

<p>The problem lies in a fundamental lack of understanding about how serial communications work on your part, so you are telling it to do the wrong thing.  Until you fix that aspect no program you try and write in this way will be a success.</p>

<p>You should start by learning how serial communication actually works.  A good starting point is an article I wrote ages ago: <a href="http://hacking.majenko.co.uk/reading-serial-on-the-arduino" rel="nofollow">http://hacking.majenko.co.uk/reading-serial-on-the-arduino</a></p>
