#define SHOW_THE_SIGNAL
//#define JUST_SHOW_FAIL
#define RUN_AFTER_LOAD
//#define START_BY_BTN
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using QTInterface;
using MoonControl;
using System.Threading;
using QTIOBoardControl;
using Common;


namespace HollywoodQT
{
    public partial class Form1 : Form
    {
        private const bool ON = false;
        private const bool OFF = true;

        private QT m_qt = null;
        private QTIOBoard m_IoBoard;
        private QTIOBoard m_IoBoard_2;

        private MoonMotor m_MoonMotorRTU;
        private MoonMotor m_GrayMotorRTU;
        private MoonMotor m_doorMotorRTU;

        //private MoonMotorTCP m_MoonMotorTCP;/*P1.1阶段更换电机未禾川电机 取消此对象*/
        private MoonMotorTCP m_GrayMotorTCP;
        private MoonMotorTCP m_doorMotorTCP;

        private MoonMotor m_IPDMotor;
        private Thread m_Thread;
        private bool m_start = false;
        private bool m_loop = false;
        private int loop_count = 0;

        public Form1()
        {
            InitializeComponent();
        }

        public void setLabelBkColor(Func<bool> f,ref Label lab)
        {
            if (f())
            {
                lab.BackColor = Color.Green;
            }
            else
            {
                lab.BackColor = Color.White;
            }
        }

        public void setIPDtxt(Func<byte,int> f, byte slave, TextBox txt)
        {
            Invoke(new Action(() =>
            {
                txt.Text = f(slave).ToString();
            }));
        }

        public void get_io_status()
        {
            m_start = true;
            while (m_start)
            {
                if (m_IoBoard != null&&m_IoBoard_2 != null)
                {
                    //setLabelBkColor(m_IoBoard.SafeDoor, ref SafeDoor);
                    setLabelBkColor(m_IoBoard.Start, ref Start);
                    setLabelBkColor(m_IoBoard.E_Stop, ref E_Stop);
                    setLabelBkColor(m_IoBoard.Reset, ref Reset);

                    setLabelBkColor(m_IoBoard.PowerTest, ref PowerTest);
                    setLabelBkColor(m_IoBoard.PowerOrigin, ref PowerOrigin);
                    setLabelBkColor(m_IoBoard.VolAddTest, ref VolplusTest);
                    setLabelBkColor(m_IoBoard.VolAddOrigin, ref VolplusOrigin);
                    setLabelBkColor(m_IoBoard.VolReduTest, ref VolRedTest);
                    setLabelBkColor(m_IoBoard.VolReduOrigin, ref VolRedOrigin);
                    setLabelBkColor(m_IoBoard.PogoOrigin, ref PogoOrigin);
                    setLabelBkColor(m_IoBoard.PogoTest, ref PogoTest);
                    //setLabelBkColor(m_IoBoard.CoverClose, ref CoverBoard);
                    //setLabelBkColor(m_IoBoard.CoverOpen, ref CoverBoardOpen);
                    setLabelBkColor(m_IoBoard.PoweroutOrigin, ref PoweroutOrigin);
                    setLabelBkColor(m_IoBoard.PowerOutTest, ref PowerOutTest);

                    setLabelBkColor(m_IoBoard_2.IPDOrigin, ref IPDOrigin);
                    setLabelBkColor(m_IoBoard_2.IPDTest, ref IPDTest);
                    setLabelBkColor(m_IoBoard_2.GrayCardOrigin, ref GrayCardOrigin);
                    setLabelBkColor(m_IoBoard_2.GrayCardTest, ref GrayCardTest);

                    /*2022-08-17
                     增加夹爪气缸(4个)、产品到位(2个)感应器
                     */
                    setLabelBkColor(m_IoBoard.CheckDUT_1, ref lbl_dutON1);
                    setLabelBkColor(m_IoBoard_2.CheckDUT_2, ref lbl_dutON2);
                    setLabelBkColor(m_IoBoard.LeftCover_ON, ref lbl_leftCoverON);
                    setLabelBkColor(m_IoBoard_2.LeftCover_OFF, ref lbl_leftCoverOFF);
                    setLabelBkColor(m_IoBoard_2.RightCover_ON, ref lbl_rightCoverON);
                    setLabelBkColor(m_IoBoard_2.RightCover_OFF, ref lbl_rightCoverOFF);
                    setLabelBkColor(m_IoBoard_2.RGBTest, ref lbl_RGBcly);


                    setLabelBkColor(m_IoBoard_2.Check_safe_raster, ref lbl_GS);

                    //setLabelBkColor(m_IoBoard.SDHorizOrig, ref SDCardHBack);
                    //setLabelBkColor(m_IoBoard.SDHorizTest, ref SDCardHInsertion);
                    //setLabelBkColor(m_IoBoard.SDVertOrigin, ref SDCardVBack);
                    //setLabelBkColor(m_IoBoard.SDVertTest, ref SDCardVInsertion);


                    //setLabelBkColor(m_IoBoard_2.TypeCOrigin, ref TypeOrigin);
                    //setLabelBkColor(m_IoBoard_2.TypeCTest, ref TypeCTest);

                    setIPDtxt(m_IPDMotor.GetCurrentSpeed, m_qt.m_IPDWheelSlave, txt_motor);
                    setIPDtxt(m_IPDMotor.GetmotorSpeed, m_qt.m_IPDWheelSlave, txt_motorspeed);

                    setIPDtxt(m_IPDMotor.GetCurrentSpeed, m_qt.m_headphone_slave, txt_Speed_Audio);
                    setIPDtxt(m_IPDMotor.GetmotorSpeed, m_qt.m_headphone_slave, txt_SpeedN_Audio);

                    if (dt_Positive != null)
                    {
                        string[] str = { txt_Speed_Audio.Text, txt_SpeedN_Audio.Text };
                        dt_Positive.Rows.Add(str);
                    }
                }
                Thread.Sleep(80);
            }
        }

        /*创建一个表 用于记录耳机点击点动时的扭矩变化，速度变化*/
        DataTable dt_Positive;

        private void Form1_Load(object sender, EventArgs e)
        {
            m_qt = new QT();

            this.txt_grayhome.Text = m_qt.Gray_Home.ToString();
            this.txt_doorhome.Text = m_qt.Door_Home.ToString();
            this.txt_gray30.Text = m_qt.Prox_Pos13mm.ToString();
            this.txt_gray40.Text = m_qt.Prox_Pos20mm.ToString();
            this.txt_gray50.Text = m_qt.Prox_Pos30mm.ToString();
            this.txt_Brow_gray13.Text = m_qt.Cap_Pos13mm.ToString();
            this.txt_Brow_gray20.Text = m_qt.Cap_Pos20mm.ToString();
            this.txt_Brow_gray30.Text = m_qt.Cap_Pos30mm.ToString();
            this.txt_door_work.Text = m_qt.DoorWorkPostion.ToString();
            this.txt_audio.Text = m_qt.Headphone_pos.ToString();
            this.txt_ReversingRotation.Text = m_qt.Motor_ReversingRotation.ToString();
            this.txt_PositiveRotation.Text = m_qt.Motor_PositiveRotation.ToString();
            this.txt_Position.Text = m_qt.Motor_Position.ToString();
            this.txt_StopSpeed.Text = m_qt.Motor_StoptSpeed.ToString();
            this.txt_IPD_TimeOut.Text = m_qt.Motor_IPD_TimeOut.ToString();
            this.Torque_Range.Text = m_qt.Torque_Range.ToString();
            this.txt_Max_count.Text = m_qt.Max_count.ToString();
            this.txt_Sample_length.Text = m_qt.Sample_length.ToString();
            this.txt_Sample_range.Text = m_qt.Sample_range.ToString();

            /*AudioMotor Par*/
            this.txt_PositiveRotation_Audio.Text = m_qt.Headphone_acspeed.ToString();
            this.txt_ReversingRotation_Audio.Text = m_qt.Headphone_respeed.ToString();
            this.txt_Position_Audio.Text = m_qt.Headphone_pos.ToString();
            this.txt_Position_Audio_re.Text = m_qt.Headphone_pos_re.ToString();
            this.txt_StopSpeed_Audio.Text = m_qt.Headphone_HeadStopSeepd.ToString();
            this.txt_OutTime_Audio.Text = m_qt.Headphone_HeadTimeOut.ToString();
            this.txt_Range1_Audio.Text = m_qt.Headphone_HeadStopRange_1.ToString();
            this.txt_Range2_Audio.Text = m_qt.Headphone_HeadStopRange_2.ToString();
            this.txt_Speed_Audio.Text = m_qt.Headphone_HeadStopSeepd.ToString();
            this.txt_HomeTime_Audio.Text = m_qt.Headphone_HeadHomeTime.ToString();

            /*RGB_cal*/
            txt_led_r.Text = m_qt.Get_RGB_value("RGB_power_cal", "r");
            txt_led_g.Text = m_qt.Get_RGB_value("RGB_power_cal", "g");
            txt_led_b.Text = m_qt.Get_RGB_value("RGB_power_cal", "b");
            txt_power_r.Text = m_qt.Get_RGB_value("RGB_status_cal", "r");
            txt_power_g.Text = m_qt.Get_RGB_value("RGB_status_cal", "g");
            txt_power_b.Text = m_qt.Get_RGB_value("RGB_status_cal", "b");

            if (m_qt.Init(true))
            {
                m_IoBoard = m_qt.IoBoard;
                m_IoBoard_2 = m_qt.IoBoard_2;
                m_MoonMotorRTU = m_qt.MoonMotorRTU;
                m_GrayMotorRTU = m_qt.GrayMoonMotorRTU;
                m_doorMotorRTU = m_qt.MoonDoorRTU;

                //m_MoonMotorTCP = m_qt.MoonMotorTCP;/*P1.1阶段更换电机未禾川电机 取消此对象*/
                m_GrayMotorTCP = m_qt.GrayMoonMotorTCP;
                m_doorMotorTCP = m_qt.MoonDoorTCP;

                m_IPDMotor = m_qt.MoonIPDWheel;

                StartThread();
                

//#if (!SHOW_THE_SIGNAL)
//                StartThread();
//#endif
//#if (START_BY_BTN)
//                Thread startThread = new Thread(StartBtnCheckThread);
//                startThread.Start();
//#endif
            }
            else
            {
                MessageBox.Show("qt init fail#############");
                Console.WriteLine("qt init fail#############");
                FileWriter.WriteLog("qt init fail#############");
            }
        }
        private void StartBtnCheckThread()
        {
            bool res = m_qt.CheckedStart();
            while(true)
            {
                if (res)
                {
                    loop();
                    break;
                }
                res = m_qt.CheckedStart();
                Thread.Sleep(1000);
                Console.WriteLine("check start res == " + res);
            }
        }
        private void StartThread()
        {
            m_Thread = new Thread(get_io_status);
            m_Thread.Start();
        }

        private void StopThread()
        {
            m_start = false;
            try
            {
                if (m_Thread != null)
                {
                    m_Thread.Abort();
                }

            }
            catch (Exception)
            {
            }
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
        }

        private void button2_Click(object sender, EventArgs e)//audio motor
        {
            int i = 10;
            int.TryParse(txt_audio.Text.ToString().Trim(), out i);
            m_qt.AudioMotor2(false,i);


            //if (m_qt.m_devices_id == "2")
            //{
            //    if (m_MoonMotorRTU == null)
            //    {
            //        MessageBox.Show("请先open");
            //        return;
            //    }
            //}
            //if (m_qt.m_devices_id == "1")
            //{
            //    //if (m_MoonMotorTCP == null)
            //    //{
            //    //    MessageBox.Show("请先open");
            //    //    return;
            //    //}
            //}
            

            //int pos = 0;
            //ushort speed = 0, acspeed = 0, respeed = 0;
            //if (int.TryParse(this.txt_audio.Text, out pos))
            //{
            //    if(ushort.TryParse(txt_speed.Text,out speed))
            //    {
            //        if(ushort.TryParse(txt_acspeed.Text,out acspeed))
            //        {
            //            if(ushort.TryParse(txt_respeed.Text,out respeed))
            //            {
            //                if (m_MoonMotorRTU.RTU_MotorRun(m_qt.m_headphone_slave, pos) == false)
            //                {
            //                    return;
            //                }


            //                ////if (m_qt.m_devices_id == "2")
            //                ////{
            //                ////    if (m_MoonMotorRTU.RTU_MotorRun(m_qt.m_headphone_slave, pos) == false)
            //                ////    {
            //                ////        return;
            //                ////    }
            //                ////}
            //                ////if (m_qt.m_devices_id == "1")
            //                ////{
            //                ////    //m_MoonMotorTCP.MoveLine(m_qt.m_headphone_slave, pos, speed, acspeed, respeed);
            //                ////}
                            
            //            }                        
            //        }                    
            //    }                
            //}
            //else
            //{
            //    MessageBox.Show("输入运动数据非法，请输入0-9组成的数据");
            //}

        }

        private void button3_Click(object sender, EventArgs e)
        {
            //m_MoonMotorTCP = new MoonMotorTCP("10.10.10.10", 502);
            //bool isopen = m_MoonMotorTCP.OpenPort();
            //if (isopen)
            //{
            //    button3.Enabled = false;
            //    MessageBox.Show("链接成功");
            //}
            //else
            //{
            //    MessageBox.Show("链接失败");
            //}
        }

        private void button4_Click(object sender, EventArgs e)
        {
            m_MoonMotorRTU.RTU_MotorGoHome(m_qt.m_headphone_slave);
            //if (m_qt.m_devices_id == "1")
            //{
            //    //if (m_MoonMotorTCP == null)
            //    //{
            //    //    MessageBox.Show("请先open");
            //    //    return;
            //    //}

            //    //m_MoonMotorTCP.SetMoonsHome(1);
            //}
            //if (m_qt.m_devices_id == "2")
            //{
            //    if (m_MoonMotorRTU == null)
            //    {
            //        MessageBox.Show("请先open");
            //        return;
            //    }
            //    if (m_MoonMotorRTU.RTU_MotorGoHome(m_qt.m_headphone_slave) == false)
            //    {
            //        return;
            //    }
            //}
            //else
            //{
            //    MessageBox.Show("设备ID号不对，请检查配置文件");
            //}
            
        }

        private void button5_Click(object sender, EventArgs e)
        {
            bool result =  m_IPDMotor.SetMoonsPosition(5, 0);       //将扭矩值设为百分之0

            Console.WriteLine("AudioMotor Stop : result"+result);

            //m_MoonMotorRTU.Motor_Stop(2);
            //if (m_qt.m_devices_id == "2")
            //{
            //    if (m_MoonMotorRTU == null)
            //    {
            //        MessageBox.Show("请先open");
            //        return;
            //    }
            //    m_MoonMotorRTU.Motor_Stop(2);
            //}
            //if (m_qt.m_devices_id == "1")
            //{
            //    //if (m_MoonMotorTCP == null)
            //    //{
            //    //    MessageBox.Show("请先open");
            //    //    return;
            //    //}
            //    //m_MoonMotorTCP.SetMoonsImmediatelyStop(1);
            //}
            
        }

        private void button6_Click(object sender, EventArgs e)
        {
            //if(m_qt.CheckedStart() == false)
            //{
            //    ErrLabel.Text = "CheckedStart fail";
            //}
            ShowMessage(m_qt.CheckedStart);
        }

        private void tabPage3_Click(object sender, EventArgs e)
        {

        }

        private void button7_Click(object sender, EventArgs e)
        {
            //if(m_qt.TypeCInsertion() == false)
            //{
            //   ErrLabel.Text = "TypeCInsertion fail";
            //}
            ShowMessage(m_qt.TypeCInsertion);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            //if(m_qt.AudioInsertion() == false)
            //{
            //   ErrLabel.Text = "AudioInsertion fail";
            //}
            ShowMessage(m_qt.AudioInsertion);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            //if(m_qt.AudioBack() == false)
            //{
            //   ErrLabel.Text = "AudioBack fail";
            //}
            ShowMessage(m_qt.AudioBack);
        }

        private void button10_Click(object sender, EventArgs e)
        {
            //if(m_qt.PowerButtonTest() == false)
            //{
            //   ErrLabel.Text = "PowerButtonTest fail";
            //}
            ShowMessage(m_qt.PowerButtonTest);
        }

        private void button11_Click(object sender, EventArgs e)
        {
            //if(m_qt.PowerButtonReset() == false)
            //{
            //   ErrLabel.Text = "PowerButtonReset fail";
            //}
            ShowMessage(m_qt.PowerButtonReset);
        }

        private void button12_Click(object sender, EventArgs e)
        {
            //if(m_qt.VolumeplusButtonTest() == false)
            //{
            //   ErrLabel.Text = "VolumeplusButtonTest fail" ;
            //}
            ShowMessage(m_qt.VolumeplusButtonTest);
        }

        private void button13_Click(object sender, EventArgs e)
        {
            //if(m_qt.VolumeplusButtonReset() == false)
            //{
            //   ErrLabel.Text = "VolumeplusButtonReset fail";
            //}
            ShowMessage(m_qt.VolumeplusButtonReset);
        }

        private void button14_Click(object sender, EventArgs e)
        {
            //if(m_qt.VolumeSubButtonTest() == false)
            //{
            //   ErrLabel.Text = "VolumeSubButtonTest fail" ;
            //}
            ShowMessage(m_qt.VolumeSubButtonTest);
        }

        private void button15_Click(object sender, EventArgs e)
        {
            //if(m_qt.VolumeSubButtonReset() == false)
            //{
            //   ErrLabel.Text = "VolumeSubButtonReset fail";
            //}
            ShowMessage(m_qt.VolumeSubButtonReset);
        }

        bool btn_16 = false;
        private void button16_Click(object sender, EventArgs e)
        {
            if (btn_16)
            {
                btn_16 = false;
                check_readRGB_Value.Checked = false;
            }
            else
            {
                Thread th = new Thread(read_left_rgb);
                th.IsBackground = true;
                th.Start();
                btn_16 = true;
            }
            
        }

        private void read_left_rgb()
        {
            var res = m_qt.LeftDisplayTest();

            while (check_readRGB_Value.Checked)
            {
                res = m_qt.LeftDisplayTest();
                this.Invoke(new EventHandler(delegate
                {
                    richTextBox1.AppendText("LeftDisplayTest:" + res[0].ToString() + "," + res[1].ToString() + "," + res[2].ToString() + System.Environment.NewLine + "\n");
                }));
                Thread.Sleep(10);
            }

            if (res == null)
            {
                this.Invoke(new EventHandler(delegate
                {
                    richTextBox1.AppendText("LeftDisplayTest" + " fail" + System.Environment.NewLine);
                }));
            }
            else
            {
                this.Invoke(new EventHandler(delegate
                {
                    richTextBox1.AppendText("LeftDisplayTest:" + res[0].ToString() + "," + res[1].ToString() + "," + res[2].ToString() + System.Environment.NewLine + "\n");
                }));
            }
        }

        private void button24_Click(object sender, EventArgs e)
        {
            //if(m_qt.Reset() == false)
            //{
            //   ErrLabel.Text = "Reset() fail";
            //}
            richTextBox1.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "开始复位");
            ShowMessage(m_qt.Reset);
            richTextBox1.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "复位结束");
        }

        bool btn_17 = false;
        private void button17_Click(object sender, EventArgs e)
        {
            if (btn_17)
            {
                btn_17 = false;
                check_readRGB_Value.Checked = false;
            }
            else
            {
                Thread th = new Thread(power_rgb);
                th.Start();
                btn_17 = true;
            }
        }

        private void power_rgb()
        {
            var datas = m_qt.PowerLedTest();
            while (check_readRGB_Value.Checked)
            {
                datas = m_qt.PowerLedTest();
                this.Invoke(new EventHandler(delegate
                {
                    richTextBox1.AppendText("PowerLedTest:" + datas[0].ToString() + "," + datas[1].ToString() + "," + datas[2].ToString() + System.Environment.NewLine + "\n");
                }
                                    ));
                Thread.Sleep(10);
            }
            if (datas == null)
            {
                this.Invoke(new EventHandler(delegate
                {
                    richTextBox1.AppendText("PowerLedTest" + " fail" + System.Environment.NewLine);
                }
                                    ));
            }
            else
            {
                this.Invoke(new EventHandler(delegate
                {
                    richTextBox1.AppendText("PowerLedTest:" + datas[0].ToString() + "," + datas[1].ToString() + "," + datas[2].ToString() + System.Environment.NewLine + "\n");
                }
                                    ));
            }
        }

        private void button18_Click(object sender, EventArgs e)
        {
            //if(m_qt.SDCardInsertion() == false)
            //{
            //    ErrLabel.Text = "SDCardInsertion fail";
            //}
            //ShowMessage(m_qt.SDCardInsertion);
        }

        private void button19_Click(object sender, EventArgs e)
        {
            //if(m_qt.SDCardBack() == false)
            //{
            //   ErrLabel.Text ="SDCardBack fail";
            //}
            //ShowMessage(m_qt.SDCardBack);
        }

        #region 鼻子
        private void button20_Click(object sender, EventArgs e)
        {
            //if(m_qt.ProxGrayCdTest500mm() == false)
            //{                
            //   ErrLabel.Text ="ProxGrayCdTest500mm() fail";
            //}
            ShowMessage(m_qt.ProxGrayCdTest500mm);
            string Command = "adb shell \"syncboss_test -f 202 -n 10 -t 100\"";
            string data = adb.Send_Command(Command);
            richTextBox1.AppendText("Test_Cray " + data + "\n");
        }

        private void button21_Click(object sender, EventArgs e)
        {
            //if(m_qt.ProxGrayCdTest30mm() == false)
            //{
            //   ErrLabel.Text ="ProxGrayCdTest30mm() fail";
            //}
            ShowMessage(m_qt.ProxGrayCdTest30mm);
            string Command = "adb shell \"syncboss_test -f 202 -n 10 -t 100\"";
            string data = adb.Send_Command(Command);
            richTextBox1.AppendText("Test_Cray " + data + "\n");
        }

        private void button22_Click(object sender, EventArgs e)
        {
            //if (m_qt.ProxGrayCdTest20mm() == false)
            //{
            //   ErrLabel.Text ="ProxGrayCdTest20mm() fail";
            //}
            ShowMessage(m_qt.ProxGrayCdTest20mm);
            string Command = "adb shell \"syncboss_test -f 202 -n 10 -t 100\"";
            string data = adb.Send_Command(Command);
            richTextBox1.AppendText("Test_Cray " + data + "\n");
        }

        private void button23_Click(object sender, EventArgs e)
        {
            //if (m_qt.ProxGrayCdTest13mm() == false)
            //{
            //   ErrLabel.Text = "ProxGrayCdTest13mm() fail";
            //}
            ShowMessage(m_qt.ProxGrayCdTest13mm);
            string Command = "adb shell \"syncboss_test -f 202 -n 10 -t 100\"";
            string data = adb.Send_Command(Command);
            richTextBox1.AppendText("Test_Cray " + data + "\n");
        }
        #endregion

        
        #region 眉毛

        private void button26_Click(object sender, EventArgs e)
        {
            ShowMessage(m_qt.CapGrayCdTest500mm);
            string Command = "adb shell \"syncboss_test -f 202 -n 10 -t 100\"";
            string data = adb.Send_Command(Command);
            richTextBox1.AppendText("Test_Cray " + data + "\n");
        }

        private void button5_Click_1(object sender, EventArgs e)
        {
            ShowMessage(m_qt.CapGrayCdTest13mm);
            string Command = "adb shell \"syncboss_test -f 202 -n 10 -t 100\"";
            string data = adb.Send_Command(Command);
            richTextBox1.AppendText("Test_Cray " + data + "\n");
        }

        private void button18_Click_1(object sender, EventArgs e)
        {
            ShowMessage(m_qt.CapGrayCdTest20mm);
            string Command = "adb shell \"syncboss_test -f 202 -n 10 -t 100\"";
            string data = adb.Send_Command(Command);
            richTextBox1.AppendText("Test_Cray " + data + "\n");
        }

        private void button19_Click_1(object sender, EventArgs e)
        {
            ShowMessage(m_qt.CapGrayCdTest30mm);
            string Command = "adb shell \"syncboss_test -f 202 -n 10 -t 100\"";
            string data = adb.Send_Command(Command);
            richTextBox1.AppendText("Test_Cray " + data + "\n");
        }

        #endregion

        private void GrayCdTestRest_Click(object sender, EventArgs e)
        {
            //if(m_qt.GrayCdTestRest() == false)
            //{
            //   ErrLabel.Text = "GrayCdTestRest() fail";
            //}
            ShowMessage(m_qt.GrayCdTestRest);
        }

        private void AudioInsertion_Click(object sender, EventArgs e)
        {

        }

        private void SafeDoor_Click(object sender, EventArgs e)
        {

        }
        private bool ShowMessage(Func<bool> f)
        {
            if (f())
            {
#if (!JUST_SHOW_FAIL)
                this.Invoke(new EventHandler(delegate
                    {
                        richTextBox1.AppendText(f.Method.Name + " successe" + System.Environment.NewLine);
                    }
                    ));
                //richTextBox1.AppendText(f.ToString() + " successe");
                //MessageBox.Show(f.ToString() + "successe");
#endif
                return true;
            }
            else
            {
                this.Invoke(new EventHandler(delegate
                    {
                        richTextBox1.AppendText(f.Method.Name + " fail" + System.Environment.NewLine);
                    }
                     ));
               
                //MessageBox.Show(f.ToString() + "fail");
                return false;
            }
        }

        private void SetMessage(string msg, bool status)
        {
            richTextBox1.AppendText(msg);
        }
        public bool make_sure_gray_in_test()
        {
            return true;
            bool res = true;
            m_IoBoard.GrayCardCylinder(ON);
            res = m_IoBoard.StatusCk(m_IoBoard.GrayCardTest, 20);

            if (res == false)
            {
                MessageBox.Show("Gray Card not in Test location");
                res = false;
            }
            return res;
        }
        private void Graymmove_Click(object sender, EventArgs e)
        {
            if (m_qt.m_devices_id == "1")
            {
                if (m_GrayMotorTCP == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }
            if (m_qt.m_devices_id == "2")
            {
                if (m_GrayMotorRTU == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }

            //上升时判断灰卡已伸出
            if (!make_sure_gray_in_test())
            {
                MessageBox.Show("灰卡伸出失败，停止上升");
                return;
            }

            int pos = 0;
            ushort speed = 0, acspeed = 0, respeed = 0;
            if (int.TryParse(this.txt_gray30.Text, out pos))
            {
                if (ushort.TryParse(txt_speed.Text, out speed))
                {
                    if (ushort.TryParse(txt_acspeed.Text, out acspeed))
                    {
                        if (ushort.TryParse(txt_respeed.Text, out respeed))
                        {
                            if (m_qt.m_devices_id == "1")
                            {
                                if (m_IoBoard_2.GrayCardCylinder(ON) == false)
                                {
                                    return;
                                }
                                if (m_IoBoard_2.StatusCk(m_IoBoard_2.GrayCardTest, 10) == false)
                                {
                                    return;
                                }
                                m_GrayMotorTCP.MoveLine(m_qt.m_gray_slave, pos, speed, acspeed, respeed);
                            }
                            else if (m_qt.m_devices_id == "2")
                            {
                                if (m_IoBoard_2.GrayCardCylinder(ON) == false)
                                {
                                    return;
                                }
                                if (m_IoBoard_2.StatusCk(m_IoBoard_2.GrayCardTest, 10) == false)
                                {
                                    return;
                                }
                                m_GrayMotorRTU.RTU_MotorRun(m_qt.m_gray_slave, pos);
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("输入运动数据非法，请输入0-9组成的数据");
            }
        }

        private void GraymStop_Click(object sender, EventArgs e)
        {
            if (m_qt.m_devices_id == "2")
            {
                if (m_GrayMotorRTU == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
                m_GrayMotorRTU.Motor_Stop(1);
            }
            if (m_qt.m_devices_id == "1")
            {
                if (m_GrayMotorTCP == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
                m_GrayMotorTCP.SetMoonsImmediatelyStop(1);
            }
        }
        
        private void GrayMhome_Click(object sender, EventArgs e)
        {
            if (m_qt.m_devices_id == "2")
            {
                if (m_GrayMotorRTU == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }

                if (make_sure_gray_in_test())
                {
                    m_GrayMotorRTU.RTU_MotorGoHome(m_qt.m_gray_slave);
                }
            }
            if (m_qt.m_devices_id == "1")
            {
                if (m_GrayMotorTCP == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }

                if(make_sure_gray_in_test())
                {
                     m_GrayMotorTCP.SetMoonsHome(1);
                }
            }
        }

        private void startBtn_Click(object sender, EventArgs e)
        {
            //            m_qt.IoBoard.TriColorGreen(false);
            m_qt.IoBoard.StartBtLight(ON);
        }

        private void resetBtn_Click(object sender, EventArgs e)
        {
            m_qt.IoBoard.RsetBtLight(ON);
        }

        private void statusRed_Click(object sender, EventArgs e)
        {
            m_qt.IoBoard.StatusLightRed(ON);
        }

        private void statusGreen_Click(object sender, EventArgs e)
        {
            m_qt.IoBoard.StatusLightGreen(ON);
        }

        private void powerBtn_Click(object sender, EventArgs e)
        {
            if (m_qt.PowerKeyTest() == false)
            { MessageBox.Show("PowerKeyTest fail"); }
            //m_qt.IoBoard.PowerCylinder(ON);
        }

        private void VolPlusBtn_Click(object sender, EventArgs e)
        {
            if (m_qt.VolumeplusButtonTest()==false)
            {
                MessageBox.Show("VolumeplusButtonTest fail");
            }
            //m_qt.IoBoard.VolAddCylinder(ON);
        }

        private void VolRedBtn_Click(object sender, EventArgs e)
        {
            if (m_qt.VolumeSubButtonTest() == false)
            {
                MessageBox.Show("VolumeSubButtonTest fail");
            }
            
            //m_qt.IoBoard.VolReduceCylinder(ON);
        }

        private void SDCardVerBtn_Click(object sender, EventArgs e)
        {
            //m_qt.IoBoard.SDVertCylinder(ON);
        }

        private void SDHeriBtn_Click(object sender, EventArgs e)
        {
            //bool res = m_qt.SDCardInsertion();

        //    m_qt.IoBoard.SDHorizCylinder(ON);
        }

        private void GrayBtn_Click(object sender, EventArgs e)
        {
            m_qt.IoBoard_2.GrayCardCylinder(ON);           
        }

        private void TypeCBtn_Click(object sender, EventArgs e)
        {
            m_qt.IoBoard_2.TypeCCylinder(ON);
        }

        private void startBtnOff_Click(object sender, EventArgs e)
        {
            m_qt.IoBoard.StartBtLight(OFF);
        }

        private void resetBtnOFF_Click(object sender, EventArgs e)
        {
            m_qt.IoBoard.RsetBtLight(OFF);
        }

        private void powerBtnOff_Click(object sender, EventArgs e)
        {
            m_qt.IoBoard.PowerCylinder(OFF);
        }

        private void VolPlusBtnOff_Click(object sender, EventArgs e)
        {
            
            m_qt.VolumeplusButtonReset();
            //m_qt.IoBoard.VolAddCylinder(OFF);
        }

        private void VolRedBtnOff_Click(object sender, EventArgs e)
        {
            m_qt.VolumeSubButtonReset();
            //m_qt.IoBoard.VolReduceCylinder(OFF);
        }

        private void GrayBtnOff_Click(object sender, EventArgs e)
        {
            //if (m_qt.m_devices_id == "2")
            //{
            //    if (m_GrayMotorRTU == null)
            //    {
            //        MessageBox.Show("请先open");
            //        return;
            //    }

            //    if (make_sure_gray_in_test())
            //    {
            //        m_GrayMotorRTU.RTU_MotorGoHome(m_qt.m_gray_slave);
            //    }
            //    else
            //    {
            //        return;
            //    }
            //}
            //else if (m_qt.m_devices_id == "1")
            //{
            //    if (m_GrayMotorTCP == null)
            //    {
            //        MessageBox.Show("请先open");
            //        return;
            //    }

            //    if (make_sure_gray_in_test())
            //    {
            //        if (m_GrayMotorTCP.SetMoonsHome(1) == false)
            //        {
            //            return;
            //        }
            //    }
            //    else 
            //    {
            //        return;
            //    }
            //}
            //else
            //{
            //    return;
            //}
            m_qt.GrayCdTestRest();
            //bool res = m_qt.GrayMoonMotor.MoveLine(1, 0, 100, 100, 100);
            //if (res == false)
            //{
            //    MessageBox.Show("GrayMoonMotor Move to 0 fail");
            //}
            //else
            //{
            //    m_qt.IoBoard.GrayCardCylinder(OFF);
            //}            
        }

        private void TypeCBtnOff_Click(object sender, EventArgs e)
        {
            m_qt.IoBoard.TypeCCylinder(OFF);
        }

        private void PogoBtn_Click(object sender, EventArgs e)
        {
            m_qt.PogoCylinderTest();
            //m_qt.IoBoard.PogoCylinder(ON);
        }

        private void PogoBtnOff_Click(object sender, EventArgs e)
        {
            m_qt.PogoCylinderReset();
            //m_qt.IoBoard.PogoCylinder(OFF);
        }

        private void IPDBtn_Click(object sender, EventArgs e)
        {
            m_qt.IPDCylinderTest();
            //m_qt.IoBoard_2.IPDCCylinder(ON);
        }

        private void IPDBtnOff_Click(object sender, EventArgs e)
        {
            m_qt.IPDCylinderReset();
            //m_qt.IoBoard_2.IPDCCylinder(OFF);
        }

        private void SDHeriBtnOff_Click(object sender, EventArgs e)
        {
            //m_qt.IoBoard.SDHorizCylinder(OFF);
        }

        private void SDCardVerBtnOff_Click(object sender, EventArgs e)
        {
            //m_qt.IoBoard.SDVertCylinder(OFF);
        }

        private void message_show_Click(object sender, EventArgs e)
        {

        }
        public void show_fail_message(string str)
        {
            message_show.Text = str;
        }

        private void button6_Click_1(object sender, EventArgs e)
        {
            //int pos = 0;
            //ushort speed = 100;
            //while(true)
            //{
            //    if (m_MoonMotorTCP == null)
            //    {
            //        MessageBox.Show("请先open");
            //        return;
            //    }
            //    ushort acspeed = 0, respeed = 0;
            //    if (ushort.TryParse(txt_acspeed.Text, out acspeed))
            //    {
            //        if (ushort.TryParse(txt_respeed.Text, out respeed))
            //        {
            //            if (m_qt.m_devices_id == "2")
            //            {
            //                if (m_MoonMotorRTU.RTU_MotorRun(m_qt.m_headphone_slave, pos) == false)
            //                {
            //                    return;
            //                }
                            
            //            }
            //            if (m_qt.m_devices_id == "1")
            //            {
            //                m_MoonMotorTCP.MoveLine(1, pos, speed, acspeed, respeed);
            //            }
                        
            //            if (pos == 0)
            //                pos = 100000;
            //            else
            //                pos = 0;

            //            speed += 100;
            //            if (speed > 500)
            //                speed = 100;

            //            Thread.Sleep(2000);
            //        }
            //    }
            //}
        }

        private void button7_Click_1(object sender, EventArgs e)
        {
            //bool s = m_IoBoard.SDVertOrigin();
        }

        private void button7_Click_2(object sender, EventArgs e)
        {
            if (btn_thread.Text == "stop thread")
            {
                StopThread();
                btn_thread.Text = "start thread";
            }
            else
            {
                btn_thread.Text = "stop thread";
                StartThread();
            }

        }

        private void button7_Click_3(object sender, EventArgs e)
        {
            if (btn_loop.Text == "loop")
            {
                btn_loop.Text = "stop loop";
                m_loop = true;
                StartLoop();
            }
            else
            {
                btn_loop.Text = "loop";
                m_loop = false;
                StopLoop();
            }
        }

        private void StartLoop()
        {
            Thread th = new Thread(loop);
            th.Start();
            //Thread th = new Thread(PogoCylinder_loop);
            //th.Start();
        }

        private void PogoCylinder_loop()
        {
            while (m_loop)
            {
                button35_Click(null, null);
                Thread.Sleep(5000);
                button31_Click(null, null);
                Thread.Sleep(5000);
                //Console.WriteLine("===============ogoCylinderTest()==================");
                //Console.WriteLine(m_qt.PogoCylinderTest());
                //Thread.Sleep(4000);
                //Console.WriteLine("===============PogoCylinderReset()==================");
                //Console.WriteLine(m_qt.PogoCylinderReset());
                //Thread.Sleep(4000);
            }
        }

        private void StopLoop()
        {
            m_loop = false;
        }

        private void loop()
        {
            this.StopThread();
            Thread.Sleep(1000);
            m_loop = true;
            bool status = true;

            ////// //Gray电机复位 not move to 0
            bool sdret = m_qt.SDCardBack();
            if (sdret == false)
            {
                MessageBox.Show("SDCardBack fail");
                return;
                
            }
            bool GrayCardTest = m_qt.IoBoard.GrayCardCylinder(ON);
            if (!GrayCardTest)
            {
                MessageBox.Show(".GrayCard  not in test location");
                return;                
            }
            bool grayMotor = false;
            //bool audioMotor = false;
            if (m_qt.m_devices_id == "2")
            {
                grayMotor = m_GrayMotorRTU.RTU_MotorGoHome(m_qt.m_gray_slave);
                //audioMotor = m_MoonMotorRTU.RTU_MotorGoHome(m_qt.m_headphone_slave);
            }
            if (m_qt.m_devices_id == "1")
            {
                grayMotor = m_GrayMotorTCP.SetMoonsHome(1);
                //audioMotor = m_MoonMotorTCP.SetMoonsHome(1);
            }
            if (grayMotor == false)
            {
                MessageBox.Show("Gray Motor Set Home fail");
                return;
            }
            //if (audioMotor == false)
            //{
            //    MessageBox.Show("audio Motor Set Home fail");
            //    return;
            //}
            Int32 start_time = 0, end_time = 0;
            while (m_loop)
            {
                start_time = DateTime.Now.Second;
                button25_Click(null, null);
#if (!X_TEST)
                if (status == false)
                {
                    status = ShowMessage(m_qt.Reset);
                    Thread.Sleep(100);
                    continue;
                }
                //没有TypeC功能
                //status = ShowMessage(m_qt.TypeCInsertion);
                //if (status)
                //{
                //    status = ShowMessage(m_qt.TypeCRest);
                //}
                //else
                //{
                //    break;
                //}
                if (status)
                {
                    status = ShowMessage(m_qt.CoverBoardTest);
                }
                else {
                    break;
                }
                if (status)
                {
                    status = ShowMessage(m_qt.CameraON);
                }
                else
                {
                    break;
                }
                if (status)
                {
                    btn_Door_Close_Click(null, null);
                }
                else {
                    break;
                }
                if(status){
                    status = ShowMessage(m_qt.AudioInsertion);
                }else{
                    break;
                }
                if (status){
                    status = ShowMessage(m_qt.AudioBack);
                }else{
                    break;
                }
                if (status){
                    status = ShowMessage(m_qt.PowerButtonTest);
                }else{
                    break;
                }
                if (status){
                    status = ShowMessage(m_qt.PowerButtonReset);
                }else{
                    break;
                }
                if (status){
                    status = ShowMessage(m_qt.VolumeplusButtonTest);
                }else{
                    break;
                }
                if (status){
                    status = ShowMessage(m_qt.VolumeplusButtonReset);
                }else{
                    break;
                }
                if (status){
                    status = ShowMessage(m_qt.VolumeSubButtonTest);
                }else{
                    break;
                }
                if (status){
                    status = ShowMessage(m_qt.VolumeSubButtonReset);
                }else{
                    break;
                }
                btn_IPD_Cliyner_Click(null, null);
                button35_Click(null, null);
                //if (status)
                //    status = ShowMessage(m_qt.VolumeSubButtonReset);    //display
                //if (status)
                //    status = ShowMessage(m_qt.VolumeSubButtonReset);    //led

                //if (status){
                //    status = ShowMessage(m_qt.SDCardInsertion);
                //}else{
                //    break;
                //}

                if (status){
                    status = ShowMessage(m_qt.SDCardBack);
                }else{
                    break;
                }

                //if (status){
                //    status = ShowMessage(m_qt.ProxGrayCdTest500mm);
                //}else{
                //    break;
                //}

                if (status){
                    status = ShowMessage(m_qt.ProxGrayCdTest13mm);
                }else{
                    break;
                }
                if (status){
                    status = ShowMessage(m_qt.ProxGrayCdTest20mm);
                }else{
                    break;
                }
                if (status){
                    status = ShowMessage(m_qt.ProxGrayCdTest30mm);
                }else{
                    break;
                }
                if (status){
                    status = ShowMessage(m_qt.Reset);
                }else{
                    break;
                }
#endif
                button16_Click(null,null);
                button7_Click_4(null, null);
                button17_Click(null, null);
                button25_Click(null, null);

                Thread.Sleep(1000);
                loop_count++;
                end_time = DateTime.Now.Second;
                Console.WriteLine("success run times " + loop_count.ToString() + "run a time " + ((end_time-start_time)>0?(end_time-start_time):(end_time+60-start_time)));

            }
        }

        bool btn_7 = false;
        private void button7_Click_4(object sender, EventArgs e)
        {
            if (btn_7)
            {
                btn_7 = false;
                check_readRGB_Value.Checked = false;
            }
            else
            {
                Thread th = new Thread(right_rgb);
                th.IsBackground = true;
                th.Start();
                btn_7 = true;
            }
        }

        private void right_rgb()
        {
            var res = m_qt.RightDisplayTest();
            while (check_readRGB_Value.Checked)
            {
                res = m_qt.RightDisplayTest();
                this.Invoke(new EventHandler(delegate
                {
                    richTextBox1.AppendText("RightDisplayTest:" + res[0].ToString() + "," + res[1].ToString() + "," + res[2].ToString() + System.Environment.NewLine + "\n");
                }
                ));
                Thread.Sleep(10);
            }
            if (res == null)
            {
                this.Invoke(new EventHandler(delegate
                {
                    richTextBox1.AppendText("RightDisplayTest" + " fail" + System.Environment.NewLine);
                }
                ));
            }
            else
            {
                this.Invoke(new EventHandler(delegate
                {
                    richTextBox1.AppendText("RightDisplayTest:" + res[0].ToString() + "," + res[1].ToString() + "," + res[2].ToString() + System.Environment.NewLine + "\n");
                }
                ));
            }
        }

        bool btn_25 = false;
        private void button25_Click(object sender, EventArgs e)
        {
            if (btn_25)
            {
                btn_25 = false;
                check_readRGB_Value.Checked = false;
            }
            else
            {
                Thread th = new Thread(status_rgb);
                th.IsBackground = true;
                th.Start();
                btn_25 = true;
            }
        }

        private void status_rgb()
        {
            var res = m_qt.StatusLedTest();
            while (check_readRGB_Value.Checked)
            {
                res = m_qt.StatusLedTest();
                this.Invoke(new EventHandler(delegate
                {
                    richTextBox1.AppendText("StatusLedTest:" + res[0].ToString() + "," + res[1].ToString() + "," + res[2].ToString() + System.Environment.NewLine + "\n");
                }
                ));
                Thread.Sleep(10);
            }
            if (res == null)
            {
                this.Invoke(new EventHandler(delegate
                {
                    richTextBox1.AppendText("StatusLedTest" + " fail" + System.Environment.NewLine);
                }
                ));
            }
            else
            {
                this.Invoke(new EventHandler(delegate
                {
                    richTextBox1.AppendText("StatusLedTest:" + res[0].ToString() + "," + res[1].ToString() + "," + res[2].ToString() + System.Environment.NewLine + "\n");
                }
                ));
            }
        }

        private void VolumeSubButtonTest_Click(object sender, EventArgs e)
        {

        }

        private void SDCardHBack_Click(object sender, EventArgs e)
        {

        }

        private void TypeCBtnReset_Click(object sender, EventArgs e)
        {
            ShowMessage(m_qt.TypeCRest);            
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
          //  Console.WriteLine("run to this");            
        }

        private void TriColorRed_Click(object sender, EventArgs e)
        {
            m_qt.StatusLightRed();
            //m_qt.IoBoard.StatusLightRed(ON);
            ////m_qt.IoBoard.StatusLightGreen(ON);
        }

        private void TriColorGreen_Click(object sender, EventArgs e)
        {
            m_qt.StatusLightGreen();
            //m_qt.IoBoard.StatusLightGreen(ON);
        }

        private void StatusLightOff_Click(object sender, EventArgs e)
        {
            m_qt.StatusLightOff();
            ////StatusLightOff
            //m_qt.IoBoard.StatusLightOff(OFF);
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            //光强板复位打开
            m_qt.IoBoard.LBreset(ON);
        }

        private void button6_Click_2(object sender, EventArgs e)
        {
            //光强板复位关闭
            m_qt.IoBoard.LBreset(OFF);
        }

        private void btn_gray40_Click(object sender, EventArgs e)
        {
            if (m_qt.m_devices_id == "1")
            {
                if (m_GrayMotorTCP == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }
            if (m_qt.m_devices_id == "2")
            {
                if (m_GrayMotorRTU == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }

            //上升时判断灰卡已伸出
            if (!make_sure_gray_in_test())
            {
                MessageBox.Show("灰卡伸出失败，停止上升");
                return;
            }

            int pos = 0;
            ushort speed = 0, acspeed = 0, respeed = 0;
            if (int.TryParse(this.txt_gray40.Text, out pos))
            {
                if (ushort.TryParse(txt_speed.Text, out speed))
                {
                    if (ushort.TryParse(txt_acspeed.Text, out acspeed))
                    {
                        if (ushort.TryParse(txt_respeed.Text, out respeed))
                        {
                            if (m_qt.m_devices_id == "2")
                            {
                                if (m_IoBoard_2.GrayCardCylinder(ON) == false)
                                {
                                    return;
                                }
                                if (m_IoBoard_2.StatusCk(m_IoBoard_2.GrayCardTest, 10) == false)
                                {
                                    return;
                                }
                                m_GrayMotorRTU.RTU_MotorRun(m_qt.m_gray_slave, pos);
                            }
                            if (m_qt.m_devices_id == "1")
                            {
                                if (m_IoBoard_2.GrayCardCylinder(ON) == false)
                                {
                                    return;
                                }
                                if (m_IoBoard_2.StatusCk(m_IoBoard_2.GrayCardTest, 10) == false)
                                {
                                    return;
                                }
                                if (m_GrayMotorTCP.MoveLine(1, pos, speed, acspeed, respeed) == false)
                                {
                                    return;
                                }
                            }
                           
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("输入运动数据非法，请输入0-9组成的数据");
            }
        }

        private void btn_gray50_Click(object sender, EventArgs e)
        {
           if (m_qt.m_devices_id == "1")
            {
                if (m_GrayMotorTCP == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }
            if (m_qt.m_devices_id == "2")
            {
                if (m_GrayMotorRTU == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }
            //上升时判断灰卡已伸出
            if (!make_sure_gray_in_test())
            {
                MessageBox.Show("灰卡伸出失败，停止上升");
                return;
            }

            int pos = 0;
            ushort speed = 0, acspeed = 0, respeed = 0;
            if (int.TryParse(this.txt_gray50.Text, out pos))
            {
                if (ushort.TryParse(txt_speed.Text, out speed))
                {
                    if (ushort.TryParse(txt_acspeed.Text, out acspeed))
                    {
                        if (ushort.TryParse(txt_respeed.Text, out respeed))
                        {
                            if(m_qt.m_devices_id=="2")
                            {
                                if (m_IoBoard_2.GrayCardCylinder(ON) == false)
                                {
                                    return;
                                }
                                if (m_IoBoard_2.StatusCk(m_IoBoard_2.GrayCardTest, 10)==false)
                                { 
                                    return;
                                }
                                m_GrayMotorRTU.RTU_MotorRun(m_qt.m_gray_slave, pos);
                            }
                            if (m_qt.m_devices_id == "1")
                            {
                                if (m_IoBoard_2.GrayCardCylinder(ON) == false)
                                {
                                    return;
                                }
                                if (m_IoBoard_2.StatusCk(m_IoBoard_2.GrayCardTest, 10) == false)
                                {
                                    return;
                                }
                                m_GrayMotorTCP.MoveLine(1, pos, speed, acspeed, respeed);
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("输入运动数据非法，请输入0-9组成的数据");
            }
        }

        private void btn_door_move_Click(object sender, EventArgs e)
        {
            if (m_qt.m_devices_id == "1")
            {
                if (m_doorMotorTCP == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }
            if (m_qt.m_devices_id == "2")
            {
                if (m_doorMotorRTU == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }
            int pos = 0;
            ushort speed = 0, acspeed = 0, respeed = 0;
            if (int.TryParse(this.txt_door_work.Text, out pos))
            {
                if (ushort.TryParse(txt_speed.Text, out speed))
                {
                    if (ushort.TryParse(txt_acspeed.Text, out acspeed))
                    {
                        if (ushort.TryParse(txt_respeed.Text, out respeed))
                        {
                            if (m_qt.m_devices_id == "2")
                            {
                                if (this.m_doorMotorRTU.RTU_MotorRun(m_qt.m_DoorSlave,pos) == false)
                                {
                                    return;
                                }
                            }
                            if (m_qt.m_devices_id == "1")
                            {
                                if (this.m_doorMotorTCP.MoveLine(m_qt.m_DoorSlave, pos, speed, acspeed, respeed) == false)
                                {
                                    return;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("输入运动数据非法，请输入0-9组成的数据");
            }
        }

        private void btn_door_home_Click(object sender, EventArgs e)
        {
            
            if (m_qt.m_devices_id == "2")
            {
                if (m_doorMotorRTU == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
                if (this.m_doorMotorRTU.RTU_MotorGoHome(m_qt.m_DoorSlave))
                {
                    return;
                }
            }
            if (m_qt.m_devices_id == "1")
            {
                if (m_doorMotorTCP == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
                this.m_doorMotorTCP.SetMoonsHome(m_qt.m_DoorSlave);
            }
            
            
        }

        private void btn_door_stop_Click(object sender, EventArgs e)
        {
            if (m_qt.m_devices_id == "2")
            {
                if (m_doorMotorRTU == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
                m_doorMotorRTU.Motor_Stop(3);
            }
            if (m_qt.m_devices_id == "1")
            {
                if (m_doorMotorTCP == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
                m_doorMotorTCP.SetMoonsImmediatelyStop(1);
            }
        }

        private void btn_save_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(this, "确认是否保存位置参数?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
            {
                return;
            }

            double pos = 0;
            if (txt_gray30.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_gray30.Text.Trim(), out pos))
                {
                    m_qt.Prox_Pos13mm = (int)pos;
                }
            }
            if (txt_gray40.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_gray40.Text.Trim(), out pos))
                {
                    m_qt.Prox_Pos20mm = (int)pos;
                }
            }
            if (txt_gray50.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_gray50.Text.Trim(), out pos))
                {
                    m_qt.Prox_Pos30mm = (int)pos;
                }
            }

            if (txt_Brow_gray13.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_Brow_gray13.Text.Trim(), out pos))
                {
                    m_qt.Cap_Pos13mm = (int)pos;
                }
            }
            if (txt_Brow_gray20.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_Brow_gray20.Text.Trim(), out pos))
                {
                    m_qt.Cap_Pos20mm = (int)pos;
                }
            }
            if (txt_Brow_gray30.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_Brow_gray30.Text.Trim(), out pos))
                {
                    m_qt.Cap_Pos30mm = (int)pos;
                }
            }
            if (txt_grayhome.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_grayhome.Text.Trim(), out pos))
                {
                    m_qt.Gray_Home = (int)pos;
                }
            }
            else
            {
                MessageBox.Show("请设置灰卡原点位置");
                return;
            }
            if (txt_doorhome.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_doorhome.Text.Trim(), out pos))
                {
                    m_qt.Door_Home = (ushort)pos;
                }
            }
            else
            {
                MessageBox.Show("请设置门原点位置");
                return;
            }

            if (txt_door_work.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_door_work.Text.Trim(), out pos))
                {
                    m_qt.DoorWorkPostion = (int)pos;
                }
            }
            if (txt_audio.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_audio.Text.Trim(), out pos))
                {
                    m_qt.Headphone_pos = (int)pos;
                }
            }

            //IPDMonitor
            if (txt_PositiveRotation.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_PositiveRotation.Text.Trim(), out pos))
                {
                    m_qt.Motor_PositiveRotation = (int)pos;
                }
            }
            if (txt_Position.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_Position.Text.Trim(), out pos))
                {
                    m_qt.Motor_Position = (int)pos;
                }
            }
            if (txt_IPD_TimeOut.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_IPD_TimeOut.Text.Trim(), out pos))
                {
                    m_qt.Motor_IPD_TimeOut = (int)pos;
                }
            }
            if (txt_ReversingRotation.Text.Trim().Length > 0)
            {

                if (double.TryParse(txt_ReversingRotation.Text.Trim(), out pos))
                {
                    m_qt.Motor_ReversingRotation = (int)pos;
                }
            }
            if (txt_StopSpeed.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_StopSpeed.Text.Trim(), out pos))
                {
                    m_qt.Motor_StoptSpeed = (int)pos;
                }
            }
            if (Torque_Range.Text.Trim().Length > 0)
            {
                if (double.TryParse(Torque_Range.Text.Trim(), out pos))
                {
                    m_qt.Torque_Range = (double)pos;
                }
            }
            if ( txt_Max_count.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_Max_count.Text.Trim(), out pos))
                {
                    m_qt.Max_count = (int)pos;
                }
            }
            if (txt_Sample_length.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_Sample_length.Text.Trim(), out pos))
                {
                    m_qt.Sample_length = (int)pos;
                }
            }
            if (txt_Sample_range.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_Sample_range.Text.Trim(), out pos))
                {
                    m_qt.Sample_range = (int)pos;
                }
            }

            MessageBox.Show("保存完成");
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            if (m_qt.m_devices_id == "1")
            {
                if (m_GrayMotorTCP == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }
            if (m_qt.m_devices_id == "2")
            {
                if (m_GrayMotorRTU == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }

            if (!make_sure_gray_in_test())
            {
                return;
            }

            int pos = 0;
            ushort speed = 0, acspeed = 0, respeed = 0;
            if (ushort.TryParse(txt_speed.Text, out speed))
            {
                if (ushort.TryParse(txt_acspeed.Text, out acspeed))
                {
                    if (ushort.TryParse(txt_respeed.Text, out respeed))
                    {
                        if (m_qt.m_devices_id == "2")
                        {
                            m_GrayMotorRTU.RTU_MotorGoHome(m_qt.m_gray_slave);
                        }
                        if (m_qt.m_devices_id == "1")
                        {
                            m_GrayMotorTCP.SetMoonsHome(m_qt.m_gray_slave);
                        }
                        
                    }
                }
            }
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            if (m_qt.m_devices_id == "1")
            {
                if (m_doorMotorTCP == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }
            if (m_qt.m_devices_id == "2")
            {
                if (m_doorMotorRTU == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }

            int pos = 0;
            ushort speed = 0, acspeed = 0, respeed = 0;
            if (ushort.TryParse(txt_speed.Text, out speed))
            {
                if (ushort.TryParse(txt_acspeed.Text, out acspeed))
                {
                    if (ushort.TryParse(txt_respeed.Text, out respeed))
                    {
                        if(m_qt.m_devices_id=="2")
                        {
                            if (this.m_doorMotorRTU.RTU_MotorGoHome(m_qt.m_DoorSlave) == false)
                            {
                                return;
                            }
                        }
                        if (m_qt.m_devices_id == "1") 
                        {
                            this.m_doorMotorTCP.SetMoonsHome(m_qt.m_DoorSlave);
                        }
                        
                    }
                }
            }
        }

        private void button4_Click_1(object sender, EventArgs e)
        {
            if (m_qt.m_devices_id == "2")
            {
                if (m_MoonMotorRTU == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }
            if (m_qt.m_devices_id == "1")
            {
                if (m_MoonMotorRTU == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }

            int pos = 0;
            ushort speed = 0, acspeed = 0, respeed = 0;
            if (ushort.TryParse(txt_speed.Text, out speed))
            {
                if (ushort.TryParse(txt_acspeed.Text, out acspeed))
                {
                    if (ushort.TryParse(txt_respeed.Text, out respeed))
                    {
                        if (m_MoonMotorRTU.RTU_MotorRun(m_qt.m_headphone_slave, pos) == false)
                        {
                            return;
                        }
                        //if (m_qt.m_devices_id == "2")
                        //{
                        //    if (m_MoonMotorRTU.RTU_MotorRun(m_qt.m_headphone_slave, pos) == false)
                        //    {
                        //        return;
                        //    }
                        //}
                        //if (m_qt.m_devices_id == "1")
                        //{
                        //    //m_MoonMotorTCP.MoveLine(1, pos, speed, acspeed, respeed);
                        //}
                    }
                }
            }
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            StopThread();
        }

        private void button28_Click(object sender, EventArgs e)
        {
            bool status=m_qt.ElectromagnetOpen();
            this.Invoke(new EventHandler(delegate
            {
                richTextBox1.AppendText("\nElectromagnetOpen:" + status.ToString() + "\n");
                string Command = "adb shell \"syncboss_test -f 102 -n 10 -t 100\"";
                string data = adb.Send_Command(Command);
                richTextBox1.AppendText("Test_Electromagnet " + data + "\n");
            }));

        }

        private void button27_Click(object sender, EventArgs e)
        {
            bool status = m_qt.ElectromagnetClose();
            this.Invoke(new EventHandler(delegate
            {
                richTextBox1.AppendText("\nElectromagnetClose:" + status.ToString() + "\n");
                string Command = "adb shell \"syncboss_test -f 102 -n 10 -t 100\"";
                string data = adb.Send_Command(Command);
                richTextBox1.AppendText("Test_Electromagnet " + data + "\n");
            }));
        }

        private void button29_Click(object sender, EventArgs e)
        {
            bool status = m_qt.PogoOpen();
            this.Invoke(new EventHandler(delegate
            {
                richTextBox1.AppendText("PogoOpen:" + status.ToString() + "\n");
            }));
        }

        private void button30_Click(object sender, EventArgs e)
        {
            bool status = m_qt.PogoClose();
            this.Invoke(new EventHandler(delegate
            {
                richTextBox1.AppendText("PogoClose:" + status.ToString() + "\n");
            }));
        }

        private void button31_Click(object sender, EventArgs e)
        {
            //ShowMessage(m_qt.IPDWheelMotor);
            m_qt.CoverBoardTest();
            m_qt.IoBoard_2.IPDCCylinder(ON);

            Thread.Sleep(1000);
            ShowMessage(m_qt.IPDWheelMotor_Reversing);
            Thread.Sleep(1000);

            m_qt.CoverBoardRest();
            m_qt.IoBoard_2.IPDCCylinder(OFF);
        }

        private void btn_Brow_gray13_Click(object sender, EventArgs e)
        {
            if (m_qt.m_devices_id == "1")
            {
                if (m_GrayMotorTCP == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }
            if (m_qt.m_devices_id == "2")
            {
                if (m_GrayMotorRTU == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }
            //上升时判断灰卡已伸出
            if (!make_sure_gray_in_test())
            {
                MessageBox.Show("灰卡伸出失败，停止上升");
                return;
            }

            int pos = 0;
            ushort speed = 0, acspeed = 0, respeed = 0;
            if (int.TryParse(this.txt_Brow_gray13.Text, out pos))
            {
                if (ushort.TryParse(txt_speed.Text, out speed))
                {
                    if (ushort.TryParse(txt_acspeed.Text, out acspeed))
                    {
                        if (ushort.TryParse(txt_respeed.Text, out respeed))
                        {
                            if (m_qt.m_devices_id == "2")
                            {
                                if (m_IoBoard_2.GrayCardCylinder(ON) == false)
                                {
                                    return;
                                }
                                if (m_IoBoard_2.StatusCk(m_IoBoard_2.GrayCardTest, 10) == false)
                                {
                                    return;
                                }
                                m_GrayMotorRTU.RTU_MotorRun(m_qt.m_gray_slave, pos);
                            }
                            if (m_qt.m_devices_id == "1")
                            {
                                if (m_IoBoard_2.GrayCardCylinder(ON) == false)
                                {
                                    return;
                                }
                                if (m_IoBoard_2.StatusCk(m_IoBoard_2.GrayCardTest, 10) == false)
                                {
                                    return;
                                }
                                m_GrayMotorTCP.MoveLine(m_qt.m_gray_slave, pos, speed, acspeed, respeed);
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("输入运动数据非法，请输入0-9组成的数据");
            }
        }

        private void btn_Brow_gray20_Click(object sender, EventArgs e)
        {
            if (m_qt.m_devices_id == "1")
            {
                if (m_GrayMotorTCP == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }
            if (m_qt.m_devices_id == "2")
            {
                if (m_GrayMotorRTU == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }

            //上升时判断灰卡已伸出
            if (!make_sure_gray_in_test())
            {
                MessageBox.Show("灰卡伸出失败，停止上升");
                return;
            }

            int pos = 0;
            ushort speed = 0, acspeed = 0, respeed = 0;
            if (int.TryParse(this.txt_Brow_gray20.Text, out pos))
            {
                if (ushort.TryParse(txt_speed.Text, out speed))
                {
                    if (ushort.TryParse(txt_acspeed.Text, out acspeed))
                    {
                        if (ushort.TryParse(txt_respeed.Text, out respeed))
                        {
                            if (m_qt.m_devices_id == "2")
                            {
                                if (m_IoBoard_2.GrayCardCylinder(ON) == false)
                                {
                                    return;
                                }
                                if (m_IoBoard_2.StatusCk(m_IoBoard_2.GrayCardTest, 10) == false)
                                {
                                    return;
                                }
                                m_GrayMotorRTU.RTU_MotorRun(m_qt.m_gray_slave, pos); 
                            }
                            if (m_qt.m_devices_id == "1")
                            {
                                if (m_IoBoard_2.GrayCardCylinder(ON) == false)
                                {
                                    return;
                                }
                                if (m_IoBoard_2.StatusCk(m_IoBoard_2.GrayCardTest, 10) == false)
                                {
                                    return;
                                }
                                m_GrayMotorTCP.MoveLine(1, pos, speed, acspeed, respeed); 
                            }

                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("输入运动数据非法，请输入0-9组成的数据");
            }
        }

        private void btn_Brow_gray30_Click(object sender, EventArgs e)
        {
            if (m_qt.m_devices_id == "1")
            {
                if (m_GrayMotorTCP == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }
            if (m_qt.m_devices_id == "2")
            {
                if (m_GrayMotorRTU == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
            }

            //上升时判断灰卡已伸出
            if (!make_sure_gray_in_test())
            {
                MessageBox.Show("灰卡伸出失败，停止上升");
                return;
            }

            int pos = 0;
            ushort speed = 0, acspeed = 0, respeed = 0;
            if (int.TryParse(this.txt_Brow_gray30.Text, out pos))
            {
                if (ushort.TryParse(txt_speed.Text, out speed))
                {
                    if (ushort.TryParse(txt_acspeed.Text, out acspeed))
                    {
                        if (ushort.TryParse(txt_respeed.Text, out respeed))
                        {
                            if (m_qt.m_devices_id == "2")
                            {
                                if (m_IoBoard_2.GrayCardCylinder(ON) == false)
                                {
                                    return;
                                }
                                if (m_IoBoard_2.StatusCk(m_IoBoard_2.GrayCardTest, 10) == false)
                                {
                                    return;
                                }
                                m_GrayMotorRTU.RTU_MotorRun(m_qt.m_gray_slave, pos); 
                            }
                            if (m_qt.m_devices_id == "1")
                            {
                                if (m_IoBoard_2.GrayCardCylinder(ON) == false)
                                {
                                    return;
                                }
                                if (m_IoBoard_2.StatusCk(m_IoBoard_2.GrayCardTest, 10) == false)
                                {
                                    return;
                                }
                                m_GrayMotorTCP.MoveLine(1, pos, speed, acspeed, respeed);
                            }
                            
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("输入运动数据非法，请输入0-9组成的数据");
            }
        }
        public bool make_sure_IPDCylinder_in_test()
        {
            bool res = true;
            m_IoBoard.IPDCCylinder(ON);
            res = m_IoBoard.StatusCk(m_IoBoard.IPDTest, 20);

            if (res == false)
            {
                MessageBox.Show("IPDCylinder not in Test location");
                res = false;
            }
            return res;
        }
        private void btn_IPD_Move_Click(object sender, EventArgs e)
        {
            //m_qt.IPDWheelMotor1();


            if (m_IPDMotor == null)
            {
                MessageBox.Show("请先open");
                return;
            }

            //if (!make_sure_IPDCylinder_in_test())
            {
                //return;
            }

            int PositiveRotation, ReversingRotation = 1000;
            int position = 1;
            int timeout = 10000;
            int stopspeed = 10;
            bool convert = true;
            int stop_rang = 10;
            convert = int.TryParse(this.Torque_Range.Text, out stop_rang);
            convert = int.TryParse(this.txt_PositiveRotation.Text, out PositiveRotation);
            convert = int.TryParse(this.txt_ReversingRotation.Text, out ReversingRotation);
            convert = int.TryParse(this.txt_Position.Text, out position);
            convert = int.TryParse(this.txt_IPD_TimeOut.Text, out timeout);
            convert = int.TryParse(this.txt_StopSpeed.Text, out stopspeed);
            if (convert)
            {

                //1.设定正反向转动最大值
                bool status = true;
                status = m_IPDMotor.SetMoonsPositiveRotation(m_qt.m_IPDWheelSlave, PositiveRotation);
                status = m_IPDMotor.SetMoonsReversingRotation(m_qt.m_IPDWheelSlave, ReversingRotation);
                //status = m_qt.m_MoonIPDWheel.SetMoonsPositiveRotation(1, PositiveRotation);
                //status = m_qt.m_MoonIPDWheel.SetMoonsPositiveRotation(1, ReversingRotation);

                if (!status)
                {
                    FileWriter.WriteLog("SetMoonsPositiveRotation or SetMoonsPositiveRotation is fail");
                    return;
                }
                //2.输入扭矩
                status = m_IPDMotor.SetMoonsPosition(m_qt.m_IPDWheelSlave, (ushort)position);
                DateTime start = DateTime.Now;
                Thread thrwad = new Thread(() =>
                {
                    while (true)
                    {
                        int w = m_IPDMotor.GetmotorSpeed(m_qt.m_IPDWheelSlave);
                        Thread.Sleep(200);
                        if (Math.Abs(position - w) <= Math.Abs(position * stop_rang / 100) || (DateTime.Now - start).Seconds > 20)
                        {
                            m_qt.m_MoonIPDWheel.SetMoonsPosition(m_qt.m_IPDWheelSlave, 0);       //将扭矩值设为百分之0
                            break;
                        }

                    }
                });
                thrwad.Start();

            //while (m_IPDMotor.GetCurrentSpeed(1) <= 0)
            //{
            //    Console.WriteLine("Wait IPDMotor Move...");
            //}
            ////3.监控伺服实时速度，低于某值将扭矩输入为0
            //if (status)
            //{
            //    //监控伺服当前速度，小于判定值停止电机。
            //    try
            //    {
            //        DateTime end = System.DateTime.Now.AddSeconds(timeout);
            //        int speed = m_IPDMotor.GetCurrentSpeed(1);
            //        while ((speed > stopspeed) && (DateTime.Now <= end))
            //        //while ((m_qt.m_MoonIPDWheel.GetCurrentSpeed(1) > stopspeed) && (DateTime.Now <= end))
            //        {
            //            speed = m_IPDMotor.GetCurrentSpeed(1);
            //            Console.WriteLine("MoonIPDWheel Speed:" + speed);
            //            Thread.Sleep(10);
            //        }
            //        return;
            //    }
            //    catch (Exception ex)
            //    {
            //        FileWriter.WriteLog("IPDWheelMotor exception:" + ex.Message);
            //    }
            //    finally
            //    {
            //        status = m_IPDMotor.SetMoonsPosition(1, (ushort)0);       //将扭矩值设为百分之0
            //        //status = m_qt.m_MoonIPDWheel.SetMoonsPosition(1, 0);       //将扭矩值设为百分之0
            //    }
            //}
            }
            else
            {
                MessageBox.Show("输入运动数据非法，请输入0-9组成的数据");
            }
        }

        private void btn_IPD_Stop_Click(object sender, EventArgs e)
        {
            if (m_qt.m_devices_id == "1")
            {
                if (m_IPDMotor == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
                m_IPDMotor.SetMoonsPosition(m_qt.m_IPDWheelSlave, 0);       //将扭矩值设为百分之0
            }
            
            if (m_qt.m_devices_id == "2")
            {
                if (m_IPDMotor == null)
                {
                    MessageBox.Show("请先open");
                    return;
                }
                m_IPDMotor.SetMoonsPosition(m_qt.m_IPDWheelSlave, 0);       //将扭矩值设为百分之0
            }
        }

        private void btn_Power_out_Click(object sender, EventArgs e)
        {
            if (m_qt.PowerCylinderTest()==false)
            {
                MessageBox.Show("PowerCylinderTest fail");
            }
            
        }

        private void btn_power_in_Click(object sender, EventArgs e)
        {
            if (m_qt.PowerCylinderRest() == false)
            {
                MessageBox.Show("PowerCylinderRest fail");
            }
        }

        private void btn_holder_in_Click(object sender, EventArgs e)
        {
            if (m_qt.CoverBoardTest() == false)
            {
                MessageBox.Show("CoverBoardTest fail");
            }
        }

        private void btn_holder_out_Click(object sender, EventArgs e)
        {
            m_qt.CoverBoardRest();
        }

        private void btn_HolderIN_Click(object sender, EventArgs e)
        {
            m_qt.CoverBoardTest();
        }

        private void btn_HolderOUT_Click(object sender, EventArgs e)
        {
            m_qt.CoverBoardRest();
        }

        private void btn_IPD_Cliyner_Click(object sender, EventArgs e)
        {
            m_qt.IoBoard_2.IPDCCylinder(ON);
        }

        private void btn_IPDCliynerOFF_Click(object sender, EventArgs e)
        {
            m_qt.IoBoard_2.IPDCCylinder(OFF);
        }

        private void btn_Door_Open_Click(object sender, EventArgs e)
        {
            m_qt.OpenDoor();
        }

        private void btn_Door_Close_Click(object sender, EventArgs e)
        {
            m_qt.CloseDoor();
        }

        private void btn_PowerCylienerIN_Click(object sender, EventArgs e)
        {
            m_qt.PowerCylinderRest();
        }

        private void btn_PowerCylinerOUT_Click(object sender, EventArgs e)
        {
            m_qt.PowerCylinderTest();
            
        }

        private void btn_PogoCyliner_ON_Click(object sender, EventArgs e)
        {
            m_qt.PogoCylinderTest();
        }

        private void btn_PogoCyliner_OFF_Click(object sender, EventArgs e)
        {
            m_qt.PogoCylinderReset();
        }

        private void timer_motor_Tick(object sender, EventArgs e)
        {
            
        }

        private void timer_motorspeed(object sender, EventArgs e)
        {
            //txt_motor.Text = m_qt.m_MoonIPDWheel.GetCurrentSpeed(m_qt.m_IPDWheelSlave).ToString();
            //string str = m_qt.m_MoonIPDWheel.GetCurrentSpeed(m_qt.m_IPDWheelSlave).ToString();
            //Console.WriteLine(str.ToString());
            ////txt_motorspeed.Text = m_qt.m_MoonIPDWheel.GetmotorSpeed(m_qt.m_IPDWheelSlave).ToString();
            //string str1 = m_qt.m_MoonIPDWheel.GetmotorSpeed(m_qt.m_IPDWheelSlave).ToString();
            //Console.WriteLine(str1.ToString());
            //setLabelBkColor(m_IoBoard.E_Stop, ref E_Stop);
        }

        private void TriColorYellow_Click(object sender, EventArgs e)
        {
            //m_qt.IoBoard.StatusLightYellow(ON);
            m_qt.StatusLightYellow();
        }

        private void txt_motorspeed_TextChanged(object sender, EventArgs e)
        {

        }

        private void button32_Click(object sender, EventArgs e)
        {
            m_qt.Reset();
        }



        Adb_Common adb = new Adb_Common();
        private void Open_Red_Click(object sender, EventArgs e)
        {
            //string Command = "adb root";
            //adb.Send_Command(Command);
            //Thread.Sleep(1000);
            string Command = "adb shell \"echo 75 > /sys/class/leds/red/brightness\"";
            adb.Send_Command(Command);
            Command = "adb shell \"echo 0 > /sys/class/leds/blue/brightness\"";
            adb.Send_Command(Command);
            Command = "adb shell \"echo 0 > /sys/class/leds/green/brightness\"";
            adb.Send_Command(Command);
            button17_Click(null, null);
        }

        private void Open_Green_Click(object sender, EventArgs e)
        {
            //string Command = "adb root";
            //adb.Send_Command(Command);
            //Thread.Sleep(1000);
            string Command = "adb shell \"echo 0 > /sys/class/leds/red/brightness\"";
            adb.Send_Command(Command);
            Command = "adb shell \"echo 0 > /sys/class/leds/blue/brightness\"";
            adb.Send_Command(Command);
            Command = "adb shell \"echo 95 > /sys/class/leds/green/brightness\"";
            string data = adb.Send_Command(Command);
            button17_Click(null, null);
        }

        private void Open_Blue_Click(object sender, EventArgs e)
        {
            //string Command = "adb root";
            //adb.Send_Command(Command);
            //Thread.Sleep(1000);
            string Command = "adb shell \"echo 0 > /sys/class/leds/red/brightness\"";
            adb.Send_Command(Command);
            Command = "adb shell \"echo 55 > /sys/class/leds/blue/brightness\"";
            adb.Send_Command(Command);
            Command = "adb shell \"echo 0 > /sys/class/leds/green/brightness\"";
            string data = adb.Send_Command(Command);
            button17_Click(null, null);
        }

        private void Open_Status_Click(object sender, EventArgs e)
        {
            string Command = "adb root";
            adb.Send_Command(Command);
            Thread.Sleep(1000);
            Command = "adb shell \"cameratool -T\"";
            adb.Send_Command(Command,false);

            button25_Click(null, null);
            
        }

        private void Test_Electromagnet_Click(object sender, EventArgs e)
        {
            string Command = "adb shell \"syncboss_test -f 102 -n 10 -t 100\"";
            string data = adb.Send_Command(Command);
            richTextBox1.AppendText("Test_Electromagnet " + data + "\n");
        }

        private void Test_Cray_Click(object sender, EventArgs e)
        {
            string Command = "adb shell syncboss_test -f 201";
            string data = adb.Send_Command(Command);
            string offsetH = data.Split(',')[0].Split('=')[1];
            string offsetL = data.Split(',')[1].Split('=')[1].Replace("\r\n","");
            data = adb.Send_Command("adb shell syncboss_test -f 202 -n 10 -t 100 -p "+offsetH+" "+offsetL);
            richTextBox1.AppendText("Test_Cray " + data + "\n");
        }

        private void Clear_box_Click(object sender, EventArgs e)
        {
            richTextBox1.Text = "";
            richTextBox1.Clear();
        }

        private void button33_Click(object sender, EventArgs e)
        {
            ///*读取当前位置*/
            //float pos = this.m_doorMotorTCP.GetMoonsLocalPosition(this.m_qt.m_DoorSlave);
            //richTextBox1.AppendText(pos.ToString());

            /*检测当前电机状态*/
            bool status = this.m_GrayMotorTCP.CheckHomeStatus(this.m_qt.m_gray_slave);
            double pos = this.m_GrayMotorTCP.GetMoonsLocalPosition(this.m_qt.m_gray_slave);
            double door_pos = this.m_doorMotorTCP.GetMoonsLocalPosition(this.m_qt.m_DoorSlave);
            richTextBox1.AppendText(status.ToString()+"\n");
            richTextBox1.AppendText(pos.ToString() + "\n");
            richTextBox1.AppendText(door_pos.ToString() + "\n");
            //string com = "COM28";
            //string type = "0";
            //string Command = string.Format(@"D:\EurekaQT\EurekaQT\bin\Debug\Debug\PortMangmenTool.exe {0} {1}",com,type);
            //string data = adb.Send_Command(Command);
            //richTextBox1.AppendText("COM28 " + data + "\n");
            Thread thread_led = new Thread(() =>
            {
                
                for(int i=0;i<100;i++)
                {
                    m_qt.PowerCylinderTest();
                    button17_Click(null, null);
                    button17_Click(null, null);
                    button17_Click(null, null);
                    button17_Click(null, null);
                    button25_Click(null, null);
                    button7_Click_4(null, null);
                    button16_Click(null, null);
                    m_qt.PowerCylinderRest();
                    Thread.Sleep(200);
                }
            });
            //thread_led.Start();
        }

        private void button34_Click(object sender, EventArgs e)
        {
            string Command = "adb root";
            adb.Send_Command(Command);
            //Thread.Sleep(2000);
            //Thread thread_led = new Thread(() =>
            //{

            //    for (int i = 0; i < 100; i++)
            //    {
            //        Open_Red_Click(null,null);
                   
            //        Thread.Sleep(1500);
            //        Open_Green_Click(null, null);
                    
            //        Thread.Sleep(500);
            //        Open_Blue_Click(null, null);
            //        Thread.Sleep(500);
            //        Command = "adb shell \"echo 255 > /sys/class/leds/red/brightness\"";
            //        adb.Send_Command(Command);
            //        Command = "adb shell \"echo 255 > /sys/class/leds/blue/brightness\"";
            //        adb.Send_Command(Command);
            //        Command = "adb shell \"echo 255 > /sys/class/leds/green/brightness\"";
            //        string data = adb.Send_Command(Command);
            //        button17_Click(null, null);
            //        Thread.Sleep(700);
            //    }
            //});
            //thread_led.Start();
        }

        private void txt_Position_TextChanged(object sender, EventArgs e)
        {

        }

        private void txt_PositiveRotation_TextChanged(object sender, EventArgs e)
        {

        }

        private void txt_motor_TextChanged(object sender, EventArgs e)
        {

        }

        private void label20_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void txt_IPD_TimeOut_TextChanged(object sender, EventArgs e)
        {

        }

        private void txt_ReversingRotation_TextChanged(object sender, EventArgs e)
        {

        }

        private void btn_Save_Audio_Click(object sender, EventArgs e)
        {
            //AudioMonitor
            double pos = 0;
            if (txt_PositiveRotation_Audio.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_PositiveRotation_Audio.Text.Trim(), out pos))
                {
                    m_qt.Headphone_acspeed = (ushort)pos;
                }
            }

            if (txt_ReversingRotation_Audio.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_ReversingRotation_Audio.Text.Trim(), out pos))
                {
                    m_qt.Headphone_respeed = (ushort)pos;
                }
            }

            if (txt_Position_Audio.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_Position_Audio.Text.Trim(), out pos))
                {
                    m_qt.Headphone_pos = (ushort)pos;
                }
            }

            if (txt_Position_Audio_re.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_Position_Audio_re.Text.Trim(), out pos))
                {
                    m_qt.Headphone_pos_re = (ushort)pos;
                }
            }

            if (txt_Range1_Audio.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_Range1_Audio.Text.Trim(), out pos))
                {
                    m_qt.Headphone_HeadStopRange_1 = (ushort)pos;
                }
            }

            if (txt_Range2_Audio.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_Range2_Audio.Text.Trim(), out pos))
                {
                    m_qt.Headphone_HeadStopRange_2 = (ushort)pos;
                }
            }

            if (txt_StopSpeed_Audio.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_StopSpeed_Audio.Text.Trim(), out pos))
                {
                    m_qt.Headphone_HeadStopSeepd = (ushort)pos;
                }
            }

            if (txt_OutTime_Audio.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_OutTime_Audio.Text.Trim(), out pos))
                {
                    m_qt.Headphone_HeadTimeOut = (ushort)pos;
                }
            }

            if (txt_HomeTime_Audio.Text.Trim().Length > 0)
            {
                if (double.TryParse(txt_HomeTime_Audio.Text.Trim(), out pos))
                {
                    m_qt.Headphone_HeadHomeTime = (ushort)pos;
                }
            }

            MessageBox.Show("保存完成");

        }

        private void btn_Move_Audio_Click(object sender, EventArgs e)
        {
            int i = 10;

            int.TryParse(txt_Position_Audio.Text.ToString().Trim(), out i);
            m_qt.AudioMotor2(false, i);
        }

        private void btn_Stop_Audio_Click(object sender, EventArgs e)
        {
            bool result = m_IPDMotor.SetMoonsPosition(5, 0);       //将扭矩值设为百分之0

            Console.WriteLine("AudioMotor Stop : result" + result);
        }

        private void btn_step_Audio_MouseDown(object sender, MouseEventArgs e)
        {
            Console.WriteLine("btn_step_Audio_MouseDown");
            int speed = 0;
            dt_Positive = new DataTable();
            dt_Positive.Columns.Add("speed");
            dt_Positive.Columns.Add("speedN");

            int.TryParse(txt_PositiveRotation_Audio.Text.Trim(),out speed);
            bool status = m_MoonMotorRTU.SetMoonsPositiveRotation(m_qt.m_headphone_slave, speed);

            int.TryParse(txt_ReversingRotation_Audio.Text.Trim(),out speed);
            status = m_MoonMotorRTU.SetMoonsReversingRotation(m_qt.m_headphone_slave, speed);
            
            if (!status)
            {
                FileWriter.WriteLog("Audio SetMoonsPositiveRotation or SetMoonsPositiveRotation is fail");
            }
            else
            {
                int.TryParse(txt_Position_Audio.Text.ToString().Trim(), out speed);
                bool ret = m_MoonMotorRTU.SetMoonsPosition(m_qt.m_headphone_slave, (ushort)speed);
                Console.WriteLine("btn_step_Audio_MouseDown---result:" + ret);
            }
            
        }

        private void btn_step_Audio_MouseUp(object sender, MouseEventArgs e)
        {
            Console.WriteLine("btn_step_Audio_MouseUp");
            bool ret = m_MoonMotorRTU.SetMoonsPosition(m_qt.m_headphone_slave, 0);
            Console.WriteLine("btn_step_Audio_MouseUp---result:" + ret);
            

            string os = DateTime.Now.ToString("yyyy_MM_dd");
            string p = DateTime.Now.ToString("HH_mm_ss");
            string path1 = string.Format(@"D:\csv_data\{0}\{1}_Audio_Jog+.csv", os, p);
            Write_csv.SaveCSV1(dt_Positive, path1);
        }

        private void btn_step_Audio_out_MouseDown(object sender, MouseEventArgs e)
        {
            Console.WriteLine("btn_step_Audio_MouseDown");
            int speed = 0;
            dt_Positive = new DataTable();
            dt_Positive.Columns.Add("speed");
            dt_Positive.Columns.Add("speedN");

            int.TryParse(txt_PositiveRotation_Audio.Text.Trim(), out speed);
            bool status = m_MoonMotorRTU.SetMoonsPositiveRotation(m_qt.m_headphone_slave, speed);

            int.TryParse(txt_ReversingRotation_Audio.Text.Trim(), out speed);
            status = m_MoonMotorRTU.SetMoonsReversingRotation(m_qt.m_headphone_slave, speed);

            if (!status)
            {
                FileWriter.WriteLog("Audio SetMoonsPositiveRotation or SetMoonsPositiveRotation is fail");
            }
            else
            {
                int.TryParse(txt_Position_Audio.Text.ToString().Trim(), out speed);
                speed = speed * -1;
                bool ret = m_MoonMotorRTU.SetMoonsPosition(m_qt.m_headphone_slave, (ushort)speed);
                Console.WriteLine("btn_step_Audio_MouseDown---result:" + ret);
            }
        }

        private void btn_step_Audio_out_MouseUp(object sender, MouseEventArgs e)
        {
            Console.WriteLine("btn_step_Audio_MouseUp");
            bool ret = m_MoonMotorRTU.SetMoonsPosition(m_qt.m_headphone_slave, 0);
            Console.WriteLine("btn_step_Audio_MouseUp---result:" + ret);

            string os = DateTime.Now.ToString("yyyy_MM_dd");
            string p = DateTime.Now.ToString("HH_mm_ss");
            string path1 = string.Format(@"D:\csv_data\{0}\{1}_Audio_Jog-.csv", os, p);
            Write_csv.SaveCSV1(dt_Positive, path1);
        }

        private void btn_camera_out_Click(object sender, EventArgs e)
        {
            m_qt.CameraON();
        }

        private void bnt_camera_in_Click(object sender, EventArgs e)
        {
            m_qt.CameraOFF();
        }

        private void btn_Buzzer_Open_Click(object sender, EventArgs e)
        {
            m_qt.TriColorBuzzer_Open();
        }

        private void btn_Buzzer_Close_Click(object sender, EventArgs e)
        {
            m_qt.TriColorBuzzer_Close();
        }

        private void btn_VBUS_Click(object sender, EventArgs e)
        {
            m_qt.Ping_VBUS_On();
        }

        private void btn_CC_Click(object sender, EventArgs e)
        {
            m_qt.Ping_CC_On();
        }

        private void btn_GND_Click(object sender, EventArgs e)
        {
            m_qt.Ping_GND_On();
        }

        private void btn_VBUS_Off_Click(object sender, EventArgs e)
        {
            m_qt.Ping_VBUS_Off();
        }

        private void btn_CC_Off_Click(object sender, EventArgs e)
        {
            m_qt.Ping_CC_Off();
        }

        private void bnt_GND_Off_Click(object sender, EventArgs e)
        {
            m_qt.Ping_GND_Off();
        }

        private void btn_Home_Audio_Click(object sender, EventArgs e)
        {
            m_qt.AudioMotor_Home(false);
        }

        private void button35_Click(object sender, EventArgs e)
        {
            m_qt.CoverBoardTest();
            m_qt.IoBoard_2.IPDCCylinder(ON);

            Thread.Sleep(1000);
            ShowMessage(m_qt.IPDWheelMotor);
            Thread.Sleep(1000);

            m_qt.CoverBoardRest();
            m_qt.IoBoard_2.IPDCCylinder(OFF);
        }

        private void Open_Status_write_Click(object sender, EventArgs e)
        {
            string Command = "adb root";
            adb.Send_Command(Command);
            Thread.Sleep(1000);
            Command = "adb shell \"cameratool -T\"";
            adb.Send_Command_CameraTool(Command);
            Command = @"shell echo 255 > /sys/class/leds/white\:indicator/brightness";
            adb.Send_Command(Command);

            button25_Click(null, null);
        }

        private void Close_Status_Click(object sender, EventArgs e)
        {
            string Command = "adb root";
            adb.Send_Command(Command);
            Thread.Sleep(1000);
            Command = "adb shell setprop vendor.debug.camera.factory.stop  1";
            adb.Send_Command(Command);
        }

        private void btn_pogo_V_Click(object sender, EventArgs e)
        {
            string Command = "adb shell \"cat sys/class/power_supply/wireless/voltage_now\"";
            string data = adb.Send_Command(Command);
            richTextBox1.AppendText("Pogo 电压: " + data + "\n");
        }

        private void button43_Click(object sender, EventArgs e)
        {
            var datas = m_qt.StatusLedTest();
            if (datas == null)
            {
                this.Invoke(new EventHandler(delegate
                {
                    richTextBox2.AppendText("StatusLedTest" + " fail" + System.Environment.NewLine);
                }
                ));

            }
            else
            {
                var cal_r = double.Parse(txt_led_r.Text.ToString());
                var cal_g = double.Parse(txt_led_g.Text.ToString());
                var cal_b = double.Parse(txt_led_b.Text.ToString());

                //计算比率
                var r = Math.Round(cal_r / cal_r, 2);
                var g = Math.Round(cal_r / cal_g, 2);
                var b = Math.Round(cal_r / cal_b, 2);

                var cal_r_value = (int)(datas[0] * r);
                var cal_g_value = (int)(datas[1] * g);
                var cal_b_value = (int)(datas[2] * b);
                this.Invoke(new EventHandler(delegate
                {
                    richTextBox2.AppendText("StatusLedTest 原始值:" + datas[0].ToString() + "," + datas[1].ToString() + "," + datas[2].ToString() + System.Environment.NewLine + "\n");
                    richTextBox2.AppendText("StatusLedTest 比率值:" + r.ToString() + "," + g.ToString() + "," + b.ToString() + System.Environment.NewLine + "\n");
                    richTextBox2.AppendText("StatusLedTest 校准值:" + cal_r_value.ToString() + "," + cal_g_value.ToString() + "," + cal_b_value.ToString() + System.Environment.NewLine + "\n");
                }
                ));
            }
        }

        private void button45_Click(object sender, EventArgs e)
        {
            {
                var datas = m_qt.PowerLedTest();
                if (datas == null)
                {
                    this.Invoke(new EventHandler(delegate
                    {
                        richTextBox2.AppendText("PowerLedTest" + " fail" + System.Environment.NewLine);
                    }
                                        ));
                }
                else
                {
                    var cal_r = double.Parse(txt_power_r.Text.ToString());
                    var cal_g = double.Parse(txt_power_g.Text.ToString());
                    var cal_b = double.Parse(txt_power_b.Text.ToString());

                    //计算比率
                    var r = Math.Round(cal_r / cal_r, 2);
                    var g = Math.Round(cal_r / cal_g, 2);
                    var b = Math.Round(cal_r / cal_b, 2);

                    var cal_r_value = (int)(datas[0] * r);
                    var cal_g_value = (int)(datas[1] * g);
                    var cal_b_value = (int)(datas[2] * b);
                    this.Invoke(new EventHandler(delegate
                    {
                        richTextBox2.AppendText("PowerLedTest 初始值:" + datas[0].ToString() + "," + datas[1].ToString() + "," + datas[2].ToString() + System.Environment.NewLine + "\n");
                        richTextBox2.AppendText("PowerLedTest 比率值:" + r.ToString() + "," + g.ToString() + "," + b.ToString() + System.Environment.NewLine + "\n");
                        richTextBox2.AppendText("PowerLedTest 校准值:" + cal_r_value.ToString() + "," + cal_g_value.ToString() + "," + cal_b_value.ToString() + System.Environment.NewLine + "\n");
                    }
                                        ));
                }
            }
        }

        public void button44_Click(object sender, EventArgs e)
        {
            //保存校准值  WriteInt
            double value = 0;
            if (double.TryParse(txt_led_r.Text, out value))
            {
                this.m_qt.Set_RGB_value("RGB_power_cal", "r", (txt_led_r.Text).ToString());
            }
            else
            { 
                MessageBox.Show("状态灯R通道输入值非法!");
                return;
            }
            
            if (double.TryParse(txt_led_g.Text, out value))
            {
                this.m_qt.Set_RGB_value("RGB_power_cal", "g", (txt_led_g.Text).ToString());
            }
            else
            {
                MessageBox.Show("状态灯G通道输入值非法!");
                return;
            }
            
            if (double.TryParse(txt_led_b.Text, out value))
            {
                this.m_qt.Set_RGB_value("RGB_power_cal", "b", (txt_led_b.Text).ToString());
            }
            else
            {
                MessageBox.Show("状态灯B通道输入值非法!");
                return;
            }
            
            if (double.TryParse(txt_power_r.Text, out value))
            {
                this.m_qt.Set_RGB_value("RGB_status_cal", "r", (txt_power_r.Text).ToString());
            }
            else
            {
                MessageBox.Show("Power灯R通道输入值非法!");
                return;
            }
            if (double.TryParse(txt_power_g.Text, out value))
            {
                this.m_qt.Set_RGB_value("RGB_status_cal", "g", (txt_power_g.Text).ToString());
            }
            else
            {
                MessageBox.Show("Power灯G通道输入值非法!");
                return;
            }
            if (double.TryParse(txt_power_b.Text, out value))
            {
                this.m_qt.Set_RGB_value("RGB_status_cal", "b", (txt_power_b.Text).ToString());
            }
            else
            {
                MessageBox.Show("Power灯B通道输入值非法!");
                return;
            }
            MessageBox.Show("保存成功 ！");
        }

        private void button36_Click(object sender, EventArgs e)
        {
            richTextBox2.Text = "";
            richTextBox2.Clear();
        }

        private void button39_Click(object sender, EventArgs e)
        {
            string Command = "adb root";
            adb.Send_Command(Command);
            Thread.Sleep(1000);
            Command = "adb shell \"cameratool -T\"";
            string data = adb.Send_Command(Command, false);
            richTextBox2.AppendText(Command + ":" + data + "\n");
        }

        private void button38_Click(object sender, EventArgs e)
        {
            string Command = "adb root";
            adb.Send_Command(Command);
            Thread.Sleep(1000);
            Command = "adb shell \"cameratool -G\"";
            string data =
            adb.Send_Command_CameraTool(Command);
            Command = @"shell echo 255 > /sys/class/leds/white\:indicator/brightness";
            adb.Send_Command(Command);
        }

        private void btn_doorpos_Click(object sender, EventArgs e)
        {
            double door_pos = this.m_doorMotorTCP.GetMoonsLocalPosition(this.m_qt.m_DoorSlave);
            txt_doorpos.Text = door_pos.ToString();
        }

        private void btn_graypos_Click(object sender, EventArgs e)
        {
            double pos = this.m_GrayMotorTCP.GetMoonsLocalPosition(this.m_qt.m_gray_slave);
            txt_graypos.Text = pos.ToString();
        }

        private void button16_MouseEnter(object sender, EventArgs e)
        {
            Console.WriteLine("================");
//            var res = m_qt.LeftDisplayTest();
//            if (res == null)
//            {
//                //                Console.WriteLine("LeftDisplayTest fail");
//                this.Invoke(new EventHandler(delegate
//                {
//                    richTextBox1.AppendText("LeftDisplayTest" + " fail" + System.Environment.NewLine);
//                }));
//            }
//            else
//            {
//                //                Console.WriteLine(res.ToString());
//#if (!JUST_SHOW_FAIL)
//                this.Invoke(new EventHandler(delegate
//                {
//                    richTextBox1.AppendText("LeftDisplayTest:" + res[0].ToString() + "," + res[1].ToString() + "," + res[2].ToString() + System.Environment.NewLine + "\n");
//                }));
//#endif
//            }
        }



    }
}
