private void serialConnect(int request) { connectSerialBool = Serial_Functions.connectSerialLogic(request); if (connectSerialBool[0] && connectSerialBool[1]) { serialPort.PortName = ComPortNumber.Text; serialPort.Open(); SerialConnectionStatus.Text = "Connected"; SerialConnectionStatus.BackColor = System.Drawing.Color.DarkSeaGreen; Thread.Sleep(500); } if (!connectSerialBool[0] && connectSerialBool[1]) { serialPort.Close(); SerialConnectionStatus.Text = "Disconnected"; SerialConnectionStatus.BackColor = System.Drawing.Color.IndianRed; } if (connectSerialBool[0] && !connectSerialBool[1]) { MessageBox.Show("No Ports Available", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); SerialConnectionStatus.Text = "No Ports"; } if (!connectSerialBool[0] && !connectSerialBool[1]) { MessageBox.Show("Port Error", "OS Error", MessageBoxButtons.OK, MessageBoxIcon.Information); //statusConnectionStatus.Text = "Port Fault"; SerialConnectionStatus.BackColor = Color.Red; } }
private void SerialConnectionStatus_Click(object sender, EventArgs e) { if (Serial_Functions.connectionStatus()) { serialConnect(disconect); } else { serialConnect(connect); } }
private void ScanSerial(bool errorMode) { bool serialDetected = Serial_Functions.IfSerialDetected(errorMode); string portNum = Serial_Functions.returnPortNumber(); if (serialDetected == true) { ComPortNumber.Text = Serial_Functions.returnPortNumber(); serialPort.ReadTimeout = 10000; serialPort.BaudRate = 19200; } else { SerialConnectionStatus.Text = "No Ports"; SerialConnectionStatus.BackColor = Color.Yellow; serialConnect(disconect); } }