void GetCommunicationStatus() { Quad_SerialPort.Write("c"); for (int i = 0; i < 100000; i++) { ; } try { Status = Quad_SerialPort.ReadLine(); Status.Trim(); Connection_ListBox.Items.Add("Data Received"); } catch (TimeoutException) { Connection_ListBox.Items.Add("Timeout Exception Occurred"); } //Connection_ListBox.Items.Add("Status:"); Connection_ListBox.Items.Add("\n\n"); Connection_ListBox.Items.Add(Status); Connection_ListBox.Items.Add("\n\n"); if (Status == "Granted") { progressBar1.Value = 40; Connection_ListBox.Items.Add("Access Granted"); Quad_SerialPort.Write("b"); try { DataRequest = Quad_SerialPort.ReadLine(); DataRequest.Trim(); } catch (TimeoutException) { Connection_ListBox.Items.Add("Timeout Exception Occurred"); } if (DataRequest == "Request Granted") { progressBar1.Value = 70; Connection_ListBox.Items.Add("Exchanging Data"); /* * * Check Code Here * */ } else { Connection_ListBox.Items.Add("Invalid Data"); //MessageBox.Show("An Error Occurred while Trying to Exchange Data with the Device", "Data Sharing Unavailable", MessageBoxButtons.OK, MessageBoxIcon.Error); //this.Close(); } } else { Connection_ListBox.Items.Add("Invalid Data"); //MessageBox.Show("An Error Occurred while Connecting to the Device", "Failed to Communicate", MessageBoxButtons.OK, MessageBoxIcon.Error); //this.Close(); } }