コード例 #1
0
ファイル: Form7.cs プロジェクト: Andrew-Gan/ece-undergrad
        private async void button4_Click(object sender, EventArgs e)
        {
            if (isConnected)
            {
                //Store Credential	    { startCodeByte, 0x04, MsgSize, [DisplayName,UserName,url,Password,], endCodeByte};
                //Facebook,[email protected],www.facebook.com,Boomer1950!,

                string MSG         = (textBox1.Text).Trim();
                string end         = "\n";
                int    MSGsize     = MSG.Length;
                byte[] MSGByte     = Encoding.ASCII.GetBytes(MSG);
                byte[] endBYTE     = Encoding.ASCII.GetBytes(end);
                byte   MSGsizeByte = Convert.ToByte(MSGsize);

                byte Endbyte = Convert.ToByte('\n');

                char startCode     = '#';
                byte startCodeByte = Convert.ToByte(startCode);

                byte[] StoreCred = { startCodeByte, 0x04, MSGsizeByte };

                byte[] newBytes   = Combine(StoreCred, MSGByte);
                byte[] FinalBytes = Combine(newBytes, endBYTE);

                int freq = MSG.Split(',').Length - 1;
                if (freq == 4)
                {
                    port.Write(FinalBytes, 0, MSGsize + 4);
                    MessageBox.Show("Please Scan Fingerprint");

                    string str = port.ReadLine();

                    if (str == "1")
                    {
                        MessageBox.Show("Credential Stored");
                        textBox1.Clear();
                    }
                    else if (str == "0")
                    {
                        MessageBox.Show("Operation Failure");
                        textBox1.Text = str;
                    }
                }
                else
                {
                    MessageBox.Show("Incorrect Format. Try Again with 'WebsiteID,Email/Username,WesbiteURL,Password,'.");
                }
            }
        }
コード例 #2
0
ファイル: Form7.cs プロジェクト: Andrew-Gan/ece-undergrad
        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]);
        }
コード例 #3
0
        private void button4_Click(object sender, EventArgs e)
        {
            //Clear fingerprint and Deivce
            DialogResult dialogResult = MessageBox.Show("This will clear the device. Do you wish to countinue?", "Warning", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                string end           = "\n";
                byte[] endBYTE       = Encoding.ASCII.GetBytes(end);
                char   startCode     = '#';
                byte   startCodeByte = Convert.ToByte(startCode);

                byte[] StoreFingerprint = { startCodeByte, 0x07 };

                byte[] FinalBytes = Combine(StoreFingerprint, endBYTE);

                port.Write(FinalBytes, 0, FinalBytes.Length);
                MessageBox.Show("Please Scan Fingerprint");

                string str = port.ReadLine();
                if (str == "1")
                {
                    MessageBox.Show("Device Clear Success. Please Restart Device and Scan New Fingerprint.");
                }
                else if (str == "0")
                {
                    MessageBox.Show("Device Clear Failure");
                }
            }
            else if (dialogResult == DialogResult.No)
            {
                port.Close();
                this.Close();
            }
        }