title: Read bytes from serial port
body: <p>I have written code to read data as a byte array from a serial port and show it in a textbox. The code compiles fine, but doesn't work properly:</p>
  
  <pre><code>private void button2_Click(object sender, EventArgs e)
  {
      if (serialPort1.IsOpen == false)
          serialPort1.Open();
      serialPort1.WriteLine(textBox1.Text);
      int bytes = serialPort1.BytesToRead;
      byte[] byte_buffer = new byte[bytes];
      serialPort1.Read(byte_buffer, 0, bytes);
      //textBox2.Text = " ";
      for (int t = 0; t &lt; bytes; t++)
      {
          textBox2.Text += (byte_buffer[t]).ToString();
      }
  }
  </code></pre>