【发布时间】:2022-10-02 15:06:35
【问题描述】:
我正在尝试将 115200 Bd 的一些数据传输到 C# 表单 RichTextBox。下面是我的 Arduino 代码:
void serialEvent() {
if (Serial.available()) {
int command = Serial.parseInt();
Serial.println(command);
switch(command) {
case 1:
/*executes its job and writes data in the following format in each line - xxxxxx xxx xxx*/
break;
case 0:
/*executes another unrelated job*/
break;
}
}
}
现在,在 6000/7000 行附近,总的书面行数停止打印到我的 C# 表单。为什么会这样,以及如何纠正它?我无法降低波特率;事实上,我想增加它。我希望以一种可以通过 C# 表单对其执行数学函数的方式访问数据,并在需要时复制它。
下面是我的 C# 表单应用程序代码部分:
private void settext(string val)
{
richTextBox1.AppendText(val);
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string incomstring = serialPort1.ReadLine();
settext(incomstring);
}
private void button5_Click_1(object sender, EventArgs e)
{
try
{
Cursor.Current = Cursors.WaitCursor;
if (serialPort1.IsOpen)
{
serialPort1.WriteLine(\"1\");
}
else
{
MessageBox.Show(\"Open Port FIrst.\", \"Port not open.\", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
Cursor.Current = Cursors.Default;
}
}
-
不要在活动中打印出来
-
您可以为串行流添加缓冲和流量控制吗?这样您就可以为自己争取更多时间来处理所有数据。
-
@PapaAtHome 之前有人提到过这样的事情,将其分成块并使用缓冲区数组,但我不知道该怎么做。你能建议样品或解决方案吗?
-
@NeilButterworth我很抱歉我不明白,请用更通俗的方式解释。
标签: c# c++ serial-communication