Let me share a c# sample string read from serial.println

Hello people here.

I improved upon a c# serial programming example, and i like to share it here.
This is a programming demo, and when started you will see options to connect.
Select your arduino comport, and select your baudrate, press start.

As for the demo, you will see two textboxes one on the left textbox1 and one on the right textbox2
When running the program will display the serial input from the arduino in both textboxes
The difference is, that the right textbox will only update on received whole line strings. (serial.println)
It will not update on partial received data, if more then 1 line string is received it will also update per string.
In contrast the left textbox just flushes anything it receives including partial of strings.

Hmm fun but ehm why did i make it, you might wonder.
Well the point is, if you have a preformated string as output from your arduino.
And you would like to do something with it its much more easier, to work on the same string you tried to send. As compared to partial strings.

Imagine you would write in the arduino :
Serial.println("This is what i received.");
Serial.println("2678 do you like it?");

The left textbox1 might upate like :
---|This is wh|----|at i rec|----|eived. \r|----|\n 2|---|678 do y|---|ou like it? \r\n|

However right textbox2 will update like :
---|This is what i received. \r\n|----|2678 do you like it ? \r\n|---

Practical..??
Well yes, if you know the syntax output from a GPS module or other data output it would be more easy to buildup on whole strings at a connected computer side, then parts of strings. I probably am not the first who solved it. But post it here so people who find this difficult to do com reading from c#, can use it.

Written in c# 2010 express (free downloadable from Microsoft, just google it).

PS..
The code is as is, i'm not going to support it, or give long explanations about it, reason its working
But its a demo release and not a final version, as the final one wont include the leftbox, this version still does show the difference in programming, therefore you might learn from it. So instead of me explaining, i rather focus on a next version which will not be for a coding example, but will include some cool other stuff.

Just reply thanks if you liked it.

SimpleSerial.zip (465 KB)

In contrast the left textbox just flushes anything it receives including partial of strings.

It just flushes data? How can a text box flush data?

But post it here so people who find this difficult to do com reading from c#, can use it.

Thank you for doing that. Is the end-of-packet marker variable? (I didn't look at the code.)

:slight_smile:

no, its not really flushing data, it was a way of speaking.
if you take a look at the code at this function :
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)

you will find the difference of how each textbox gets its data.


End of packet marker, well i rather mind linebreaks, so i just reads whatever data is send and brings it back as the same string as was send by serial.println its no problem if your strings are variable in size.
Also you wont need to install c# (but its a code demo) as a working executable is inside the zip too.