private void DloadFPGABtn_Click(object sender, EventArgs e) { char[] sendbuf;//下发数据缓存 openFileDialog.Filter = "FPGA文件(*.data)|*.data|所有文件(*.*)|*.*"; if (openFileDialog.ShowDialog() == DialogResult.OK) { FPGA_filename.Text = openFileDialog.FileName; } if (!File.Exists(FPGA_filename.Text)) { try { Encoding ascii = Encoding.ASCII; string readText = File.ReadAllText(FPGA_filename.Text, ascii); sendbuf = new char[readText.Length]; readText.CopyTo(0, sendbuf, 0, readText.Length); DloadType = 1; NetSender.RunWorkerAsync(sendbuf); } catch (Exception myEx) { MessageBox.Show(myEx.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("文件不存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//下发数据文件 private void sendbtn_Click(object sender, EventArgs e) { byte[] sendbuf; //判断时间长度是否合法 //if (Convert.ToInt32(lenBox.Text) <= 0 || Convert.ToInt32(lenBox.Text) > 3000) //{ // MessageBox.Show(" 长度设置错误(0 - 3000)", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} //if (Convert.ToInt32(textBox6.Text) <= 0 || Convert.ToInt32(textBox6.Text) > 3000) //{ // MessageBox.Show(" 长度设置错误(0 - 3000)", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} ////判断幅度是否合法 try { amp = Convert.ToDouble(ampBox.Text); if (amp >= 0.1 && amp <= 1) { AmpValidate.SetError(ampBox, ""); } else { AmpValidate.SetError(ampBox, "范围有误!(0.1 - 1)"); MessageBox.Show(" 幅度设置错误", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch (Exception myEx) { AmpValidate.SetError(ampBox, "格式有误!(0.1 - 1)"); ampBox.Focus(); } //禁止下发数据时重新发数据 sendbtn.Enabled = false; if (radioButton1.Checked) { CosineWave wavedata = new CosineWave(); try { wavedata.Set(Convert.ToDouble(textBox3.Text), Math.PI, Convert.ToInt32(comboBox1.Text), amp, Convert.ToDouble(lenBox.Text)); wavedata.Genarate(); sendbuf = new byte[(int)(wavedata.Length * wavedata.SampleRate) * 2]; wavedata.copy(sendbuf); toolProgressBar.Visible = true; DloadType = 0;//下载数据 NetSender.RunWorkerAsync(sendbuf); } catch (Exception myEx) { MessageBox.Show(myEx.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } if (radioButton2.Checked) { ChirpWave wavedata = new ChirpWave(); try { wavedata.Set(Convert.ToDouble(textBox2.Text), Convert.ToDouble(textBox4.Text), Convert.ToInt32(comboBox2.Text), Convert.ToDouble(textBox6.Text), amp); wavedata.Genarate(); sendbuf = new byte[(int)(wavedata.Length * wavedata.SampleRate) * 2]; wavedata.copy(sendbuf); NetSender.RunWorkerAsync(sendbuf); } catch (Exception myEx) { MessageBox.Show(myEx.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { wavedata.Dispose(); } } if (radioButton3.Checked) { try { FileStream fs = new FileStream(filepathbox.Text, FileMode.Open, FileAccess.Read); filereader = new BinaryReader(fs); sendbuf = new byte[fs.Length]; filereader.Read(sendbuf, 0, (int)fs.Length); NetSender.RunWorkerAsync(sendbuf); } catch (Exception myEx) { MessageBox.Show(myEx.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }