private void Set_AcTiming()
        {
            PGRemoteRPCClient client = new PGRemoteRPCClient();
            int    rc        = client.Connect("", 2799);
            string errMsg    = "";
            string statusMsg = "";

            byte[] DUTResp = new byte[0];
            if (rc < 0)
            {
                return;
            }
            client.PGRemoteCmd(RPCCmds.START_EDIT_CONFIG, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_LP_FREQ, (float)18e+6, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_HS_FREQ, PG_Setting_Value.bitrate, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.END_EDIT_CONFIG, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_DPHY_PARAMETER, RPCDefs.DPHY_PARAM_USE_SYSTEM_COMPUTED_TIMING, 1, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_DPHY_PARAMETER, RPCDefs.DPHY_PARAM_USE_SYSTEM_COMPUTED_TIMING, 0, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_DPHY_PARAMETER, RPCDefs.DPHY_PARAM_HS_PREPARE, PG_Setting_Value.hs_prepare, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_DPHY_PARAMETER, RPCDefs.DPHY_PARAM_HS_ZERO, PG_Setting_Value.hs_zero, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_DPHY_PARAMETER, RPCDefs.DPHY_PARAM_HS_EXIT, PG_Setting_Value.hs_exit, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_DPHY_PARAMETER, RPCDefs.DPHY_PARAM_HS_TRAIL, PG_Setting_Value.hs_trail, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_DPHY_PARAMETER, RPCDefs.DPHY_PARAM_CLK_PREPARE, PG_Setting_Value.clk_prepare, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_DPHY_PARAMETER, RPCDefs.DPHY_PARAM_CLK_ZERO, PG_Setting_Value.clk_zero, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_DPHY_PARAMETER, RPCDefs.DPHY_PARAM_CLK_TRAIL, PG_Setting_Value.clk_trail, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_DPHY_PARAMETER, RPCDefs.DPHY_PARAM_CLK_PRE, PG_Setting_Value.clk_pre, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_DPHY_PARAMETER, RPCDefs.DPHY_PARAM_CLK_POST, PG_Setting_Value.clk_post, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_DPHY_PARAMETER, RPCDefs.DPHY_PARAM_TA_GO, PG_Setting_Value.TA_go, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_DPHY_PARAMETER, RPCDefs.DPHY_PARAM_WAKEUP, PG_Setting_Value.T_wakeup, ref errMsg, ref statusMsg);
            client.Disconnect(true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="blanking_type">1:lp every frame 2:lp every line</param>
        /// <param name="sync_mode">1:pulse mode 2:event mode 3: burst mode</param>
        public void Set_VideoMode_Type(int blanking_type, int sync_mode)
        {
            PGRemoteRPCClient client = new PGRemoteRPCClient();
            int    rc        = client.Connect("", 2799);
            string errMsg    = "";
            string statusMsg = "";

            byte[] DUTResp = new byte[0];
            if (rc < 0)
            {
                return;
            }
            if (blanking_type == 1)
            {
                client.PGRemoteCmd(RPCCmds.SET_TIMING_HBPORCH_BLANKING_MODE, 2, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_TIMING_HFPORCH_BLANKING_MODE, 2, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_TIMING_HSYNC_BLANKING_MODE, 2, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_TIMING_VERTICAL_BLANKING_MODE, 1, ref errMsg, ref statusMsg);
            }
            else if (blanking_type == 2)
            {
                client.PGRemoteCmd(RPCCmds.SET_TIMING_HBPORCH_BLANKING_MODE, 1, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_TIMING_HFPORCH_BLANKING_MODE, 1, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_TIMING_HSYNC_BLANKING_MODE, 1, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_TIMING_VERTICAL_BLANKING_MODE, 1, ref errMsg, ref statusMsg);
            }
            else
            {
                return;
            }
            if (sync_mode == 1)
            {
                client.PGRemoteCmd(RPCCmds.SET_TIMING_ENABLE_DSI_BURST_MODE, false, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_TIMING_ENABLE_DSI_PULSE_MODE, true, ref errMsg, ref statusMsg);
            }
            else if (sync_mode == 2)
            {
                client.PGRemoteCmd(RPCCmds.SET_TIMING_ENABLE_DSI_BURST_MODE, false, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_TIMING_ENABLE_DSI_PULSE_MODE, false, ref errMsg, ref statusMsg);
            }
            else if (sync_mode == 3)
            {
                client.PGRemoteCmd(RPCCmds.SET_TIMING_ENABLE_DSI_BURST_MODE, true, ref errMsg, ref statusMsg);
            }
            else
            {
                return;
            }


            client.Disconnect(true);
        }
            public void PG_Stop()
            {
                PGRemoteRPCClient client = new PGRemoteRPCClient();
                int    rc        = client.Connect("", 2799);
                string errMsg    = "";
                string statusMsg = "";

                byte[] DUTResp = new byte[0];
                if (rc < 0)
                {
                    return;
                }
                client.PGRemoteCmd(RPCCmds.PG_ABORT, ref errMsg, ref statusMsg);
                client.Disconnect(true);
            }
            public void Clock_Alway_Switch(bool a)
            {
                PGRemoteRPCClient client = new PGRemoteRPCClient();
                int    rc        = client.Connect("", 2799);
                string errMsg    = "";
                string statusMsg = "";

                byte[] DUTResp = new byte[0];
                if (rc < 0)
                {
                    return;
                }
                client.PGRemoteCmd(RPCCmds.SET_OPTION, RPCDefs.OPT_CLOCK_ON_OFF_EACH_COMMAND, a, ref errMsg, ref statusMsg);
                client.Disconnect(true);
            }
            public void Eotp_Switch(bool a)
            {
                PGRemoteRPCClient client = new PGRemoteRPCClient();
                int    rc        = client.Connect("", 2799);
                string errMsg    = "";
                string statusMsg = "";

                byte[] DUTResp = new byte[0];
                if (rc < 0)
                {
                    return;
                }
                client.PGRemoteCmd(RPCCmds.SET_OPTION, RPCDefs.OPT_ENABLE_EOT_PKTS, a, ref errMsg, ref statusMsg);
                client.Disconnect(true);
            }
            public void P338_Loop_Command(bool a)
            {
                PGRemoteRPCClient client = new PGRemoteRPCClient();
                int    rc        = client.Connect("", 2799);
                string errMsg    = "";
                string statusMsg = "";

                byte[] DUTResp = new byte[0];
                if (rc < 0)
                {
                    return;
                }
                client.PGRemoteCmd(RPCCmds.SET_OPTION, RPCDefs.OPT_LOOP_NON_VIDEO_COMMANDS, a, ref errMsg, ref statusMsg);
                client.Disconnect(true);
            }
        public void SEND_Video_mode(string file_path)
        {
            PGRemoteRPCClient client = new PGRemoteRPCClient();
            int    rc        = client.Connect("", 2799);
            string errMsg    = "";
            string statusMsg = "";

            byte[] DUTResp = new byte[0];
            if (rc < 0)
            {
                return;
            }
            client.MIPICmd(RPCDefs.PACKED_PIXEL_STREAM_888, 0, false, RPCDefs.DT_HS, 0, 1, 0, 0, file_path, null, ref errMsg, ref statusMsg);
            client.Disconnect(true);
        }
        public void Set_DPHY_Swing(MIPI_Parameter MIPI_Setting)
        {
            PGRemoteRPCClient client = new PGRemoteRPCClient();
            int    rc        = client.Connect("", 2799);
            string errMsg    = "";
            string statusMsg = "";

            byte[] DUTResp = new byte[0];
            if (rc < 0)
            {
                return;
            }
            client.PGRemoteCmd(RPCCmds.START_EDIT_CONFIG, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_HS_HIGH_VOLT, 0, MIPI_Setting.HS_High, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_HS_LOW_VOLT, 0, MIPI_Setting.HS_High, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_LP_HIGH_VOLT, 0, MIPI_Setting.LP_High, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_LP_LOW_VOLT, 0, MIPI_Setting.LP_Low, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.END_EDIT_CONFIG, ref errMsg, ref statusMsg);
            client.Disconnect(true);
        }
        public void Set_DPHY_Skew(MIPI_Parameter MIPI_Setting)
        {
            PGRemoteRPCClient client = new PGRemoteRPCClient();
            int    rc        = client.Connect("", 2799);
            string errMsg    = "";
            string statusMsg = "";

            byte[] DUTResp = new byte[0];
            if (rc < 0)
            {
                return;
            }
            client.PGRemoteCmd(RPCCmds.START_EDIT_CONFIG, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_HS_DELAY, 0, MIPI_Setting.D0_Delay * 1e-12, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_HS_DELAY, 1, MIPI_Setting.D1_Delay * 1e-12, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_HS_DELAY, 2, MIPI_Setting.D2_Delay * 1e-12, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_HS_DELAY, 3, MIPI_Setting.D3_Delay * 1e-12, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_HS_DELAY, 4, MIPI_Setting.CLK_Delay * 1e-12, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.END_EDIT_CONFIG, ref errMsg, ref statusMsg);
            client.Disconnect(true);
        }
        public void Video_mode_Setting(int hact, int hsa, int hbp, int hfp, int vact, int vsa, int vbp, int vfp)
        {
            PGRemoteRPCClient client = new PGRemoteRPCClient();
            int    rc        = client.Connect("", 2799);
            string errMsg    = "";
            string statusMsg = "";

            byte[] DUTResp = new byte[0];
            if (rc < 0)
            {
                return;
            }
            client.PGRemoteCmd(RPCCmds.SET_TIMING_HSYNC, hsa, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_TIMING_HBPORCH, hbp, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_TIMING_HFPORCH, hfp, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_TIMING_HACTIVE, hact, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_TIMING_VSYNC, vsa, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_TIMING_VBPORCH, vbp, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_TIMING_VFPORCH, vfp, ref errMsg, ref statusMsg);
            client.PGRemoteCmd(RPCCmds.SET_TIMING_VACTIVE, vact, ref errMsg, ref statusMsg);
            client.Disconnect(true);
        }
        public void Video_Auto_thread(int start_X)
        {
            PGRemoteRPCClient client = new PGRemoteRPCClient();
            int    rc        = client.Connect("", 2799);
            string errMsg    = "";
            string statusMsg = "";

            byte[] DUTResp = new byte[0];
            if (rc < 0)
            {
                return;
            }
            MIPI_Auto_Test Auto_Control = new MIPI_Auto_Test();
            int            excel_X = start_X, excel_Y = 1;

            Auto_Control.Excel_open(output_path, 2);
            PG_Setting_Value.lane      = Test_Condition.lane;
            PG_Setting_Value.hsa       = Test_Condition.hsa;
            PG_Setting_Value.hbp       = Test_Condition.hbp;
            PG_Setting_Value.hfp       = Test_Condition.hfp;
            PG_Setting_Value.hact      = Test_Condition.hact;
            PG_Setting_Value.vsa       = Test_Condition.vsa;
            PG_Setting_Value.vbp       = Test_Condition.vbp;
            PG_Setting_Value.vfp       = Test_Condition.vfp;
            PG_Setting_Value.vact      = Test_Condition.vact;
            PG_Setting_Value.framerate = Test_Condition.framerate;
            PG_Setting_Value.bbp       = Test_Condition.bbp;

            PG_Setting_Value.Calculate_bitrate();
            while (PG_Setting_Value.bitrate < Test_Condition.bitrate)
            {
                client.PGRemoteCmd(RPCCmds.START_EDIT_CONFIG, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_LP_FREQ, (float)18e+6, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_HS_FREQ, (PG_Setting_Value.bitrate) / 2 + 1, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.END_EDIT_CONFIG, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_TIMING_HSYNC, PG_Setting_Value.hsa, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_TIMING_HBPORCH, PG_Setting_Value.hbp, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_TIMING_HFPORCH, PG_Setting_Value.hfp, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_TIMING_HACTIVE, PG_Setting_Value.hact, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_TIMING_VSYNC, PG_Setting_Value.vsa, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_TIMING_VBPORCH, PG_Setting_Value.vbp, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_TIMING_VFPORCH, PG_Setting_Value.vfp, ref errMsg, ref statusMsg);
                client.PGRemoteCmd(RPCCmds.SET_TIMING_VACTIVE, PG_Setting_Value.vact, ref errMsg, ref statusMsg);
                client.MIPICmd(RPCDefs.PACKED_PIXEL_STREAM_888, 0, false, RPCDefs.DT_HS, 0, 1, 0, 0, Test_Condition.picture_path, null, ref errMsg, ref statusMsg);
                client.MIPICmd(RPCDefs.BTA, 0, false, RPCDefs.DT_LP, 0, 0, 0, 0, "", null, ref errMsg, ref statusMsg);
                Thread.Sleep(5000);
                client.MIPICmd(RPCDefs.BTA, 0, false, RPCDefs.DT_LP, 0, 0, 0, 0, "", null, ref errMsg, ref statusMsg);
                client.PGRemoteQuery(RPCCmds.GET_DUT_RESPONSE, 0, ref DUTResp, ref errMsg, ref statusMsg);
                Auto_Control.Write_Excel_cell(excel_Y, excel_X, "HFP " + PG_Setting_Value.hfp + "HBP " + PG_Setting_Value.hbp + "HSA " + PG_Setting_Value.hsa + "Bit Rate " + (PG_Setting_Value.bitrate) / 1000000);
                Auto_Control.Write_Excel_cell(excel_Y, excel_X + 1, BitConverter.ToString(DUTResp));
                excel_Y++;
                client.PGRemoteCmd(RPCCmds.PG_ABORT, ref errMsg, ref statusMsg);
                PG_Setting_Value.hsa += 16;
                PG_Setting_Value.hbp += 16;
                PG_Setting_Value.hfp += 16;
                PG_Setting_Value.Calculate_bitrate();
            }
            client.Disconnect(true);
            Auto_Control.Save_Excel();
            Auto_Control.Close_Excel();
        }