title: COMport.Readline() Issues : Flooded buffer and string manipulation
body: <p>I have a weight scale that has constant output to a serial port. I made an application that loops every 3 seconds to read the newest weight on the scale, the loop uses a <code>Async</code> Sub and then a <code>Await Task.Run(Sub()</code> then sleeps for 3 seconds. I am having 2 issues.</p>
  
  <p>First, The buffer is flooding with data and therefore if you take weight off, say 100 lb, it still reads the old data in the buffer meanwhile the actual weight on the scale is 0. But it slowly goes down every 3 secs. I tried to loop the <code>readline()</code> continuously in a Backgroundworker but the scale still outputs to fast. Should I try 'DiscardBuffer()' before <code>readline()</code>? Or is there another reading method?</p>
  
  <p>Code: COM Port Props</p>
  
  <pre><code>    With COMScale 'COM Port Properties
  
          .PortName = cmbPorts.Text 'COM Port Name
  
          .Parity = IO.Ports.Parity.None
  
          .DataBits = 8
  
          .StopBits = IO.Ports.StopBits.One
  
          .BaudRate = 9600
  
          .ReceivedBytesThreshold = 1
  
          .NewLine = vbCr
  
          .ReadTimeout = 5000
  
      End With
  </code></pre>
  
  <p>Code: Backgroundworker</p>
  
  <pre><code>Private Sub BackgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork
  
      WeightA = 0
  
      COMScale.DiscardInBuffer()
  
      Try
  
          COMScale.ReadTimeout = 10000
  
          Do
  
              Dim Incoming As String = COMScale.ReadLine()
  
              If Incoming Is Nothing Then
  
                  Exit Do
  
              Else
  
                  WeightA &amp;= Incoming
  
              End If
  
          Loop
  
      Catch ex As TimeoutException
  
          WeightA = "N/A"
  
          MsgBox(COMScale.PortName &amp; "Timed Out")
  
      Finally
  
          'If com1 IsNot Nothing Then com1.Close()
  
          lblWeightA.Text = WeightA
  
      End Try
  
  End Sub
  </code></pre>
  
  <p>Second issue is the string the scale outputs, it likes like this...</p>
  
  <p>"5?" &amp; ChrW(2) &amp; ChrW(2) &amp; "??j" &amp; ChrW(2) &amp; ";     47" &amp; ChrW(2) &amp; ChrW(2) &amp; ChrW(2) &amp; ChrW(2) &amp; "??j" &amp; ChrW(2) &amp; ";     475" &amp; ChrW(2) &amp; ChrW(2) &amp; ChrW(2) &amp; "??j" &amp; ChrW(2) &amp; ";     475    00"  </p>
  
  <p>On the scale it says 47.5 lbs</p>
  
  <p>All I need is the "475" numbers at the end but with a decimal so the string is 47.5 . The only thing I can think of is <code>Right(string)</code> issue I see with using <code>Right(String)</code> is that it could be 1000 lbs, 100 lbs or 10 lbs, so it would cut off what I need. Whats my best option here?</p>