Arduino sometimes breakups the communication string

Hi friends,

I am working with arduino duemilanove and some serial communication. What happens is, lets say arduino is suppose to send "abc123" to my pc as part of serial communication, but it sends "abc1" "\n(new line)" "23". This happens less frequently, but I want full proof serial communication. I don't know why this happens, as it breaks the chain of communication.

The following is my code
void sp(String str)
{
delay(10);
Serial.print(str);
delay(500);
Serial.flush();
}

Any help is appreciated.
Thanks

What is running on your PC that is receiving the data? We need more information before we can provide a useful diagnosis.

Hi thanks for reply,

I have developed my own C# application that communicates with arduino. It is working fine but the issue happens some times only.

Let me know if you want further information.

Thanks again.

We need to see the code in your C# application.

bforu_gs:
Hi friends,

I am working with arduino duemilanove and some serial communication. What happens is, lets say arduino is suppose to send "abc123" to my pc as part of serial communication, but it sends "abc1" "\n(new line)" "23". This happens less frequently, but I want full proof serial communication. I don't know why this happens, as it breaks the chain of communication.

I suspect it's not actually working as you think. I suspect what's actually happening is that your PC application is reading a message and then printing it with a trailing line feed. Sometimes, it reads the serial port while a message is being received and gets a partial message. The real problem in this case is that you are relying on the delay between messages to separate them. The proper solution is to detect the start and end of each message and buffer the received bytes until you have a complete message before processing it. This may mean changing your message format to make it possible to determine when each message starts and ends. If you're using an ASCII message format, this might be as simple as sending a newline character sequence at the end of each message and using that to detect the start and end of each received message.