解决方案 »

  1.   

      protected void Button4_Click(object sender, EventArgs e)
        {
          
             Button4.Enabled = false;
            Button3.Enabled = true;
            com = new System.IO.Ports.SerialPort();       
            if (com.IsOpen)
            {            com.Close();        }
            else
            {
                com.PortName = "COM1";
                com.BaudRate = 115200;
                com.DataBits = 8;
                com.StopBits = (System.IO.Ports.StopBits)1;
                com.Open();            for (int i = 1; i <= 24; i++)
                {
                    if (com.IsOpen)
                    {
                        System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
                        byte[] byteArray = new byte[] { (byte)com.ReadByte() };
                        string strCharacter = asciiEncoding.GetString(byteArray);
                        TextBox1.Text += strCharacter;
                    }
                    else
                        com.Close();
                }
            }
        }
      

  2.   

    我的端口读取代码如上,但是我不会写循环啊,望大神帮我把循环代码写出来啊,还有就是我的设计思路是很清晰的,但是把Textbox中显示的当前项目依次写入Gridview  也是需要循环写入,这部分代码我也不会写,然后就是将Gridview中的数据写入数据库的代码我也不会写,总之,大神,你把代码写出来我看看呗