private void connectToESP() { isConnected = true; string selectedPort = comboBox1.GetItemText(comboBox1.SelectedItem); //Command SerialPort sPort = new SerialPort(selectedPort, 115200, Parity.None, 8, StopBits.One); // important contection waht buard rate esp32 needs etc. port = new CryptoPort(sPort); port.Open(); button1.Text = "Disconnect"; enableControls(); byte[] bytesToSend = { Convert.ToByte('#'), Convert.ToByte(0xa), Convert.ToByte('\n') }; port.Write(bytesToSend, 0, 3); port.DiscardInBuffer(); string recvStr = port.ReadLine(); byte[] receivedByte = Encoding.ASCII.GetBytes(recvStr); if (receivedByte[0] == 1) { MessageBox.Show("UART connection established"); port.setBluetoothMode(false); } else if (receivedByte[0] == 0) { port.setBluetoothMode(true); MessageBox.Show("Bluetooth connection established"); } else { MessageBox.Show("Unknown commMode " + Convert.ToString(receivedByte[0]) + " detected"); } commMode = Convert.ToInt16(receivedByte[0]); }