title: How to read specific characters from RS232 serial port data
body: <p>I am trying to retrieve weight data from a weight indicator which sends data through the RS232 com port ( Converted through USB)</p>
  <p>following is the application I designed to receive data</p>
  <p><a href="https://i.stack.imgur.com/XX37o.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p>the problem is it shows all the data which is sent from the indicator but the real weight reading is 15,000.</p>
  <p>How can I achieve this?</p>
  <p>Thank you</p>
  <p>Data sheet of the indicator is as follows</p>
  <p><a href="https://i.stack.imgur.com/0j1yt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0j1yt.png" alt="enter image description here" /></a></p>
  <p>Code is as follows</p>
  <p>namespace Weight_Test
  {
  public partial class Form1 : Form
  {
  string dataIN;</p>
  <pre><code>    public Form1()
      {
          InitializeComponent();
      }
  
      private void Form1_Load(object sender, EventArgs e)
      {
          string[] ports = SerialPort.GetPortNames();
          cbComPort.Items.AddRange(ports);
          btnOpen.Enabled = true;
          btnClose.Enabled = false;
      }
  
      private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
      {
          dataIN = serialPort1.ReadExisting();
          this.Invoke(new EventHandler(ShowData));
      }
  
      private void ShowData(object sender, EventArgs e)
      {
          txtWeight.Text = dataIN;
      }
  
      private void btnOpen_Click(object sender, EventArgs e)
      {
          try
          {
              serialPort1.PortName = cbComPort.Text;
              serialPort1.BaudRate = Convert.ToInt32(9600);
              serialPort1.DataBits = Convert.ToInt32(8);
              serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), &quot;One&quot;);
              serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), &quot;None&quot;);
  
              serialPort1.Open();
              btnOpen.Enabled = false;
              btnClose.Enabled = true;
          }
          catch (Exception err)
          {
              MessageBox.Show(err.Message, &quot;Error&quot;, MessageBoxButtons.OK, MessageBoxIcon.Error);
              btnOpen.Enabled = true;
              btnClose.Enabled = false;
          }
      }
  
      private void btnClose_Click(object sender, EventArgs e)
      {
          if (serialPort1.IsOpen)
          {
              serialPort1.Close();
              btnOpen.Enabled = true;
              btnClose.Enabled = false;
          }
      }
  }
  </code></pre>
  <p>}</p>