public Form2(string COMPort, int Baud_Rate) { InitializeComponent(); this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form2_FormClosed); Quad_SerialPort.PortName = COMPort; Quad_SerialPort.BaudRate = Baud_Rate; Quad_SerialPort.Open(); if (Quad_SerialPort.IsOpen) { progressBar1.Value = 20; Connection_ListBox.Items.Add("Connected to the Device"); Connection_ListBox.Items.Add("Trying to Communicate..."); GetCommunicationStatus(); } else { MessageBox.Show("An Error Occurred while Connecting to the Device", "Failed to Connect", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } }
private void button1_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex > -1) { String Port_Name = comboBox1.Text; Quad_SerialPort.PortName = Port_Name; int BaudRate_Int = 0; if (BaudRate.SelectedIndex > -1) { int.TryParse(BaudRate.Text, out BaudRate_Int); Quad_SerialPort.BaudRate = BaudRate_Int; Quad_SerialPort.Open(); if (Quad_SerialPort.IsOpen) { MessageBox.Show("Connection Established!"); Quad_SerialPort.Close(); this.Hide(); Form2 newscrn = new Form2(Port_Name, BaudRate_Int); newscrn.Show(); } else { MessageBox.Show("Check the COM Port Status Again."); } } else { MessageBox.Show("Please Select the Baud Rate"); } } else { MessageBox.Show("Please Select a COM Port"); } }