private void testbtn_Click(object sender, EventArgs e) { 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(); } 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.amp = Convert.ToDouble(ampBox.Text); wavedata.Genarate(); wavedata.SaveFile(Createfilename("single", "wav")); MessageBox.Show(" 文件已保存", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception myEx) { MessageBox.Show(myEx.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { wavedata.Dispose(); } } 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(); wavedata.SaveFile(Createfilename("chirp", "wav")); MessageBox.Show(" 文件已保存", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception myEx) { MessageBox.Show(myEx.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { wavedata.Dispose(); } } }
//下发数据文件 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); } } }