Exemplo n.º 1
0
        private void trackBar4_Scroll(object sender, EventArgs e)
        {
            string str = string.Empty;

            comboBox4.Text = trackBar4.Value.ToString();
            commProtHelp_.SendCmd(button4.Text, ShujuChuli.StrToHex(comboBox4.Text), out str);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 将字符串转换成Hex字符串
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string StrToHex(string str)//40000 40000 20 255 255 65535
        {
            string strReturn = "";
            //countPram>0 表示有多个参数存在
            int countPram = Regex.Matches(str, @" ").Count; //利用正则表达式

            string[]  strPram = new string[countPram + 1];  //创建一个数组保存参数数据
            ArrayList lt      = new ArrayList();            //存放空格出现的位置

            if (countPram > 0)
            {
                int index = 0;
                foreach (Char ch in str)
                {
                    if (ch == ' ')
                    {
                        lt.Add(index);
                    }
                    index++;
                }


                strPram[0] = str.Substring(0, Convert.ToInt32(lt[0].ToString()));
                for (int i = 1; i < countPram + 1; i++)
                {
                    if (i < countPram)
                    {
                        strPram[i] = str.Substring(Convert.ToInt32(lt[i - 1].ToString()) + 1, Convert.ToInt32(lt[i].ToString()) - Convert.ToInt32(lt[i - 1].ToString()) - 1);
                    }
                    else
                    {
                        strPram[i] = str.Substring(Convert.ToInt32(lt[i - 1].ToString()) + 1, str.Length - Convert.ToInt32(lt[i - 1].ToString()) - 1);
                    }
                }
                //for (int i = 0; i < strPram.Length; i++)
                //{
                //  strPram[i]=ShujuChuli.StrToGaoDiWei(strPram[i]);
                //  strReturn += strPram[i]+" ";
                //}
                #region  针对trt机械手做特殊处理
                strPram[0] = ShujuChuli.StrToGaoDiWei(strPram[0]);
                strPram[1] = ShujuChuli.StrToGaoDiWei(strPram[1]);
                strPram[2] = ShujuChuli.StrToHex(strPram[2]);
                strPram[3] = ShujuChuli.StrToHex(strPram[3]);
                strPram[4] = ShujuChuli.StrToHex(strPram[4]);
                strPram[5] = ShujuChuli.StrToGaoDiWei(strPram[5]);
                strReturn  = strPram[0] + " " + strPram[1] + " " + strPram[2] + " " + strPram[3] + " " + strPram[4] + " " + strPram[5];
                #endregion
            }
            else
            {
                //strReturn=Convert.ToString(Convert.ToInt32(str), 16);
                strReturn = Convert.ToInt32(str).ToString("X2");
            }
            //可以判断是否有空格,是否是多个参数



            return(strReturn);
        }
Exemplo n.º 3
0
        private void button4_Click(object sender, EventArgs e)
        {
            string str = string.Empty;

            trackBar4.Value = Convert.ToInt32(comboBox4.Text);

            commProtHelp_.SendCmd(button4.Text, ShujuChuli.StrToHex(comboBox4.Text), out str);
        }
Exemplo n.º 4
0
        private void button2_Click(object sender, EventArgs e)
        {
            string str = string.Empty;

            commProtHelp_.SendCmd(button2.Text, ShujuChuli.StrToHex(comboBox2.Text), out str);
            //txtXianShi.AppendText(System.DateTime.Now + "   " + button2.Text + "---->" + str + "\r\n");
            trackBar2.Value = Convert.ToInt32(comboBox2.Text);
        }
Exemplo n.º 5
0
        private void trackBar3_Scroll(object sender, EventArgs e)
        {
            string str = string.Empty;

            commProtHelp_.SendCmd(button4.Text, ShujuChuli.StrToHex(trackBar3.Value.ToString()), out str);
            //txtXianShi.AppendText(System.DateTime.Now + "   " + button4.Text + "---->" + str + "\r\n");
            comboBox4.Text = trackBar3.Value.ToString();
        }
Exemplo n.º 6
0
        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            string str = string.Empty;

            Console.WriteLine(trackBar1.Value.ToString());
            comboBox1.Text = trackBar1.Value.ToString();

            commProtHelp_.SendCmd(button1.Text, ShujuChuli.StrToHex(comboBox1.Text) + " " + ShujuChuli.StrToHex(comboBox1.Text) + " " + ShujuChuli.StrToHex(comboBox1.Text), out str);
        }