title: Working with SerialPort´s DataReceived Event
body: <p>Im trying to read the output of a device on a COM port on my PC.
  Im wrote a C# program to do so.
  Using PuTTY, I can see the output Im expecting from my device.
  The problem is that the function <code>SerialPort.ReadExisting();</code> in my <code>DataReceived</code> function gives my a completely different string.
  What is the proper way to read from a COM port using <code>SerialPort</code>?</p>
  
  <p>Also, the strings I get from <code>SerialPort.ReadExisting();</code> are fragments of the string I sent to the device.</p>
  
  <p>Below is the code that initializes the <code>SerialPort</code>.</p>
  
  <pre><code>    SerialPort port;
  
      void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
      {
          string data = port.ReadExisting();
      }
  
      void init_serialport(object sender, EventArgs e)
      {
          if (port != null)
          {
              port.Close();
          }
  
          port = new SerialPort( /* ... */ );
          port.BaudRate = 9600;
          port.Parity = Parity.None;
          port.DataBits = 8;
          port.StopBits = StopBits.One;
          port.Handshake = Handshake.RequestToSend;
  
          port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
  
          try
          {
              port.Open();
          }
          catch (Exception ex)
          {
               // ...
          }
      }
  </code></pre>