Example #1
0
        private void OnCmdReceived(object sender, SerialDataReceivedEventArgs e)
        {
            context.Post((o) =>
            {
                Thread.Sleep(10);
                byte[] b = new byte[com.BytesToRead];
                com.Read(b, 0, b.Count());

                for (int i = 0; i < b.Count(); i++)
                {
                    txt_Serial_Received.AppendText((b[i]).ToString("X2"));
                    txt_Serial_Received.AppendText(" ");
                    if (i == b.Count() - 1)
                    {
                        txt_Serial_Received.AppendText("\r\n\r\n");
                    }
                }
                for (int i = 0; i < listBox1.Items.Count / 2; i++)
                {
                    string j = listBox1.Items[i * 2].ToString();
                    j        = j.Substring(4, j.Length - 4);
                    byte[] l = Cvt.HexStringToByteArray(j);
                    if (Cvt.ByteArrayEquals(l, b))
                    {
                        string k    = listBox1.Items[i * 2 + 1].ToString();
                        k           = k.Substring(4, k.Length - 4);
                        byte[] data = Cvt.HexStringToByteArray(k);
                        com.Write(data, 0, data.Length);
                        break;
                    }
                }
            }, null);
        }
Example #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     byte[] data = Cvt.HexStringToByteArray(txt_Serial_Send.Text);
     com.Write(data, 0, data.Length);
 }