title: Reading data from a RS232 port with RFID
body: <p><strong>UPDATE</strong>  </p>
  
  <p>I'm reading an <code>RFID Card</code>, and signing it's value into my <code>textbox.text</code>.<br>
  It's working in the first time I pass the card in my <code>RFID Reader</code>, but form the second time I pass the card, instead it shows the whole card's id on my <code>textbox.text</code>, it's showing only the LAST letter of the card's id. Sometimes you can see the whole number appear and vanish very fast on the textbox, but from the second time you pass the card, only the last letter remain in the textbox.<br>
  What may be causing this ?  </p>
  
  <p>Here's my current code:  </p>
  
  <pre><code>using System;
  using System.Windows.Forms;
  using System.IO.Ports;
  using System.Text;
  using System.Text.RegularExpressions;
  
  namespace RFID_Reader
  {
      public partial class PortaSerial : Form
      {
          private SerialPort porta_serial = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
  
  
          public PortaSerial()
          {
              InitializeComponent();
          }
  
          private void PortaSerial_Load(object sender, EventArgs e)
          {
              try
              {
                  if (porta_serial.IsOpen)
                  {
                      porta_serial.Close();
                  }
                  porta_serial.Open();
                  porta_serial.DtrEnable = true;
                  porta_serial.DataReceived += new SerialDataReceivedEventHandler(Recebe_Data);
              }
              catch (Exception ex)
              {
                  throw new Exception(ex.Message);
              }
          }
  
          void Recebe_Data(object sender, SerialDataReceivedEventArgs e)
          {
              try
              {               
                  string oi = porta_serial.ReadExisting().ToString();
                  SetLabel(oi);
              }
              catch (Exception ex)
              {
                  throw new Exception(ex.Message);
              }
          }
  
          void SetLabel(String s)
          {
              try
              {
                  if (this.InvokeRequired)
                  {
                      this.Invoke(new Action&lt;String&gt;(SetLabel), s);
                      return;
                  }
                  textBox1.Text = RemoveSpecialCharacters(s);           
              }
              catch (Exception ex)
              {
                  throw new Exception(ex.Message);
              }
          }       
  
          public static string RemoveSpecialCharacters(string str)
          {
              StringBuilder sb = new StringBuilder();            
              foreach (char c in str)
              {
                  if ((c &gt;= '0' &amp;&amp; c &lt;= '9') || (c &gt;= 'A' &amp;&amp; c &lt;= 'Z') || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || c == '.' || c == '_')
                  {
                      sb.Append(c);
                  }
              }
              return sb.ToString();
          }
      }
  }
  </code></pre>