Example #1
0
        private void bSendHEX_Click(object sender, EventArgs e)
        {
            if (eChar.Text.Length < 1)
            {
                return;
            }

            int buff_len = 1;

            //if (cbCR.Checked) buff_len++;
            //if (cbLF.Checked) buff_len++;
            byte[] buff  = new byte[buff_len];
            int    bytes = 0;

            // fill buffer
            //for (int i = 0; i < eSend.Text.Length; i++)
            //{
            buff[0] = Convert.ToByte(eChar.Text, 16);
            bytes++;
            //}

            //if (cbCR.Checked) buff[bytes++] = 0x0a;
            //if (cbLF.Checked) buff[bytes++] = 0x0d;

            if (!Port1.IsOpen)
            {
                return;
            }
            Port1.Write(buff, 0, bytes);
            //eSend.Clear();
        }
Example #2
0
        private void bSend_Click(object sender, EventArgs e)
        {
            if ((eSend.Text.Length < 1) && (!cbCR.Checked) && (!cbLF.Checked))
            {
                return;
            }

            int buff_len = eSend.Text.Length;

            if (cbCR.Checked)
            {
                buff_len++;
            }
            if (cbLF.Checked)
            {
                buff_len++;
            }
            byte[] buff  = new byte[buff_len];
            int    bytes = 0;

            if (cbAddSent.Checked)
            {
                eCon.AppendText(Environment.NewLine + "---- SENT: " + (eSend.Text.Length > 0 ? eSend.Text + " (Len=" + eSend.Text.Length.ToString() + ") " : "") + (cbCR.Checked ? "[0x0d=CR]" : "") + (cbLF.Checked ? "[0x0a=LF]" : "") + Environment.NewLine);
            }


            // fill buffer
            if (eSend.Text.Length > 0)
            {
                for (int i = 0; i < eSend.Text.Length; i++)
                {
                    buff[i] = Convert.ToByte(eSend.Text[i]);
                    bytes++;
                }
            }

            if (cbCR.Checked)
            {
                buff[bytes++] = 0x0d;
            }
            if (cbLF.Checked)
            {
                buff[bytes++] = 0x0a;
            }

            if (!Port1.IsOpen)
            {
                eCon.AppendText(Environment.NewLine + "!!!!!!!!!!!!!! Port closed. !!!!!!!!!!!!!!!!!!" + Environment.NewLine);
                return;
            }

            try
            {
                Port1.Write(buff, 0, bytes);
                eSend.Clear();
            } catch (Exception er) {
                AddConText(Environment.NewLine + "!!!!!!!! Unable to write to port " + Port1.PortName + ". Error: " + er.ToString() + " !!!!!!!!!!!!!!" + Environment.NewLine);
            }

            eCount.Text = (eSend.Text.Length + (cbCR.Checked ? 1 : 0) + (cbLF.Checked ? 1 : 0)).ToString();
        }