private void Shift_M1_Click(object sender, EventArgs e) { //button todecrement shift by 1 if (shift > 0 && shift < 32) { shift = shift - 1; } ShiftText.Clear(); string n = Convert.ToString(shift); ShiftText.AppendText(n); if (serialPort1.IsOpen) { serialPort1.Write("C"); //send flag Thread.Sleep(10); } }
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; } } }