private void Off_M1_Click(object sender, EventArgs e) { //button to decrement offset by 1 if (off > 0 && off < 129) { off = off - 1; } OffsetText.Clear(); string n = Convert.ToString(off); OffsetText.AppendText(n); if (serialPort1.IsOpen) { serialPort1.Write("H"); //send flag Thread.Sleep(10); } }
private void Off_P10_Click(object sender, EventArgs e) { //button to increment offset by 10 if (off >= 0 && off <= 118) { off = off + 10; } OffsetText.Clear(); string n = Convert.ToString(off); OffsetText.AppendText(n); if (serialPort1.IsOpen) { serialPort1.Write("I"); //send flag Thread.Sleep(10); } }
private void Stop_btn_Click(object sender, EventArgs e) { //reset dropdowns to none and clear textboxes Passband.Text = "(none)"; tbAscii.Clear(); SampFreq.Text = "(none)"; ShiftText.Clear(); theDialog.FileName = ""; OffsetText.Clear(); FilePath.Text = theDialog.FileName; if (serialPort1.IsOpen) { serialPort1.Write("S"); //send stop flag to chip } //reset stop flag stop_flag = false; //disable buttons Shift_P1.Enabled = false; Shift_M1.Enabled = false; Off_M1.Enabled = false; button1.Enabled = false; Off_M10.Enabled = false; Off_P10.Enabled = false; }
private void Send_btn_Click(object sender, EventArgs e) { if (stop_flag == false) //stop button pressed and ready for new data { error_flag = false; OffsetText.Clear(); OffsetText.AppendText("128"); //default offset & display if (Passband.Text == "Lowpass") { if (serialPort1.IsOpen) { serialPort1.Write("L"); //send lowpass flag to chip Thread.Sleep(20); } shift = 21; //default shift value ShiftText.Clear(); ShiftText.AppendText("21"); //display 21 } else if (Passband.Text == "Bandpass") { if (serialPort1.IsOpen) { serialPort1.Write("B"); //send bandpass flag to chip Thread.Sleep(20); } shift = 19; //default shift value ShiftText.Clear(); ShiftText.AppendText("19"); //display value } else if (Passband.Text == "(none)") { //send error if nothing selecting error_flag = true; MessageBox.Show("A Passband Must be Selected.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (SampFreq.Text == "1 KHz") { if (serialPort1.IsOpen) { serialPort1.Write("X"); //send flag Thread.Sleep(20); } } else if (SampFreq.Text == "1.5 KHz") { if (serialPort1.IsOpen) { serialPort1.Write("Y"); //send falg Thread.Sleep(20); } } else if (SampFreq.Text == "2 KHz") { if (serialPort1.IsOpen) { serialPort1.Write("Z"); //send flag Thread.Sleep(20); } } else if (SampFreq.Text == "(none)") { //send error if nothing selecting error_flag = true; MessageBox.Show("A Sampling Frequency Must be Selected.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (FilePath.Text == "") { //send error if nothing selecting MessageBox.Show("A File Must be Selected.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); error_flag = true; } if (!error_flag) { //open and read the file file = File.ReadAllText(theDialog.FileName); file = file.Substring(file.IndexOf('{') + 2); //delete the { and everything before file = file.Substring(0, file.IndexOf('}') - 1); //delete the } and everything after file = file.Replace(" ", ""); //relpace spaces with nothing file = file.Replace("\n", ""); //replace end line with nothing data = file.ToCharArray(); //convert to char array for (int i = 0; i < data.Length; i++) { //send on char at a time if (serialPort1.IsOpen) { string c = data[i].ToString(); serialPort1.Write(c); Thread.Sleep(20); } } if (serialPort1.IsOpen) { serialPort1.Write("D"); //send done flag } stop_flag = true; //wait for stop button to be pressed theDialog.FileName = ""; //clear file name FilePath.Text = theDialog.FileName; //enable shift and off set buttons Shift_P1.Enabled = true; Shift_M1.Enabled = true; Off_M1.Enabled = true; button1.Enabled = true; Off_M10.Enabled = true; Off_P10.Enabled = true; } } }