Arduino continous output on serial port

I have written a short sketch to have the Arduino continously send a string out the serial port. The strings are "message0000" ... "message0099" and repeats.

void writeDummyData();

void setup()
{
    Serial.begin(115200);
    delay(2000);
}

void loop()
{
    unsigned long count = 0;
    int i = 0;

    for (;;)
    {
       writeDummyData(count);
       count++;
       delay(100);    //wait 2 seconds
       if (count == 100)
       {
         count = 0;
       }
    }
}

void writeDummyData(unsigned long number)
{
    char a[] = "message";
    char buffer[50];


    sprintf(buffer, "%04d", number);    //convert to string
    strcat(a, buffer);                //concatenate strings
    //strcat(a, "\r\n");              //append CR\LF 
    Serial.print(a);
}

I have a C# program listening on the other end.

        private void dataReceivedFromArduinoUno(object sender, SerialDataReceivedEventArgs e)
        {
            int bytes = arduinoUnoSerialPort.BytesToRead;
            //read until the ETX byte
            string data = arduinoUnoSerialPort.ReadTo("\x03");


            this.addText1(data.TrimEnd('\x03'));
            this.addText2(bytes.ToString());
        }

Every few messages, the listbox will show that not all 12 bytes are there for the C# program to read. Because I am reading until the ETX byte, the program will wait until all 12 bytes are received.

If I used arduinoUnoSerialPort.ReadExisting(), then I will get a message that may have 4 bytes and then a message that has 8 bytes.

Is this a Windows issue?

no,

delay(100); //wait 2 seconds conflict between code and comments => code wins

strcat(a, buffer); //concatenate strings where is the result stored? is that big enough? are you sure?

try this variation

void writeDummyData(unsigned long number)
{
    char buffer[50];
    sprintf(buffer, "message%04d", number); 
    Serial.print(buffer);
}

I tried the new Arduino code, and there are still hiccups. The Serial Monitor shows a constant rate of the messages being sent out, so the Arduino is working fine.

I even tried changing the rate the Arduino is sending the messages from 100ms to 1s. No difference.

Probably something with Windows.

is that big enough? are you sure?

No, it isn't. Yes, I am.

PaulS: No, it isn't. Yes, I am.

The Arduino code worked before. The Arduino code worked after I made the change as Rob suggested.

Anything else you wish to add that would make the C# code work?

The Arduino code worked before.

Maybe. But that does not mean that it is right. Make it right, and then we'll talk. There is NO room in a to concatenate more data.

What is the "\x03" that you are reading serial data to? You don't send anything that looks even vaguely like that.

PaulS: Maybe. But that does not mean that it is right. Make it right, and then we'll talk. There is NO room in a to concatenate more data.

UH, I guess you missed the part where I did make it right per Rob's post. And it does not work.

Do you even bother reading anything carefully? Sheesh.

PaulS: What is the "\x03" that you are reading serial data to? You don't send anything that looks even vaguely like that.

Again, you don't bother reading what I write above, and then post something that was already answered.

I wrote that I had to make the C# program work by telling it to read until the "\x03" ETX so that it will read everything in the buffer. If I don't then I get fragments every so often. My question is there no way to make C#'s serial port's ReadExisting() function without having to resort to using the serial port's ReadTo().

Do you even bother reading anything carefully?

If you don't know the answer, just say so. You're just going around in circle covering ground I already answered and tried.

UH, I guess you missed the part where I did make it right per Rob's post.

I guess YOU missed the part where you are supposed to post your revised code.

And it does not work.

Then why did you say that it did?

Again, you don't bother reading what I write above

That's an assumption on your part that is totally wrong.

I wrote that I had to make the C# program work by telling it to read until the "\x03" ETX

Where does your Arduino program send an ETX?

My question is there no way to make C#'s serial port's ReadExisting() function without having to resort to using the serial port's ReadTo().

I use:

                    if (port.BytesToRead > 0)
                    {
                        string message = port.ReadLine();

and have the Arduino send data using println(). All packets are then received complete.

Do you even bother reading anything carefully?

More often than you bother to write clearly.