Beispiel #1
0
        private void uartQueryButton_Click(object sender, EventArgs e)
        {
            string inputStr = uartComboBox.Text;

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

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

            byte[] resp     = null;
            byte[] byteAry1 = null;
            string respStr  = string.Empty;

            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.TimeOut = 15000;//Convert.ToInt32(byteTimeoutComboBox.Text) / 1000 + 500;
            Console.WriteLine(remote_inst.TimeOut);
            remote_inst.BufferSize = 40000;
            remote_inst.uartQueryBytes(len, byteAry1, ref resp);



            string readstring = System.Text.Encoding.ASCII.GetString(resp);

            Console.WriteLine(resp.Length);
            //Console.WriteLine(readstring);
            //uartTextBox.Text = readstring;
            double[] real64 = null;
            if (binDecode.Checked)
            {
                remote_inst.binaryToDouble64(resp, ref real64, swapBinOrder.Checked);
                if (real64 != null)
                {
                    readstring = "";
                    for (int kk = 0; kk < real64.Length; kk++)
                    {
                        if (kk > 0)
                        {
                            readstring += "," + Convert.ToString(real64[kk]);
                        }
                        else
                        {
                            readstring = Convert.ToString(real64[kk]);
                        }
                    }
                }
            }
            uartRespTextBox.AppendText(inputStr);
            uartRespTextBox.AppendText(readstring);
            remote_inst.close();
            uartComboBox.Items.Add(inputStr);
        }
Beispiel #2
0
        private void uartReadButton_Click(object sender, EventArgs e)
        {
            // Read is actually a special case of write, with inputstr length of zero
            string inputStr = string.Empty;

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

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

            byte[] resp     = null;
            byte[] byteAry1 = null;
            string respStr  = string.Empty;


            /*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; // this has to be zero
             *  //byte[] newline = Encoding.ASCII.GetBytes(Environment.NewLine);
             * }*/


            VXI11Class remote_inst = new VXI11Class(gpibAddr, ipstr);

            remote_inst.TimeOut = 15000;//Convert.ToInt32(byteTimeoutComboBox.Text) / 1000 + 500;
            Console.WriteLine(remote_inst.TimeOut);
            remote_inst.BufferSize = 40000;

            //remote_inst.uartReadBytes(ref resp);
            remote_inst.uartQueryBytes(0, null, ref resp);
            string readstring = System.Text.Encoding.ASCII.GetString(resp);

            Console.WriteLine(resp.Length);
            //Console.WriteLine(readstring);
            //uartTextBox.Text = readstring;
            double[] real64 = null;
            if (binDecode.Checked)
            {
                remote_inst.binaryToDouble64(resp, ref real64, swapBinOrder.Checked);
                if (real64 != null)
                {
                    readstring = "";
                    for (int kk = 0; kk < real64.Length; kk++)
                    {
                        if (kk > 0)
                        {
                            readstring += "," + Convert.ToString(real64[kk]);
                        }
                        else
                        {
                            readstring = Convert.ToString(real64[kk]);
                        }
                    }
                }
            }


            uartRespTextBox.AppendText(@"uart read:");
            uartRespTextBox.AppendText(readstring + "\r\n");
            remote_inst.close();
        }
Beispiel #3
0
        private void queryButton_Click(object sender, EventArgs e)
        {
            string ipstr    = ipAddrTextBox.Text;
            string gpibAddr = "inst" + gpibAddrTextBox.Text;
            string cmd      = commandComboBox.Text;


            Console.WriteLine(cmd);
            VXI11Class remote_inst = null;// new VXI11Class(gpibAddr, ipstr);

            //string resp = string.Empty;
            byte[] resp = null;
            try
            {
                remote_inst = new VXI11Class(gpibAddr, ipstr);

                /* if (LockDeviceCheckBox.Checked)
                 * {
                 *  // device lock is requested, min 1000 ms is chosen for demo
                 *  //
                 *  if (Convert.ToInt32(timeOutTextBox.Text) >= 1000)
                 *  {
                 *      //resp = remote_inst.query(cmd, Convert.ToInt32(timeOutTextBox.Text));
                 *     resp = remote_inst.queryByte(cmd, Convert.ToInt32(timeOutTextBox.Text));
                 *  }
                 * }
                 * else
                 * {
                 *  //resp = remote_inst.query(cmd);
                 *  resp = remote_inst.queryByte(cmd);
                 * }*/
                resp = remote_inst.queryByte(cmd);
            }
            catch (Exception ex)
            {
                //resp = ex.ErrorCode.ToString();
                //resp = ex.Message;
                throw ex;
            }

            string readstring = System.Text.Encoding.ASCII.GetString(resp);

            //Console.WriteLine(readstring);
            byte[] bytesAry = resp;// System.Text.Encoding.ASCII.GetBytes(resp);//BitConverter.GetBytes(resp.ToCharArray());


            double[] real64 = null;
            if (binDecode.Checked)
            {
                remote_inst.binaryToDouble64(bytesAry, ref real64, swapBinOrder.Checked);
                if (real64 != null)
                {
                    readstring = "";
                    for (int kk = 0; kk < real64.Length; kk++)
                    {
                        if (kk > 0)
                        {
                            readstring += "," + Convert.ToString(real64[kk]);
                        }
                        else
                        {
                            readstring = Convert.ToString(real64[kk]);
                        }
                    }
                }
            }
            responseTextBox.Text += readstring + "\r\n\r\n";
            remote_inst.close();
            commandComboBox.Items.Add(cmd);
        }