Visual Studio windows窗体应用程序C#串行通信是否接收数据?

Visual Studio windows窗体应用程序C#串行通信是否接收数据?,c#,winforms,visual-studio-2013,arduino-uno,serial-communication,C#,Winforms,Visual Studio 2013,Arduino Uno,Serial Communication,我需要一个代码,将从arduino接收串行数据,并显示在文本框中。 我正在接收用逗号分隔的整型数据。 Arduino串行数据示例:250389123225536366455 我需要在六个单独的文本框中显示前六个数据,然后连续的数据必须替换这些文本框中已经存在的值。 我试了好几次,但都没有成功。有人可以帮我。我假设您正在使用System.IO.Ports命名空间和SerialPort类进行通信。我还希望波特率和其他通信设置符合设备的预期。 如果是,则如果重复接收数据,可以使用ReadTo方法捕获数

我需要一个代码,将从arduino接收串行数据,并显示在文本框中。 我正在接收用逗号分隔的整型数据。 Arduino串行数据示例:250389123225536366455

我需要在六个单独的文本框中显示前六个数据,然后连续的数据必须替换这些文本框中已经存在的值。
我试了好几次,但都没有成功。有人可以帮我。

我假设您正在使用System.IO.Ports命名空间和SerialPort类进行通信。我还希望波特率和其他通信设置符合设备的预期。
如果是,则如果重复接收数据,可以使用ReadTo方法捕获数据,并将逗号作为参数。这样的读取循环可能如下所示:

while(true) // replace it with some wiser condition
{
    string textRead = serialPort.ReadTo(",");
    // do the rest here
}
TextBox[] tboxes = new TextBox[N]; // your number is 6, I know
int boxIndex = 0;
while(true) // again, use a reasonable condition
{
    string textRead = serialPort.ReadTo(",");
    tboxes[boxIndex].Text = textRead.Trim(',');
    if(++boxIndex >= tboxes.Length)
        boxIndex = 0;
}
现在,您可能还希望一次捕获更多的数据。当然你可以(比如说,捕捉100个字符),但是你应该:
-用逗号分隔字符串
-保留字符串数组的最后一项(这将是拆分方法的结果),并在下一个接收到的字符包的0位置插入
-在上面的循环中重复这些步骤。
现在,转到文本框。如果有N个,并且我们考虑了第一个捕获方法,您可以这样做:

while(true) // replace it with some wiser condition
{
    string textRead = serialPort.ReadTo(",");
    // do the rest here
}
TextBox[] tboxes = new TextBox[N]; // your number is 6, I know
int boxIndex = 0;
while(true) // again, use a reasonable condition
{
    string textRead = serialPort.ReadTo(",");
    tboxes[boxIndex].Text = textRead.Trim(',');
    if(++boxIndex >= tboxes.Length)
        boxIndex = 0;
}


这应该可以完成任务。

您是在使用WinForms还是WPF或其他什么?先生,Windows窗体应用程序……您还可以使用SerialWatcher查看端口的实际情况,并最终调整波特率、奇偶校验等。