private void button5_Click(object sender, EventArgs e) { //Enroll string end = "\n"; byte[] endBYTE = Encoding.ASCII.GetBytes(end); char startCode = '#'; byte startCodeByte = Convert.ToByte(startCode); byte[] StoreFingerprint = { startCodeByte, 0x05 }; byte[] FinalBytes = Combine(StoreFingerprint, endBYTE); port.Write(FinalBytes, 0, 4); System.Threading.Thread.Sleep(5000); int intBuffer; intBuffer = port.BytesToRead; byte[] byteBuffer = new byte[intBuffer]; port.Read(byteBuffer, 0, intBuffer); string str = System.Text.Encoding.Default.GetString(byteBuffer); if (str == "1\n") { MessageBox.Show("Fingerprint Enrollment Success"); } else { MessageBox.Show("Fingerprint Enrollment Failed"); } }
private void checkBox1_CheckedChanged(object sender, EventArgs e) { //Red LED if (isConnected) { if (checkBox1.Checked) { char startCode = '#'; byte startCodeByte = Convert.ToByte(startCode); char endCode = '\n'; byte endCodeByte = Convert.ToByte(endCode); byte[] LEDRON = { startCodeByte, 0x00, 0x01, 1, endCodeByte }; port.Write(LEDRON, 0, 5); } else { char startCode = '#'; byte startCodeByte = Convert.ToByte(startCode); char endCode = '\n'; byte endCodeByte = Convert.ToByte(endCode); byte[] LEDROF = { startCodeByte, 0x00, 0x01, 0, endCodeByte }; port.Write(LEDROF, 0, 5); } } }
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]); }