Collecting lots of different variables / serial.print's to one string or line

Hello. I have this Arduino program that is printing to serial a bunch of different information, and I have used the Serial.print for this. But I need to send this information once every second to my computer (Visual studio) and with my current code, the messages gets messeg up as the time interval with my Arduino code and my C# code is not in perfect sync.
I thought maybe I could fix this with sending the enite code in one line or string. But, is there any way to to this without writing (a + b + c + d) ? Because, that would not be “pretty” and I figured it must be another way?

My code that needs to be sent once a second: (I do realize that there exists better methods than using all these IF-statements)

       Serial.print("$A");
       if (Date < 10){
        Serial.print("0");  
       }
       Serial.print(Date);
       Serial.print("/"); 
       if (Month < 10){
        Serial.print("0");  
       }
       Serial.print(Month);
       Serial.print("/");
       Serial.print(Year);
       Serial.print("B");
       if (Hour < 10){
        Serial.print("0");  
       }
       Serial.print(Hour);
       Serial.print(":");
       if (Minutes < 10){
        Serial.print("0");  
       }
       Serial.print(Minutes);
       Serial.print(":");
       if (Seconds < 10){
        Serial.print("0");  
       }
       Serial.print(Seconds);
       Serial.print("C");
       if (potVal < 10){
        Serial.print("000");  
       }
       if (potVal < 100 && potVal > 10){
        Serial.print("00");  
       }
       if (potVal < 1000 && potVal > 100){
        Serial.print("0");  
       }
       Serial.print(potVal);
       Serial.print("D");
       Serial.print(buttonValue1);
       Serial.print(buttonValue2);
       Serial.println("#");

Your "snippet" of code doesn't show how fast you are sending each byte. Try a faster baud rate.

Paul

Does your computer have a sense of aesthetics?

Or does it simply not care, and just waits for an ugly newline?

My baud rate is 9600, but I could try changing it to 115200.

My computer (or Visual Studio) is only using a timer to check for incoming data once per sec.

baguett: I thought maybe I could fix this with sending the enite code in one line or string.

That won't send the data any faster and the receiving program won't be able to tell the difference.

I regularly use 500,000 baud for communication between my Arduino and PC programs.

...R

But sending it all in one "go" would not make my C# program only show parts of the message.?

Also, I think 115200 is the max baud rate supported for Arduino Uno (?)

baguett: But I need to send this information once every second to my computer (Visual studio) and with my current code, the messages gets messeg up as the time interval with my Arduino code and my C# code is not in perfect sync.

You are not going to get the arduino and computer into perfect sync. Have the arduino send the information once per second, and the computer process the data when it receives the complete message, or have the computer send a request to the arduino to send the information, then have the arduino respond. As far as the serial output from the arduino is concerned, sending the information in a single string as opposed to the way you are doing it now is indistinguishable to the computer.

baguett: But sending it all in one "go" would not make my C# program only show parts of the message.?

I specifically said in Reply #4 that the C# program will not be able to tell whether it was send as one long string or several short ones. I should not have to repeat myself.

Also, I think 115200 is the max baud rate supported for Arduino Uno (?)

If that was the case why would I have said in Reply #4 that I use 500,000 baud.?

...R