【发布时间】:2017-01-17 08:04:45
【问题描述】:
我正在尝试使用 c# 串行端口将数据称重读取到我的计算机。
在这样的腻子输出中:
60公斤
60公斤
60公斤
60公斤
然后我使用下面的脚本在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
有什么问题吗?
【问题讨论】:
-
你试过
ReadLine吗?
标签: regex serial-port weighting