C#使用TextBox作数据输入方法

  private void Botton_Float_Click(object sender, EventArgs e)

  {

  if (button1.Text == "关闭串口")

  {

  if(TextBox_Tem_Cal.Text != String .Empty) //判断数据输入框是否为空

  {

  HexMath CRC = new HexMath();

  Byte[] buffer = new Byte[6];

  float tem_cal_float = float.Parse(TextBox_Tem_Cal.Text);

  Byte[] float_byte_array = new Byte[4];

  float_byte_array = FloatToBytes(tem_cal_float);

  buffer[0] = float_byte_array[0];

  buffer[1] = float_byte_array[1];

  buffer[2] = float_byte_array[2];

  buffer[3 ] = float_byte_array[3];

  CRC.CalculateCrc16(buffer, out buffer[5], out buffer[4]);

  serialPort1.Write(buffer, 0, 6);

  }

  else

  {

  MessageBox.Show("校准数据不能为空");

  }

  }

  else

  {

  MessageBox.Show("串口未打开");

  }

  }