I'm trying to read the data weighing scale to my computer using c# serial port.
in putty output like this :
60KG
60KG
60KG
60KG
then i display it in richtextbox using the script below:
private void SerialPortOnDataReceived(object sender, SerialDataReceivedEventArgs serialDataReceivedEventArgs)
{
if (InvokeRequired) //<-- Makes sure the function is invoked to work properly in the UI-Thread
BeginInvoke(new Closure(() => { SerialPortOnDataReceived(sender, serialDataReceivedEventArgs); })); //<-- Function invokes itself
else
{
while (_serialPort.BytesToRead > 0) //<-- repeats until the In-Buffer is empty
{
String tampung = _serialPort.ReadExisting();
String tampungy = Regex.Replace(tampung, @"[^\d]", "").Trim();
richTextBox2.AppendText(tampungy + System.Environment.NewLine);
richTextBox2.ScrollToCaret();
}
}
}
but displays like this
6
0
6
0
6
0
Is there something wrong ?