Ejemplo n.º 1
0
        public void Updata(byte[] ReceiveData)
        {
            string Header = string.Format("[{0}]Receive:<- ", DateTime.Now.ToString("hh:mm:ss.fff"));

            Receive_DataTextBox.AppendText(Header);
            if (Show_HexCheckBox.Checked == false)
            {
                Receive_DataTextBox.AppendText(System.Text.Encoding.ASCII.GetString(ReceiveData));
            }
            else
            {
                foreach (byte b in ReceiveData)
                {
                    Receive_DataTextBox.AppendText(b.ToString("X2"));
                    Receive_DataTextBox.AppendText(" ");
                }
            }
            Receive_DataTextBox.AppendText("\r\n");
        }
Ejemplo n.º 2
0
 private void button1_Click(object sender, EventArgs e)
 {
     Receive_DataTextBox.Clear();
 }
Ejemplo n.º 3
0
        private void Send_Data_Click(object sender, EventArgs e)
        {
            if (!com.IsOpen)
            {
                return;
            }
            Button but       = sender as Button;
            string Send_Data = null;
            bool   hexsend   = false;

            switch (Convert.ToInt32(but.Tag))
            {
            case 1:
                Send_Data = Data_TextBox1.Text;
                if (Hex1.Checked)
                {
                    hexsend = true;
                }
                break;

            case 2:
                Send_Data = Data_TextBox2.Text;
                if (Hex2.Checked)
                {
                    hexsend = true;
                }
                break;

            case 3:
                Send_Data = Data_TextBox3.Text;
                if (Hex3.Checked)
                {
                    hexsend = true;
                }
                break;

            case 4:
                Send_Data = Data_TextBox4.Text;
                if (Hex4.Checked)
                {
                    hexsend = true;
                }
                break;

            case 5:
                Send_Data = Data_TextBox5.Text;
                if (Hex5.Checked)
                {
                    hexsend = true;
                }
                break;
            }

            if (Send_Data != null && Send_Data != "")
            {
                string Header = string.Format("[{0}]Send:-> ", DateTime.Now.ToString("hh:mm:ss.fff"));
                Receive_DataTextBox.AppendText(Header + Send_Data + "\r\n");

                if (hexsend == true)
                {
                    string[]    str   = Send_Data.Trim().Split(' ');
                    List <byte> bytes = new List <byte>();
                    foreach (string st in str)
                    {
                        for (int n = 0; n < st.Length; n += 2)
                        {
                            byte a = byte.Parse(st.Substring(n, 2), System.Globalization.NumberStyles.HexNumber);
                            bytes.Add(a);
                        }
                    }
                    byte[] bytearr = bytes.ToArray();
                    com.WritePort(bytearr, 0, bytearr.Length);
                }
                else
                {
                    com.serialPort.WriteLine(Send_Data);
                }
            }
        }