我正在尝试使用 c# 串行端口将数据称重秤读取到我的计算机上。
在这样的腻子输出中:
60KG
60KG
60KG
60KG
然后我使用下面的脚本在richtextbox中显示它:
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();
}
}
}
但像这样显示
6
0
6
0
6
0
有什么不对 ?