等待Serialport上的数据

时间:2013-12-06 14:21:39

标签: c# c#-4.0 serial-port

我正在寻找一种方法来阻止我的程序直到我的EventHandel在serialport上找到足够的数据。

我的代码目前看起来像这个Part01:

private void DisplayText(object sender, EventArgs e)
    {

        textBox1.AppendText(RxString);
        RxHistorie.Add(RxString);
        textBox1.AppendText("\n");

    }

    private void DataReceivedHandler(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
    {

        RxString = serialPort1.ReadLine();
        this.Invoke(new EventHandler(DisplayText));

    }

Part02:

 private void createRandomPic_Click(object sender, EventArgs e)
        {
            int numRows, numCols,i,j;
            Int32.TryParse(textBox5.Text, out numRows);
            Int32.TryParse(textBox6.Text, out numCols);
            j=RxHistorie.Count;

            string msg = String.Format("3,{0},{1},0", numRows, numCols);
            serialPort1.WriteLine(msg);
            bool done = false;
            while (!done)
            {

                if (RxHistorie.Count >= j + numCols * numRows)
                {done=true;}
            }
       }

有任何想法吗?

0 个答案:

没有答案