title: C# Read serial port value only if changed (weight machine)
body: <pre><code>private SerialPort _serialPort = null;
  
  public WeightDisplay()
  {
      InitializeComponent();
      Control.CheckForIllegalCrossThreadCalls = false; 
      _serialPort = new SerialPort("COM1", 9600, Parity.None, 8);
      _serialPort.StopBits = StopBits.One;
      _serialPort.DataReceived += new SerialDataReceivedEventHandler(_serialPort_DataReceived);
      _serialPort.Open();
  }
  void _serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
  {
      txtWeight.Text = _serialPort.ReadExisting();
  }
  </code></pre>
  
  <p>This code continuously gets values from weight machine connected to serial port and displays it in a textbox. Code works fine but I want to change the value of textbox if there is change in weight ie. if value returned by <code>ReadExisting()</code> differs from previous value.(I don't want the textbox to be fluctuated for no reason)</p>
  
  <p>When I debug I get this value:</p>
  
  <blockquote>
    <p>"+  0.000 S\r+  0.000 S\r+  0.000 S\r+  0.000 S\r+  0.000 S\r+  0.000 S\r" </p>
  </blockquote>
  
  <p>sometimes even big string</p>
  
  <p>And my textbox displays  <code>"+  0.000"</code> (continuously blinking)</p>