how to wait for incoming data
-
Hi, I was wondering if there is a way to get all data from the serialport before processing it. I got an event handler for the serialport and this is how i receive the data: string buffer += serialport.ReadExisting(); These are my delegate and event to read the data: public delegate void GetData(string getDataFromBuffer); public event GetData getTheData; After that this event handler is fired: if (this.getTheData != null) this.getTheData(buffer); All data i get will be appended to a richtextbox. Problem is, it keeps appending even the data already exists. It kinda looks like this: 123. 123.455 123.455.5677 But i want to append it all at once. Any suggestions how to fix this? Thanks in advance!
-
Hi, I was wondering if there is a way to get all data from the serialport before processing it. I got an event handler for the serialport and this is how i receive the data: string buffer += serialport.ReadExisting(); These are my delegate and event to read the data: public delegate void GetData(string getDataFromBuffer); public event GetData getTheData; After that this event handler is fired: if (this.getTheData != null) this.getTheData(buffer); All data i get will be appended to a richtextbox. Problem is, it keeps appending even the data already exists. It kinda looks like this: 123. 123.455 123.455.5677 But i want to append it all at once. Any suggestions how to fix this? Thanks in advance!
Hi, If you only want to keep the latest text only, then dont concatenate the original text with the new one. I think you might be doing something like this -
RichTextBox1.Text = RichTextBox1.Text + this.getTheData(buffer);
Change it toRichTextBox1.Text = this.getTheData(buffer);
Hope i got what you want, but i am not sure about it.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
-
Hi, If you only want to keep the latest text only, then dont concatenate the original text with the new one. I think you might be doing something like this -
RichTextBox1.Text = RichTextBox1.Text + this.getTheData(buffer);
Change it toRichTextBox1.Text = this.getTheData(buffer);
Hope i got what you want, but i am not sure about it.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
-
Hi, I got it exactly like how you suggest it to do. But the buffer still has its data from the previous serialPort.ReadExisting(); execution.