Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to wait for incoming data

how to wait for incoming data

Scheduled Pinned Locked Moved C#
helptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yustme
    wrote on last edited by
    #1

    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!

    C 1 Reply Last reply
    0
    • Y Yustme

      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!

      C Offline
      C Offline
      coolestCoder
      wrote on last edited by
      #2

      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 to RichTextBox1.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

      Y 1 Reply Last reply
      0
      • C 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 to RichTextBox1.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

        Y Offline
        Y Offline
        Yustme
        wrote on last edited by
        #3

        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.

        R 1 Reply Last reply
        0
        • Y Yustme

          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.

          R Offline
          R Offline
          Rey9999
          wrote on last edited by
          #4

          serialport.DiscardInBuffer();

          ~~~ From Milano to The Hague, easy as it goes ~~~

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups