Exemplo n.º 1
0
        private void uartWriteButton_Click(object sender, EventArgs e)
        {
            string inputStr = uartComboBox.Text;

            string[] strAry = null;
            int      len    = 0;

            string ipstr    = ipAddrTextBox.Text;
            string gpibAddr = "inst29";

            string resp;

            byte[] byteAry1 = null;

            if (inputStr == string.Empty)
            {
                return;
            }

            if (inputStr.Contains(@"/"))
            {
                // this is in hex
                strAry = inputStr.Split(new char[] { '/' });
            }
            else
            {
                if (!newLineCheckBox1.Checked)
                {
                    Regex regex = new Regex(@"\\n");
                    Match m     = regex.Match(inputStr);
                    if (m.Success)
                    {
                        byteAry1 = Encoding.ASCII.GetBytes(inputStr.ToCharArray(), 0, inputStr.Length - 1);
                        byteAry1[inputStr.Length - 2] = 0x0a; // putting newline in ascii
                    }
                    else
                    {
                        byteAry1 = Encoding.ASCII.GetBytes(inputStr);
                    }
                }
                else
                {
                    // check box is check, add new line to the input string
                    inputStr = inputStr + Environment.NewLine;
                    byteAry1 = Encoding.ASCII.GetBytes(inputStr);
                }

                len = byteAry1.Length;
                //byte[] newline = Encoding.ASCII.GetBytes(Environment.NewLine);
            }

            VXI11Class remote_inst = new VXI11Class(gpibAddr, ipstr);

            remote_inst.uartWriteBytes(len, byteAry1);
            remote_inst.close();
            uartRespTextBox.AppendText("uart write:");
            uartRespTextBox.AppendText(inputStr);
        }