title: How to read data from serial port of system using c#
body: <p>I am try to create software for weighing bridge, while try read data using c# code, its showing some other data something like below mentioned</p>
  
  <pre>
  )0 12589 00
  )0 12589 00
  )0 12589 00
  )0 12589 00
  )0 12589 00
  )0 12589 00
  </pre>
  
  <pre><code>private void timer1_Tick(object sender, EventArgs e)
  {
      string Port = GenDbUtility.GetElixirConfigValue("SERIAL_PORT", Globals.CompCode);
  
      //&lt;-- This block ensures that no exceptions happen
      if (serialPort1 != null &amp;&amp; serialPort1.IsOpen)
          serialPort1.Close();
      if (serialPort1 != null)
          serialPort1.Dispose();
      //&lt;-- End of Block
  
  
      serialPort1 = new SerialPort("COM1");       //&lt;-- Creates new SerialPort using the name selected in the combobox
      serialPort1.Encoding = Encoding.ASCII;
      serialPort1.BaudRate = 9660;
      serialPort1.Parity = Parity.None;
      serialPort1.StopBits = StopBits.One;
      serialPort1.DataBits = 50;
      serialPort1.Handshake = Handshake.None;
      serialPort1.RtsEnable = true;
      serialPort1.ReadBufferSize = 4096;
      serialPort1.ReceivedBytesThreshold = 100000;
      serialPort1.NewLine = "\r\n";
      serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
      serialPort1.Open();     //&lt;-- make the comport listen
  }
  
  void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
  {
      if (serialPort1.IsOpen)
      {
          SerialPort sp = (SerialPort)sender;
  
          string newVal = sp.ReadExisting().ToString();
          ///string[] qty = newVal.Split(' ');
          //txtQuantity.Invoke(this.myDelegate, new Object[] { qty[3].ToString() });   
          //string[] qty = newVal.Split(' ');
          //decimal Quantity1 = Convert.ToDecimal(qty[0]);
          //decimal Quantity2 = Convert.ToDecimal(qty[1]);
          //decimal Quantity3 = Convert.ToDecimal(qty[2]);
          //decimal Quantity4 = Convert.ToDecimal(qty[3]);
          //txtQuantity.Text = Quantity3.ToString();
  
          //if (String.Compare(txtQuantity.Text, qty[3]) != 0)
          //{
          //    txtQuantity.Text = Convert.ToString(qty[3]);
          //    //lblweight.Text = Convert.ToString(qty[2]);
          //        //qty[2].ToString();
          //}
      }
  }
  </code></pre>