title: Processing and displaying data from serial port - C#
body: <p>I'm developing a small program that receives analog data from the serial port and displays it into multiple Textboxes. 
  The data is 10 bit A2D from a micro in the form of two Hex bytes and a letter to identify which A2D port it came from.</p>
  
  <p>eg: 0x1A, 0x02, A</p>
  
  <p>My program is receiving the data ok, and if I only display receive analog value at a time it works fine.
  The problem I have is that I'm unsure how to process the incoming data when I try to receive multple A2D values.</p>
  
  <p>The code below is suppose to display 3 analog values in separate text boxes, but only the first text box displays any data.  What would be the best way to go able this?</p>
  
  <pre><code>private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
  {
      //Initialize a buffer to hold the received data 
      byte[] buffer = new byte[serialPort1.ReadBufferSize];
  
      int bytes = serialPort1.BytesToRead;
  
      //There is no accurate method for checking how many bytes are read 
      //unless you check the return from the Read method 
      bytesRead = serialPort1.Read(buffer, 0, bytes);
  
      nValue = buffer[0] + (buffer[1] &lt;&lt; 8);
      switch1 = Convert.ToChar(buffer[2]);
      switch (switch1)
      {
          case 'A':
              DispString1 = nValue.ToString();
              this.Invoke(new EventHandler(textBox0_TextChanged));
              break;
          case 'B':
              DispString2 = nValue.ToString();
              this.Invoke(new EventHandler(textBox1_TextChanged));
              break;
          case 'C':
              DispString3 = nValue.ToString();
              this.Invoke(new EventHandler(textBox2_TextChanged));
              break;
      }
  }
  
  private void textBox0_TextChanged(object sender, EventArgs e)
  {
      textBox0.Text = DispString1;
  }
  
  
  private void textBox1_TextChanged(object sender, EventArgs e)
  {
      textBox1.Text = DispString2;
  }
  
  private void textBox2_TextChanged(object sender, EventArgs e)
  {
      textBox2.Text = DispString3;
  }
  </code></pre>