using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using GcDevicePc.Common;

namespace GcDevicePc.GCBuffer
{
    public struct stTemp
    {
        public ushort usCurTemp_Word1;
        public ushort usCurTemp_Word2;
    }

    [StructLayout(LayoutKind.Explicit, Size = 8)]
    public struct UNION_TEMP
    {
        [FieldOffset(0)]
        public float fCurTemp;

        [FieldOffset(0)]
        public stTemp t;
    }


    /// <summary>
    /// 辅助加热区
    /// </summary>
    public struct DevAux
    {
        public ushort u16AuxHeatArea1;		//辅助加热区1
        public bool fTemp_Enable1;          //加热器1升温开关
        public float fSetTemp_HeatArea1;	//加热器1温度设定值
        public float fActualTemp_HeatArea1; //加热器1温室实际值
        public ushort u16AuxHeatArea2;		//辅助加热区2
        public bool fTemp_Enable2;          //加热器2升温开关
        public float fSetTemp_HeatArea2;	//加热器2温度设定值
        public float fActualTemp_HeatArea2; //加热器2温室实际值
    }

    /// <summary>
    /// 色谱柱
    /// </summary>
    public struct DevChromato
    {
        public ushort sChromSelect;		        //选择的色谱柱
        public ushort u16ChromType;			    //色谱柱模式
        public float fHigestTempSet;		    //最高温度
        public float fLengthSet;			    //长度设置
        public float fCalSet;				    //口径设置
        public float fFilmThicknessSet;		    //膜厚设置
        public string sDescribe;				//描述
        public float fPreSetValue;		        //压力设定值
        public float fPreActualValue;	        //压力实际值
        public float fFlowSetValue;		        //流量设定值
        public float fFlowActualValue;	        //流量实际值
        public float fSetAverageLineSpeed;	    //平均线速度
        public float fActualAverageLineSpeed;	//实际线速度
    }

    /// <summary>
    /// 柱箱
    /// </summary>
    public struct DevCol
    {
        public ushort u16KeyCol;			//柱箱开关
        public ushort u16ColProNum;         //程升阶段数
        public float fColTempSet;			//柱箱设定温度
        public float fColTempActual;		//柱箱实际温度
        public float fHigestTemp;			//柱箱最高温度
        public float fBalanceTime;			//平衡时间
        public float fSumProgramTime;		//总程序时间
        public float fBehindRunTemp;		//程升结束之后的运行温度
        public float fBehindRunTime;		//后运行时间
        public ushort u16FastColdTrap;		//快速冷阱
        public ushort u16StartTarp_Type;    //启动冷阱（风扇）//  制冷剂
        public UNION_TEMP fCurTemp;			//实际温度
        public ushort uTcColStage;			//注箱进行程序升温的不同阶段
    }

    /// <summary>
    /// FID
    /// </summary>
    public struct DevFid
    {
        public string sFid;		            //Fid的位置
        public ushort u16SignalValve;	    //信号值
        public ushort u16KeyFire;	        //自动点火
        public ushort u16IsFire;            //是否已经点火
        public ushort u16Zero;		        //调零
        public ushort u16Sensitive;	        //灵敏度
        public ushort u16Polarity;	        //极性
        public ushort u16KeyHeater;		    //加热器开关
        public float fHeaterTempSet;        //加热器设定温度
        public float fHeaterActualTemp;     //加热器实际温度
        public ushort u16KeyH2Flow;		    //氢气流量开关
        public float fSetH2Flow;		    //氢气流量设定值
        public float fActualH2Flow;	        //氢气流量实际值
        public ushort u16KeyAirFlow;		//空气流量开关
        public float fAirFlowSet;			//空气流量设定值
        public float fAirFlowActual;		//空气流量实际值
        public ushort u16KeyTailGas;		//尾吹气开关
        public float fSetTailGas;			//尾吹气设定值
        public float fActualGasFlow;		//尾吹气实际
        public float fColumnFlowReference;  //柱流量参考值
        public ushort u16SigDeduct;		    //信号扣除

        //  ushort u16FilterDepth;		//滤波深度
    }

    /// <summary>
    /// TCD
    /// </summary>
    public struct DevTcd
    {
        public string sTcdLoc;		        //TCD位置
        public float fSigValve;	            //信号值
        public ushort u16Electric;	        //桥流
        public ushort u16Polarity;	        //极性
        public ushort u16AutoZeroSet;       //自动调零
        public float fHeaterTempSet;		//加热器设定值
        public float fHeaterTempActual;	    //加热器实际值
        public float fTaiGasSet;			//尾吹气设定值
        public float fTaiGasActual;		    //尾吹气实际值
        public float fColumnFlowReference;  //柱流量参考
        public ushort u16SigDeduct;		    //信号扣除
        public ushort u16KeyBridgeFlow;     //桥流开关
        public ushort u16FilterDepth;	    //滤波深度
        public ushort u16HeaterSel;	        //加热器
        public ushort u16TaiGasSel;	        //尾吹气
    };

    /// <summary>
    /// 进样口
    /// </summary>
    public struct DevPort
    {
        public string sInjPortLoc;	        //进样口位置
        public bool bHeater;			    //加热器
        public float fHeaterSetTemp;	    //加热器设定温度值
        public float fHeaterSetTempm;	    //加热器modbus设定温度值
        public float fHeaterTempActual;     //加热器实际温度值
        public float fSetPre;			    //设定压力
        public float fPreActual;		    //实际压力
        public float fSetSumFlow;		    //总流量设定值
        public float fSumFlowActual;	    //总流量实际值
        public float fSetPurgeFlow;	        //隔垫吹扫流量设定值
        public float fPurgeFlowActual;	    //隔垫吹扫流量实际值
        public float fSetColumnFlow;	    //柱流量设定值
        public float fColumnFlowActual;	    //柱流量实际值
        public string sWeatherShuntModel;   //分流不分流模式
        public ushort u16SplitRatio;		//分流比
        public float fSplitFlow;			//分流流量
        public bool bCarrierGasSave;	    //载气节省开启
        public ushort u16CarrierGasSave;	//载气节省20ml/min
        public float fSaveGasTime;			//开始等待时间
    }

    /// <summary>
    /// 进样器
    /// </summary>
    public struct DevInj
    {
        public string sSample;			    //配备的进样器
        public float fSampleQuantity;	    //进样量
        public float fInjectorSize;		    //注射器尺寸
        public string sFrontSample;		    //进样前样品
        public string sBSSolventA;		    //进样前溶剂A
        public string sBSSolventB;		    //进样前溶剂B
        public string sASSolventA;		    //进样后溶剂A
        public string sASSolventB;		    //进样后溶剂B
        public ushort u16PushPullTimes;		//推拉针芯次数
        //其他参数
       // UNION_TEMP fCurTemp;			    //进样室当前温度
        public float fSetTemp;			    //进样室设定温度
    }

    /// <summary>
    /// 阀
    /// </summary>
    public struct DevValve
    {
        public bool bValveKey;            //是否有阀存在
        public bool bHeaterKey;           //是否有加热器
        public float fSetTemp;            //设定值
        public float fActualTemp;         //当前值
        public ushort u16ValveSetTime1;
        public ushort u16ValveSetTime2;
        public ushort u16ValveSetTime3;
        public ushort u16ValveSetTime4;
        public ushort u16ValveSetTime5;
        public ushort u16ValveSetTime6;
        public ushort u16ValveSetTime7;
        public ushort u16ValveSetTime8;
        public char ValveStatus;
    }

    public struct DevSignal
    {
        public ushort u16ChannelA; 	//A通道开关  0-关  1-开
        public ushort u16ChannelB; 	//B通道开关
        public ushort[] uDetA;	//A通道检测器
        public ushort[] uDetB;	//B通道检测器
        public ushort[] u16DetTimeLengthA;	//A/B第一时间段的检测时间
        public ushort[] u16DetTimeLengthB;	//A/B第二时间段的检测时间
        public ushort[] u16ZeroA;				//A/B第一时间段归零操作
        public ushort[] u16ZeroB;				//A/B第二时间段归零操作
        public ushort[] u16SaveA;				//A/B第一时间段保存操作
        public ushort[] u16SaveB;				//A/B第二时间段保存操作
       
    }

    public class GCMethodConfig
    {
        string[] sStage = new string[5];

        public const int MAX_VALVE_NUM = 6;  //阀数目
        public const int MAX_CHROMATO_NUM = 2;  //阀数目
        public const int MAX_CHANNEL_NUM = 8;
        public const int MAX_SAMPLE_NUM = 2;  //进样器
        public const int MAX_PORT_NUM = 2;    //进样口
        public const int MAX_FID_NUM = 3;   //FID
        public const int MAX_TCD_NUM = 3;   //TCD

        public DevAux aux = new DevAux();
        public DevChromato[] chrom = new DevChromato[MAX_CHROMATO_NUM];
        public DevCol col = new DevCol();
        public DevFid[] fid = new DevFid[MAX_FID_NUM];
        public DevTcd[] tcd = new DevTcd[MAX_TCD_NUM];
        public DevPort[] port = new DevPort[MAX_PORT_NUM];
        public DevValve[] valve = new DevValve[MAX_VALVE_NUM];
        public DevSignal signal = new DevSignal();
        public DevInj[] sample = new DevInj[MAX_SAMPLE_NUM];

        FileHelper methodconfigini;
        FileHelper savemethodconfig;

        public string savefilename = "";
        public string saveasfilename = "";

        public GCMethodConfig()
        {
            InitMethodConfig();

            sStage[0] = "Init";
            sStage[1] = "1st";
            sStage[2] = "2nd";
            sStage[3] = "3rd";

        }

        /// <summary>
        /// 初始化辅助加热器
        /// </summary>
        private void InitDevAux()
        {
            aux.u16AuxHeatArea1 = 0;
            aux.fTemp_Enable1 = false;
            aux.fSetTemp_HeatArea1=0.0f;
            aux.fActualTemp_HeatArea1 =0.0f;
            aux.u16AuxHeatArea2 =0;
            aux.fTemp_Enable2 = false;
            aux.fSetTemp_HeatArea2 = 0.0f;
            aux.fActualTemp_HeatArea2 = 0.0f;
        }

        /// <summary>
        ///  色谱柱
        /// </summary>
        private void InitDevChrom()
        {
            int i;

            for (i = 0; i < MAX_CHROMATO_NUM; i++ )
            {
                chrom[i].sChromSelect = 0;
                chrom[i].u16ChromType = 0;
                chrom[i].fHigestTempSet = 0.0f;
                chrom[i].fLengthSet = 0.0f;
                chrom[i].fCalSet = 0.0f;
                chrom[i].fFilmThicknessSet = 0.0f;
                chrom[i].sDescribe = "色谱柱";
                chrom[i].fPreSetValue = 0.0f;
                chrom[i].fPreActualValue = 0.0f;
                chrom[i].fFlowSetValue = 0.0f;
                chrom[i].fFlowActualValue = 0.0f;
                chrom[i].fSetAverageLineSpeed = 0.0f;
                chrom[i].fActualAverageLineSpeed = 0.0f;
            }
        }

        /// <summary>
        /// 柱箱
        /// </summary>
        private void InitDevCol()
        {
            col.u16KeyCol = 0; ;			//柱箱开关
            col.u16ColProNum = 0; ;         //程升阶段数
            col.fColTempSet = 0.0f;			//柱箱设定温度
            col.fColTempActual = 0.0f;		//柱箱实际温度
            col.fHigestTemp = 0.0f;			//柱箱最高温度
            col.fBalanceTime = 0.0f;		//平衡时间
            col.fSumProgramTime = 0.0f;		//总程序时间
            col.fBehindRunTemp = 0.0f;		//程升结束之后的运行温度
            col.fBehindRunTime = 0.0f;		//后运行时间
            col.u16FastColdTrap = 0;		//快速冷阱
            col.u16StartTarp_Type = 0;      //启动冷阱（风扇）//  制冷剂
            col.uTcColStage = 0;			//注箱进行程序升温的不同阶段
        }

        /// <summary>
        /// FID
        /// </summary>
        private void InitDevFid()
        {

            for(int i = 0; i < 3; i++)
            {
                switch (i)
                {
                    case 0:
                        fid[i].sFid = "前";		//Fid的位置
                        break;
                    case 1:
                        fid[i].sFid = "中";		//Fid的位置
                        break;
                    case 2:
                        fid[i].sFid = "后";		//Fid的位置
                        break;
                    default:
                        fid[i].sFid = "前";		//Fid的位置
                        break;
                }
                fid[i].u16SignalValve =0;	//信号值
                fid[i].u16KeyFire = 0;	//自动点火
                fid[i].u16IsFire = 0;    //是否已经点火
                fid[i].u16Zero = 0; ;		//调零
                fid[i].u16Sensitive = 0;	//灵敏度
                fid[i].u16Polarity = 0;	//极性
                fid[i].u16KeyHeater = 0;		//加热器开关
                fid[i].fHeaterTempSet =0.0f;  //加热器设定温度
                fid[i].fHeaterActualTemp = 0.0f;//加热器实际温度
                fid[i].u16KeyH2Flow = 0;		//氢气流量开关
                fid[i].fSetH2Flow = 0.0f;		//氢气流量设定值
                fid[i].fActualH2Flow = 0.0f;	//氢气流量实际值
                fid[i].u16KeyAirFlow = 0;		//空气流量开关
                fid[i].fAirFlowSet = 0.0f;			//空气流量设定值
                fid[i].fAirFlowActual = 0.0f;		//空气流量实际值
                fid[i].u16KeyTailGas = 0;			//尾吹气开关
                fid[i].fSetTailGas = 0.0f;			//尾吹气设定值
                fid[i].fActualGasFlow = 0.0f;		//尾吹气实际
                fid[i].fColumnFlowReference = 0.0f;//柱流量参考值
                fid[i].u16SigDeduct = 0;		//信号扣除
            }
        }

        /// <summary>
        /// TCD
        /// </summary>
        private void InitDevTcd()
        {
            for(int i =0; i < 3; i++)
            {
                switch (i)
                {
                    case 0:
                        tcd[i].sTcdLoc = "前";
                        break;
                    case 1:
                        tcd[i].sTcdLoc = "中";		//Fid的位置
                        break;
                    case 2:
                        tcd[i].sTcdLoc = "后";		//Fid的位置
                        break;
                    default:
                        tcd[i].sTcdLoc = "前";		//Fid的位置
                        break;
                }

                tcd[i].fSigValve = 0.0f;	         //信号值
                tcd[i].u16Electric = 0;	     //桥流
                tcd[i].u16Polarity = 0;	     //极性
                tcd[i].u16AutoZeroSet = 0;      //自动调零
                tcd[i].fHeaterTempSet = 0.0f;		 //加热器设定值
                tcd[i].fHeaterTempActual = 0.0f;	 //加热器实际值
                tcd[i].fTaiGasSet = 0.0f;			 //尾吹气设定值
                tcd[i].fTaiGasActual = 0.0f;		 //尾吹气实际值
                tcd[i].fColumnFlowReference = 0.0f; //柱流量参考
                tcd[i].u16SigDeduct = 0;		 //信号扣除
                tcd[i].u16KeyBridgeFlow = 0;    //桥流开关
                tcd[i].u16FilterDepth = 0;	     //滤波深度
                tcd[i].u16HeaterSel = 0;	     //加热器
                tcd[i].u16TaiGasSel = 0;	     //尾吹气
            }
        }

        /// <summary>
        /// 进样口
        /// </summary>
        private void InitDevPort()
        {
            int i =0;
            for(i = 0; i < 2; i++)
            {

                if(i==0)
                {
                    port[i].sInjPortLoc = "前";
                }
                else
                {
                    port[i].sInjPortLoc = "后";
                }

                port[i].bHeater = false;			//加热器
                port[i].fHeaterSetTemp = 0.0f;	//加热器设定温度值
                port[i].fHeaterSetTempm = 0.0f;	//加热器modbus设定温度值
                port[i].fHeaterTempActual = 0.0f ;//加热器实际温度值
                port[i].fSetPre = 0.0f;			//设定压力
                port[i].fPreActual = 0.0f;		//实际压力
                port[i].fSetSumFlow = 0.0f;		//总流量设定值
                port[i].fSumFlowActual = 0.0f;	//总流量实际值
                port[i].fSetPurgeFlow = 0.0f;	//隔垫吹扫流量设定值
                port[i].fPurgeFlowActual = 0.0f;	//隔垫吹扫流量实际值
                port[i].fSetColumnFlow = 0.0f;	//柱流量设定值
                port[i].fColumnFlowActual = 0.0f;	//柱流量实际值
                port[i].sWeatherShuntModel = "不分流"; //分流不分流模式
                port[i].u16SplitRatio = 0;			//分流比
                port[i].fSplitFlow = 0.0f;			//分流流量
                port[i].bCarrierGasSave = false;	    //载气节省开启
                port[i].u16CarrierGasSave = 0;		//载气节省20ml/min
                port[i].fSaveGasTime = 0.0f;			//开始等待时间
            }
      
        }

        /// <summary>
        /// 阀
        /// </summary>
        private void InitDevValue()
        {
            for(int i = 0; i< MAX_VALVE_NUM; i++)
            {
                 valve[i].bValveKey = false;            //是否有阀存在
                 valve[i].bHeaterKey = false;           //是否有加热器
                 valve[i].fSetTemp = 0.0f;            //设定值
                 valve[i].fActualTemp = 0.0f;         //当前值
                 valve[i].u16ValveSetTime1 = 0;
                 valve[i].u16ValveSetTime2 = 0;
                 valve[i].u16ValveSetTime3 = 0;
                 valve[i].u16ValveSetTime4 = 0;
                 valve[i].u16ValveSetTime5 = 0;
                 valve[i].u16ValveSetTime6 = 0;
                 valve[i].u16ValveSetTime7 = 0;
                 valve[i].u16ValveSetTime8 = 0;
                 valve[i].ValveStatus = '0';
            }
        }

        /// <summary>
        /// 信号通道
        /// </summary>
        private void InitDevSignal()
        {

           signal.u16ChannelA=0; 	//A通道开关  0-关  1-开
           signal.u16ChannelB = 0; 	//B通道开关
           signal.uDetA = new ushort[MAX_CHANNEL_NUM];	//A通道检测器
           signal.uDetB = new ushort[MAX_CHANNEL_NUM];	//B通道检测器
           signal.u16DetTimeLengthA = new ushort[MAX_CHANNEL_NUM];	//A/B第一时间段的检测时间
           signal.u16DetTimeLengthB = new ushort[MAX_CHANNEL_NUM];	//A/B第二时间段的检测时间
           signal.u16ZeroA = new ushort[MAX_CHANNEL_NUM];				//A/B第一时间段归零操作
           signal.u16ZeroB = new ushort[MAX_CHANNEL_NUM];				//A/B第二时间段归零操作
           signal.u16SaveA = new ushort[MAX_CHANNEL_NUM];				//A/B第一时间段保存操作
           signal.u16SaveB = new ushort[MAX_CHANNEL_NUM];				//A/B第二时间段保存操作
        }
        
        /// <summary>
        /// 进样器
        /// </summary>
        private void InitDevSample()
        {
            for(int i =0; i < MAX_SAMPLE_NUM; i++)
            {
                switch(i)
                {
                    case 0:
                        sample[i].sSample ="前";			//配备的进样器
                        break;
                    case 1:
                        sample[i].sSample ="后";			//配备的进样器
                        break;
                    default:
                        sample[i].sSample ="前";			//配备的进样器
                        break;
                }
                sample[i].fSampleQuantity = 0.0f;	//进样量
                sample[i].fInjectorSize = 0.0f;		//注射器尺寸
                sample[i].sFrontSample = "酒精";		//进样前样品
                sample[i].sBSSolventA = "XX";		//进样前溶剂A
                sample[i].sBSSolventB = "XX";		//进样前溶剂B
                sample[i].sASSolventA = "XX";		//进样后溶剂A
                sample[i].sASSolventB = "XX";		//进样后溶剂B
                sample[i].u16PushPullTimes = 0;		//推拉针芯次数
               // sample[i].fCurTemp = 0.0f;			//进样室当前温度
                sample[i].fSetTemp = 0.0f;			//进样室设定温度
            }
        }

        public void InitMethodConfig()
        {
            InitDevAux();
            InitDevChrom();
            InitDevCol();
            InitDevFid();
            InitDevTcd();
            InitDevPort();
            InitDevValue();
            InitDevSignal();
            InitDevSample();
        }

        /// <summary>
        /// 设置方法文件
        /// </summary>
        /// <param name="filename"></param>
        public void SetMethodConfigName(string filename)
        {
            methodconfigini = new FileHelper(filename);
            this.savefilename = filename;
        }

        /// <summary>
        /// 设置方法保存文件
        /// </summary>
        /// <param name="filename"></param>
        public void SetMethodSaveName(string filename)
        {
            savemethodconfig = new FileHelper(filename);
            this.saveasfilename = filename;
        }

        /// <summary>
        /// 获取进样口参数
        /// </summary>
        public void GetDevInjPortAllPara()
        {
            string strKey = "";
            ushort iDefault = 0;
            float fDefault = 0.0f;
            const int cFront = 0;
            const int cBehind = 1;

            strKey = "前进样口";
            port[cFront].sInjPortLoc = methodconfigini.GetProfileString(strKey, "进样口");
            port[cFront].bHeater = Convert.ToBoolean(methodconfigini.GetProfileInt(strKey, "加热", iDefault));
            port[cFront].fHeaterSetTemp = methodconfigini.GetProfileFloat(strKey, "设定温度", fDefault);
            port[cFront].fHeaterSetTempm = methodconfigini.GetProfileFloat(strKey, "设定温度", fDefault);
            port[cFront].fSetPre = methodconfigini.GetProfileFloat(strKey, "设定压力", fDefault);
            port[cFront].fSetSumFlow = methodconfigini.GetProfileFloat(strKey, "设定总流量", fDefault);
            port[cFront].fSetPurgeFlow = methodconfigini.GetProfileFloat(strKey, "隔垫吹扫流量设定值", fDefault);
            port[cFront].fSetColumnFlow = methodconfigini.GetProfileFloat(strKey, "柱流量设定值", fDefault);
            port[cFront].sWeatherShuntModel = methodconfigini.ReadValue(strKey, "分流不分流模式");
            port[cFront].u16SplitRatio = Convert.ToUInt16(methodconfigini.GetProfileInt(strKey, "分流比", iDefault));
            port[cFront].fSplitFlow = methodconfigini.GetProfileFloat(strKey, "分流流量", fDefault);
            port[cFront].bCarrierGasSave = Convert.ToBoolean(methodconfigini.GetProfileInt(strKey, "载气开启", iDefault));
            port[cFront].u16CarrierGasSave = Convert.ToUInt16(methodconfigini.GetProfileInt(strKey, "载气节省量", iDefault));
            port[cFront].fSaveGasTime = methodconfigini.GetProfileFloat(strKey, "载气节省开始时间", fDefault);

            strKey = "后进样口";
            port[cBehind].sInjPortLoc = methodconfigini.GetProfileString(strKey, "进样口");
            port[cBehind].bHeater = Convert.ToBoolean(methodconfigini.GetProfileInt(strKey, "加热", iDefault));
            port[cBehind].fHeaterSetTemp = methodconfigini.GetProfileFloat(strKey, "设定温度", fDefault);
            port[cBehind].fHeaterSetTempm = methodconfigini.GetProfileFloat(strKey, "设定温度", fDefault);
            port[cBehind].fSetPre = methodconfigini.GetProfileFloat(strKey, "设定压力", fDefault);
            port[cBehind].fSetSumFlow = methodconfigini.GetProfileFloat(strKey, "设定总流量", fDefault);
            port[cBehind].fSetPurgeFlow = methodconfigini.GetProfileFloat(strKey, "隔垫吹扫流量设定值", fDefault);
            port[cBehind].fSetColumnFlow = methodconfigini.GetProfileFloat(strKey, "柱流量设定值", fDefault);
            port[cBehind].sWeatherShuntModel = methodconfigini.ReadValue(strKey, "分流不分流模式");
            port[cBehind].u16SplitRatio = Convert.ToUInt16(methodconfigini.GetProfileInt(strKey, "分流比", iDefault));
            port[cBehind].fSplitFlow = methodconfigini.GetProfileFloat(strKey, "分流流量", fDefault);
            port[cBehind].bCarrierGasSave = Convert.ToBoolean(methodconfigini.GetProfileInt(strKey, "载气开启", iDefault));
            port[cBehind].u16CarrierGasSave = Convert.ToUInt16(methodconfigini.GetProfileInt(strKey, "载气节省量", iDefault));
            port[cBehind].fSaveGasTime = methodconfigini.GetProfileFloat(strKey, "载气节省开始时间", fDefault);
            
        }

        /// <summary>
        /// 设置进样口参数
        /// </summary>
        public void SetDevInjPortAllPara()
        {
            string strKey = "";
            const int cFront = 0;
            const int cBehind = 1;

            strKey = "前进样口";
            savemethodconfig.WriteValue(strKey, "进样口", port[cFront].sInjPortLoc);
            savemethodconfig.WriteProfileBool(strKey, "加热", port[cFront].bHeater);
            savemethodconfig.WriteValue(strKey, "设定温度",port[cFront].fHeaterSetTemp.ToString());
            savemethodconfig.WriteValue(strKey, "设定压力", port[cFront].fSetPre.ToString());
            savemethodconfig.WriteValue(strKey, "设定总流量",port[cFront].fSetSumFlow.ToString());
            savemethodconfig.WriteValue(strKey, "隔垫吹扫流量设定值", port[cFront].fSetPurgeFlow.ToString());
            savemethodconfig.WriteValue(strKey, "柱流量设定值", port[cFront].fSetColumnFlow.ToString());
            savemethodconfig.WriteValue(strKey, "分流不分流模式", port[cFront].sWeatherShuntModel.ToString());
            savemethodconfig.WriteValue(strKey, "分流比", port[cFront].u16SplitRatio.ToString());
            savemethodconfig.WriteValue(strKey, "分流流量", port[cFront].fSplitFlow.ToString());
            savemethodconfig.WriteProfileBool(strKey, "载气开启", port[cFront].bCarrierGasSave);
            savemethodconfig.WriteValue(strKey, "载气节省量", port[cFront].u16CarrierGasSave.ToString());
            savemethodconfig.WriteValue(strKey, "载气节省开始时间", port[cFront].fSaveGasTime.ToString());
            
            strKey = "后进样口";
            savemethodconfig.WriteValue(strKey, "进样口", port[cBehind].sInjPortLoc);
            savemethodconfig.WriteProfileBool(strKey, "加热", port[cBehind].bHeater);
            savemethodconfig.WriteValue(strKey, "设定温度", port[cBehind].fHeaterSetTemp.ToString());
            savemethodconfig.WriteValue(strKey, "设定压力", port[cBehind].fSetPre.ToString());
            savemethodconfig.WriteValue(strKey, "设定总流量", port[cBehind].fSetSumFlow.ToString());
            savemethodconfig.WriteValue(strKey, "隔垫吹扫流量设定值", port[cBehind].fSetPurgeFlow.ToString());
            savemethodconfig.WriteValue(strKey, "柱流量设定值", port[cBehind].fSetColumnFlow.ToString());
            savemethodconfig.WriteValue(strKey, "分流不分流模式", port[cBehind].sWeatherShuntModel.ToString());
            savemethodconfig.WriteValue(strKey, "分流比", port[cBehind].u16SplitRatio.ToString());
            savemethodconfig.WriteValue(strKey, "分流流量", port[cBehind].fSplitFlow.ToString());
            savemethodconfig.WriteProfileBool(strKey, "载气开启", port[cBehind].bCarrierGasSave);
            savemethodconfig.WriteValue(strKey, "载气节省量", port[cBehind].u16CarrierGasSave.ToString());
            savemethodconfig.WriteValue(strKey, "载气节省开始时间", port[cBehind].fSaveGasTime.ToString());
            

        }


        /// <summary>
        /// 获取辅助加热器
        /// </summary>
        public void GetDevAux()
        {
            const int iDefault = 0;
	        const float fDefault = 0.0f;
	        string sAppName = "辅助";
            aux.u16AuxHeatArea1 = methodconfigini.GetProfileInt(sAppName, "辅助加热区1", iDefault);
            aux.fTemp_Enable1 = (methodconfigini.GetProfileInt(sAppName, "加热开关", iDefault) == 1) ? true : false;
            aux.fSetTemp_HeatArea1 = methodconfigini.GetProfileFloat(sAppName, "辅助加热区1设定温度", fDefault);
            aux.u16AuxHeatArea2 = methodconfigini.GetProfileInt(sAppName, "辅助加热区2", iDefault);
            aux.fTemp_Enable2 = (methodconfigini.GetProfileInt(sAppName, "加热开关", iDefault) == 1) ? true : false;
            aux.fSetTemp_HeatArea2 = methodconfigini.GetProfileFloat(sAppName, "辅助加热区2设定温度", fDefault);
        }

        /// <summary>
        /// 设置辅助加热器
        /// </summary>
        public void SetDevAux()
        {
            string sAppName = "辅助";
            savemethodconfig.WriteProfileInt(sAppName, "辅助加热区1", aux.u16AuxHeatArea1);
            savemethodconfig.WriteProfileInt(sAppName, "加热开关", (aux.fTemp_Enable1 || aux.fTemp_Enable2) ? 1 : 0);
            savemethodconfig.WriteProfileFloat(sAppName, "辅助加热区1设定温度", aux.fSetTemp_HeatArea1);
            savemethodconfig.WriteProfileInt(sAppName, "加热开关", (aux.fTemp_Enable1 || aux.fTemp_Enable2) ? 1 : 0);
            savemethodconfig.WriteProfileInt(sAppName, "辅助加热区2", aux.u16AuxHeatArea2);
            savemethodconfig.WriteProfileFloat(sAppName, "辅助加热区2设定温度", aux.fSetTemp_HeatArea2);
        }

        /// <summary>
        /// 获取进样器参数
        /// </summary>
        /// <param name="strCurDev"></param>
        public void GetSampleAllPara()
        {
            ushort iDefault = 0;
            float fDefault = 0.0f;
            int cFront = 0;
            int cBehind = 1;

            sample[cFront].sSample = methodconfigini.GetProfileString("前进样器", "进样器");
            sample[cFront].fSampleQuantity = methodconfigini.GetProfileFloat("前进样器", "进样量", fDefault);
            sample[cFront].fInjectorSize = methodconfigini.GetProfileFloat("前进样器", "注射器尺寸", fDefault);
            sample[cFront].sFrontSample = methodconfigini.GetProfileString("前进样器", "进样前样品");
            sample[cFront].sBSSolventA = methodconfigini.GetProfileString("前进样器", "进样前溶剂A");
            sample[cFront].sBSSolventB = methodconfigini.GetProfileString("前进样器", "进样前溶剂B");
            sample[cFront].u16PushPullTimes = methodconfigini.GetProfileInt("前进样器", "推拉针芯次数", iDefault);
            sample[cFront].sASSolventA = methodconfigini.GetProfileString("前进样器", "进样后溶剂A");
            sample[cFront].sASSolventB = methodconfigini.GetProfileString("前进样器", "进样后溶剂B");
            sample[cBehind].sSample = methodconfigini.GetProfileString("后进样器", "进样器");
            sample[cBehind].fSampleQuantity = methodconfigini.GetProfileFloat("后进样器", "进样量", fDefault);
            sample[cBehind].fInjectorSize = methodconfigini.GetProfileFloat("后进样器", "注射器尺寸", fDefault);
            sample[cBehind].sFrontSample = methodconfigini.ReadValue("后进样器", "进样前样品");
            sample[cBehind].sBSSolventA = methodconfigini.ReadValue("后进样器", "进样前溶剂A");
            sample[cBehind].sBSSolventB = methodconfigini.ReadValue("后进样器", "进样前溶剂B");
            sample[cBehind].u16PushPullTimes = methodconfigini.GetProfileInt("后进样器", "推拉针芯次数", iDefault);
            sample[cBehind].sASSolventA = methodconfigini.ReadValue("后进样器", "进样后溶剂A");
            sample[cBehind].sASSolventB = methodconfigini.ReadValue("后进样器", "进样后溶剂B");
     
        }

        /// <summary>
        /// 设置进样器参数
        /// </summary>
        public void SetSampleAllPara()
        {
            string strCurDev = "";
            int cFront = 0;
            int cBehind = 1;
      
            strCurDev = "前进样器";
            savemethodconfig.WriteProfileString(strCurDev, "进样器", sample[cFront].sSample);
            savemethodconfig.WriteProfileFloat(strCurDev, "进样量", sample[cFront].fSampleQuantity);
            savemethodconfig.WriteProfileFloat(strCurDev, "注射器尺寸", sample[cFront].fInjectorSize);
            savemethodconfig.WriteProfileString(strCurDev, "进样前样品", sample[cFront].sFrontSample);
            savemethodconfig.WriteProfileString(strCurDev, "进样前溶剂A", sample[cFront].sBSSolventA);
            savemethodconfig.WriteProfileString(strCurDev, "进样前溶剂B", sample[cFront].sBSSolventB);
            savemethodconfig.WriteProfileInt(strCurDev, "推拉针芯次数", sample[cFront].u16PushPullTimes);
            savemethodconfig.WriteProfileString(strCurDev, "进样后溶剂A", sample[cFront].sASSolventA);
            savemethodconfig.WriteProfileString(strCurDev, "进样后溶剂B", sample[cFront].sASSolventB);
            
            strCurDev = "后进样器";
            savemethodconfig.WriteProfileString(strCurDev, "进样器", sample[cBehind].sSample);
            savemethodconfig.WriteProfileFloat(strCurDev, "进样量", sample[cBehind].fSampleQuantity);
            savemethodconfig.WriteProfileFloat(strCurDev, "注射器尺寸", sample[cBehind].fInjectorSize);
            savemethodconfig.WriteProfileString(strCurDev, "进样前样品", sample[cBehind].sFrontSample);
            savemethodconfig.WriteProfileString(strCurDev, "进样前溶剂A", sample[cBehind].sBSSolventA);
            savemethodconfig.WriteProfileString(strCurDev, "进样前溶剂B", sample[cBehind].sBSSolventB);
            savemethodconfig.WriteProfileInt(strCurDev, "推拉针芯次数", sample[cBehind].u16PushPullTimes);
            savemethodconfig.WriteProfileString(strCurDev, "进样后溶剂A", sample[cBehind].sASSolventA);
            savemethodconfig.WriteProfileString(strCurDev, "进样后溶剂B", sample[cBehind].sASSolventB);
        }

        /// <summary>
        /// 获取进样阀参数
        /// </summary>
        public void GetInjValveAllPara()
        {
            ushort iDefault = 0;
            float fDefault = 0.0f;
            string sAppName = "阀";
            string strKeyName = "阀";

            for (int i = 0; i < MAX_VALVE_NUM; i++)
            {
                int channel = i + 1;
                valve[i].bValveKey = Convert.ToBoolean(methodconfigini.GetProfileInt(sAppName, strKeyName + channel.ToString() + "开关", iDefault));
                valve[i].bHeaterKey = Convert.ToBoolean(methodconfigini.GetProfileInt(sAppName, strKeyName + channel.ToString() + "加热开关", iDefault));
                valve[i].fSetTemp = methodconfigini.GetProfileFloat(sAppName, strKeyName + channel.ToString() + "设定温度", fDefault);
                valve[i].u16ValveSetTime1 = methodconfigini.GetProfileInt(sAppName, strKeyName + channel.ToString() + "设定时间1", iDefault);
                valve[i].u16ValveSetTime2 = methodconfigini.GetProfileInt(sAppName, strKeyName + channel.ToString() + "设定时间2", iDefault);
                valve[i].u16ValveSetTime3 = methodconfigini.GetProfileInt(sAppName, strKeyName + channel.ToString() + "设定时间3", iDefault);
                valve[i].u16ValveSetTime4 = methodconfigini.GetProfileInt(sAppName, strKeyName + channel.ToString() + "设定时间4", iDefault);
                valve[i].u16ValveSetTime5 = methodconfigini.GetProfileInt(sAppName, strKeyName + channel.ToString() + "设定时间5", iDefault);
                valve[i].u16ValveSetTime6 = methodconfigini.GetProfileInt(sAppName, strKeyName + channel.ToString() + "设定时间6", iDefault);
                valve[i].u16ValveSetTime7 = methodconfigini.GetProfileInt(sAppName, strKeyName + channel.ToString() + "设定时间7", iDefault);
                valve[i].u16ValveSetTime8 = methodconfigini.GetProfileInt(sAppName, strKeyName + channel.ToString() + "设定时间8", iDefault);
            }
        }

        /// <summary>
        /// 设置进样阀参数
        /// </summary>
        public void SetInjValveAllPara()
        {
            string sAppName = "阀";
            string strKeyName = "阀";

            for (int i = 0; i < MAX_VALVE_NUM; i++)
            {
                int channel = i + 1;
                savemethodconfig.WriteProfileBool(sAppName, strKeyName + channel.ToString() + "开关", valve[i].bValveKey);
                savemethodconfig.WriteProfileBool(sAppName, strKeyName + channel.ToString() + "加热开关", valve[i].bHeaterKey);
                savemethodconfig.WriteProfileFloat(sAppName, strKeyName + channel.ToString() + "设定温度",valve[i].fSetTemp);
                savemethodconfig.WriteProfileInt(sAppName, strKeyName + channel.ToString() + "设定时间1", valve[i].u16ValveSetTime1);
                savemethodconfig.WriteProfileInt(sAppName, strKeyName + channel.ToString() + "设定时间2", valve[i].u16ValveSetTime2);
                savemethodconfig.WriteProfileInt(sAppName, strKeyName + channel.ToString() + "设定时间3", valve[i].u16ValveSetTime3);
                savemethodconfig.WriteProfileInt(sAppName, strKeyName + channel.ToString() + "设定时间4", valve[i].u16ValveSetTime4);
                savemethodconfig.WriteProfileInt(sAppName, strKeyName + channel.ToString() + "设定时间5", valve[i].u16ValveSetTime5);
                savemethodconfig.WriteProfileInt(sAppName, strKeyName + channel.ToString() + "设定时间6", valve[i].u16ValveSetTime6);
                savemethodconfig.WriteProfileInt(sAppName, strKeyName + channel.ToString() + "设定时间7", valve[i].u16ValveSetTime7);
                savemethodconfig.WriteProfileInt(sAppName, strKeyName + channel.ToString() + "设定时间8", valve[i].u16ValveSetTime8);
            }
        }

        /// <summary>
        /// 获取色谱柱
        /// </summary>
        public void GetChromAllPara()
        {
            const int iDefault = 0;
            const float fDefault = 0.0f;
            string sAppName = null;
            const int cFront = 0;
            const int cBehind = 1;

            sAppName = "前色谱柱";
            chrom[cFront].sChromSelect = methodconfigini.GetProfileInt(sAppName, "色谱柱", iDefault);
            chrom[cFront].u16ChromType = methodconfigini.GetProfileInt(sAppName, "类型", iDefault);
            chrom[cFront].fHigestTempSet = methodconfigini.GetProfileFloat(sAppName, "最高温度", fDefault);
            chrom[cFront].fLengthSet = methodconfigini.GetProfileFloat(sAppName, "长度", fDefault);
            chrom[cFront].fCalSet = methodconfigini.GetProfileFloat(sAppName, "口径", fDefault);
            chrom[cFront].fFilmThicknessSet = methodconfigini.GetProfileFloat(sAppName, "膜厚", fDefault);
            chrom[cFront].sDescribe = methodconfigini.GetProfileString(sAppName, "描述");
            chrom[cFront].fPreSetValue = methodconfigini.GetProfileFloat(sAppName, "压力设定值", fDefault);
            chrom[cFront].fFlowSetValue = methodconfigini.GetProfileFloat(sAppName, "流量设定值", fDefault);
            chrom[cFront].fSetAverageLineSpeed = methodconfigini.GetProfileFloat(sAppName, "平均线速度设定值", fDefault);
            
            sAppName = "后色谱柱";
            chrom[cBehind].sChromSelect = methodconfigini.GetProfileInt(sAppName, "色谱柱", iDefault);
            chrom[cBehind].u16ChromType = methodconfigini.GetProfileInt(sAppName, "类型", iDefault);
            chrom[cBehind].fHigestTempSet = methodconfigini.GetProfileFloat(sAppName, "最高温度", fDefault);
            chrom[cBehind].fLengthSet = methodconfigini.GetProfileFloat(sAppName, "长度", fDefault);
            chrom[cBehind].fCalSet = methodconfigini.GetProfileFloat(sAppName, "口径", fDefault);
            chrom[cBehind].fFilmThicknessSet = methodconfigini.GetProfileFloat(sAppName, "膜厚", fDefault);
            chrom[cBehind].sDescribe = methodconfigini.GetProfileString(sAppName, "描述");
            chrom[cBehind].fPreSetValue = methodconfigini.GetProfileFloat(sAppName, "压力设定值", fDefault);
            chrom[cBehind].fFlowSetValue = methodconfigini.GetProfileFloat(sAppName, "流量设定值", fDefault);
            chrom[cBehind].fSetAverageLineSpeed = methodconfigini.GetProfileFloat(sAppName, "平均线速度设定值", fDefault);
            
        }

        /// <summary>
        /// 设置色谱柱
        /// </summary>
        public void SetChromAllPara()  
        {
            string sAppName = "色谱柱";
            const int cFront = 0;
            const int cBehind = 1;

            savemethodconfig.WriteProfileInt(sAppName, "色谱柱", chrom[cFront].sChromSelect);
            savemethodconfig.WriteProfileInt(sAppName, "类型", chrom[cFront].u16ChromType);
            savemethodconfig.WriteProfileFloat(sAppName, "最高温度",chrom[cFront].fHigestTempSet);
            savemethodconfig.WriteProfileFloat(sAppName, "长度", chrom[cFront].fLengthSet);
            savemethodconfig.WriteProfileFloat(sAppName, "口径", chrom[cFront].fCalSet);
            savemethodconfig.WriteProfileFloat(sAppName, "膜厚", chrom[cFront].fFilmThicknessSet);
            savemethodconfig.WriteProfileString(sAppName, "描述", chrom[cFront].sDescribe);
            savemethodconfig.WriteProfileFloat(sAppName, "压力设定值", chrom[cFront].fPreSetValue);
            savemethodconfig.WriteProfileFloat(sAppName, "流量设定值", chrom[cFront].fFlowSetValue);
            savemethodconfig.WriteProfileFloat(sAppName, "平均线速度设定值", chrom[cFront].fSetAverageLineSpeed);
            savemethodconfig.WriteProfileInt(sAppName, "色谱柱", chrom[cBehind].sChromSelect);
            savemethodconfig.WriteProfileInt(sAppName, "类型", chrom[cBehind].u16ChromType);
            savemethodconfig.WriteProfileFloat(sAppName, "最高温度", chrom[cBehind].fHigestTempSet);
            savemethodconfig.WriteProfileFloat(sAppName, "长度", chrom[cBehind].fLengthSet);
            savemethodconfig.WriteProfileFloat(sAppName, "口径", chrom[cBehind].fCalSet);
            savemethodconfig.WriteProfileFloat(sAppName, "膜厚", chrom[cBehind].fFilmThicknessSet);
            savemethodconfig.WriteProfileString(sAppName, "描述", chrom[cBehind].sDescribe);
            savemethodconfig.WriteProfileFloat(sAppName, "压力设定值", chrom[cBehind].fPreSetValue);
            savemethodconfig.WriteProfileFloat(sAppName, "流量设定值", chrom[cBehind].fFlowSetValue);
            savemethodconfig.WriteProfileFloat(sAppName, "平均线速度设定值", chrom[cBehind].fSetAverageLineSpeed);
            

        }

        /// <summary>
        /// 获取柱箱部分配置
        /// </summary>
        public void GetColTableElseAllPara()
        {
            ushort iDefault = 0;
            float fDefault = 0.0f;
            string sAppName = "柱箱";

            col.u16KeyCol = methodconfigini.GetProfileInt(sAppName, "柱箱开关", iDefault);
            col.fHigestTemp = methodconfigini.GetProfileFloat(sAppName, "最高温度", fDefault);
            col.fBalanceTime = methodconfigini.GetProfileFloat(sAppName, "平衡时间", fDefault);
            col.u16FastColdTrap = methodconfigini.GetProfileInt(sAppName, "快速冷阱", iDefault);
            col.u16StartTarp_Type = methodconfigini.GetProfileInt(sAppName, "冷却方式", iDefault);
            col.fColTempSet = methodconfigini.GetProfileFloat(sAppName, "设定温度", fDefault); 
            col.fBehindRunTemp = methodconfigini.GetProfileFloat(sAppName, "后运行温度", fDefault);
            col.fBehindRunTime = methodconfigini.GetProfileFloat(sAppName, "后运行时间", fDefault);

            sAppName = "程升表";
            col.u16ColProNum = methodconfigini.GetProfileInt(sAppName, "阶段数目", iDefault);

        }

        /// <summary>
        /// 设置柱箱
        /// </summary>
        public void SetColTableElseAllPara()
        {
            string sAppName = "柱箱";
            savemethodconfig.WriteProfileInt(sAppName, "柱箱", col.u16KeyCol);
            savemethodconfig.WriteProfileFloat(sAppName, "最高温度", col.fHigestTemp);
            savemethodconfig.WriteProfileFloat(sAppName, "平衡时间", col.fBalanceTime);
            savemethodconfig.WriteProfileInt(sAppName, "快速冷阱", col.u16FastColdTrap);
            savemethodconfig.WriteProfileInt(sAppName, "冷却方式", col.u16StartTarp_Type);
            savemethodconfig.WriteProfileInt(sAppName, "柱箱开关", col.u16KeyCol);
            savemethodconfig.WriteProfileFloat(sAppName, "设定温度", col.fColTempSet);
            savemethodconfig.WriteProfileFloat(sAppName, "后运行温度",col.fBehindRunTemp);
            savemethodconfig.WriteProfileFloat(sAppName, "后运行时间",col.fBehindRunTime);

            sAppName = "程升表";
            savemethodconfig.WriteProfileInt(sAppName, "阶段数目", col.u16ColProNum);
        }


        public struct stRunTableVal
        {
            public float StartTemp;  //开始温度
            public float TargetTemp; //目标温度
            public float HeatSpeed;  //上升速度
            public float BalanceTime;//平衡时间
        }

        /// <summary>
        /// 获取柱箱的程升表的配置
        /// </summary>
        /// <param name="stValue"></param>
        /// <param name="u16Stage"></param>
        public void  GetColTableStageVal(ref stRunTableVal stValue, ushort u16Stage)
        {
            string strStage;

            if (u16Stage >= 4)
            {
                strStage = u16Stage.ToString() + "th";
            }
            else
            {
                strStage = sStage[u16Stage];
            }

            stValue.StartTemp = methodconfigini.GetProfileFloat(strStage, "StartTemp", 0);
            stValue.TargetTemp = methodconfigini.GetProfileFloat(strStage, "TargetTemp", 0);
            stValue.HeatSpeed = methodconfigini.GetProfileFloat(strStage, "HeatSpeed", 0);
            stValue.BalanceTime = methodconfigini.GetProfileFloat(strStage, "BalanceTime", 0);

        }

        /// <summary>
        /// 擦除程升表
        /// </summary>
        /// <param name="Stagenum"></param>
        public void EraseColTable(int Stagenum)
        {
            int i;
            string tmpname;
            for (i = 0; i < Stagenum; i++)
            {
                if (i >= 4)
                {
                    tmpname = i.ToString() + "th";
                }
                else
                {
                    tmpname = sStage[i];
                }
                savemethodconfig.EraseSection(tmpname);
            }
        }

        /// <summary>
        /// 记录一次程升表
        /// </summary>
        /// <param name="stValue"></param>
        /// <param name="u16Stage"></param>
        public void SetColTableStageVal(stRunTableVal stValue, ushort u16Stage)
        {
            string strStage;

            if (u16Stage >= 4)
            {
                strStage = u16Stage.ToString() + "th";
            }
            else
            {
                strStage = sStage[u16Stage];
            }

            savemethodconfig.EraseSection(strStage);

            savemethodconfig.WriteProfileFloat(strStage, "TargetTemp", stValue.TargetTemp);
            savemethodconfig.WriteProfileFloat(strStage, "HeatSpeed", stValue.HeatSpeed);
            savemethodconfig.WriteProfileFloat(strStage, "BalanceTime", stValue.BalanceTime);
        }


        /// <summary>
        /// 获取TCD值
        /// </summary>
        /// <param name="flag">0-前 1-中 2-后</param>
        public void GetTcdByID(int flag)
        {
            ushort iDefault = 0;
            float fDefault = 0.0f;
            string sAppName = "";
            int cFront = 0;
            int cInter = 1;
            int cBehind = 2;

            if (flag == 0)
            {
                sAppName = "前检测器";
                tcd[cFront].sTcdLoc = methodconfigini.GetProfileString(sAppName, "TCD");
                tcd[cFront].fSigValve = methodconfigini.GetProfileFloat(sAppName, "信号值", fDefault);
                tcd[cFront].u16Electric = methodconfigini.GetProfileInt(sAppName, "桥电路", iDefault);
                tcd[cFront].u16Polarity = methodconfigini.GetProfileInt(sAppName, "极性", iDefault);
                tcd[cFront].u16AutoZeroSet = methodconfigini.GetProfileInt(sAppName, "自动调零", iDefault);
                tcd[cFront].fHeaterTempSet = methodconfigini.GetProfileFloat(sAppName, "加热器设定温度", fDefault);
                tcd[cFront].fTaiGasSet = methodconfigini.GetProfileFloat(sAppName, "尾气设定值", fDefault);
                tcd[cFront].u16SigDeduct = methodconfigini.GetProfileInt(sAppName, "信号补偿", iDefault);
                tcd[cFront].u16HeaterSel = methodconfigini.GetProfileInt(sAppName, "加热器开关", iDefault);
                tcd[cFront].u16TaiGasSel = methodconfigini.GetProfileInt(sAppName, "尾吹气", iDefault);
            }
            else if (flag == 1)
            {
                sAppName = "中检测器";
                tcd[cInter].sTcdLoc = methodconfigini.GetProfileString(sAppName, "TCD");
                tcd[cInter].fSigValve = methodconfigini.GetProfileFloat(sAppName, "信号值", fDefault);
                tcd[cInter].u16Electric = methodconfigini.GetProfileInt(sAppName, "桥电路", iDefault);
                tcd[cInter].u16Polarity = methodconfigini.GetProfileInt(sAppName, "极性", iDefault);
                tcd[cInter].u16AutoZeroSet = methodconfigini.GetProfileInt(sAppName, "自动调零", iDefault);
                tcd[cInter].fHeaterTempSet = methodconfigini.GetProfileFloat(sAppName, "加热器设定温度", fDefault);
                tcd[cInter].fTaiGasSet = methodconfigini.GetProfileFloat(sAppName, "尾气设定值", fDefault);
                tcd[cInter].u16SigDeduct = methodconfigini.GetProfileInt(sAppName, "信号补偿", iDefault);
                tcd[cInter].u16HeaterSel = methodconfigini.GetProfileInt(sAppName, "加热器开关", iDefault);
                tcd[cInter].u16TaiGasSel = methodconfigini.GetProfileInt(sAppName, "尾吹气", iDefault);
            }
            else if (flag == 2)
            {
                sAppName = "后检测器";
                tcd[cBehind].sTcdLoc = methodconfigini.GetProfileString(sAppName, "TCD");
                tcd[cBehind].fSigValve = methodconfigini.GetProfileFloat(sAppName, "信号值", fDefault);
                tcd[cBehind].u16Electric = methodconfigini.GetProfileInt(sAppName, "桥电路", iDefault);
                tcd[cBehind].u16Polarity = methodconfigini.GetProfileInt(sAppName, "极性", iDefault);
                tcd[cBehind].u16AutoZeroSet = methodconfigini.GetProfileInt(sAppName, "自动调零", iDefault);
                tcd[cBehind].fHeaterTempSet = methodconfigini.GetProfileFloat(sAppName, "加热器设定温度", fDefault);
                tcd[cBehind].fTaiGasSet = methodconfigini.GetProfileFloat(sAppName, "尾气设定值", fDefault);
                tcd[cBehind].u16SigDeduct = methodconfigini.GetProfileInt(sAppName, "信号补偿", iDefault);
                tcd[cBehind].u16HeaterSel = methodconfigini.GetProfileInt(sAppName, "加热器开关", iDefault);
                tcd[cBehind].u16TaiGasSel = methodconfigini.GetProfileInt(sAppName, "尾吹气", iDefault);
            }
            else
            {

            }
        }

        /// <summary>
        /// 设置TCD值
        /// </summary>
        /// <param name="flag"></param>
        public void SetTcdByID(int flag)
        {
            string sAppName = "";
            const int cFront = 0;
            const int cInter = 1;
            const int cBehind = 2;

            if (flag == 0)
            {
                sAppName = "前检测器";
                savemethodconfig.WriteProfileString(sAppName, "TCD", tcd[cFront].sTcdLoc);
                savemethodconfig.WriteProfileFloat(sAppName, "信号值", tcd[cFront].fSigValve);
                savemethodconfig.WriteProfileInt(sAppName, "桥电路", tcd[cFront].u16Electric);
                savemethodconfig.WriteProfileInt(sAppName, "极性", tcd[cFront].u16Polarity);
                savemethodconfig.WriteProfileInt(sAppName, "自动调零", tcd[cFront].u16AutoZeroSet);
                savemethodconfig.WriteProfileFloat(sAppName, "加热器设定温度", tcd[cFront].fHeaterTempSet);
                savemethodconfig.WriteProfileFloat(sAppName, "尾气设定值", tcd[cFront].fTaiGasSet);
                savemethodconfig.WriteProfileInt(sAppName, "信号补偿", tcd[cFront].u16SigDeduct);
                savemethodconfig.WriteProfileInt(sAppName, "加热器开关", tcd[cFront].u16HeaterSel);
                savemethodconfig.WriteProfileInt(sAppName, "尾吹气", tcd[cFront].u16TaiGasSel);
            }
            else if (flag == 1)
            {
                sAppName = "中检测器";
                savemethodconfig.WriteProfileString(sAppName, "TCD", tcd[cInter].sTcdLoc);
                savemethodconfig.WriteProfileFloat(sAppName, "信号值", tcd[cInter].fSigValve);
                savemethodconfig.WriteProfileInt(sAppName, "桥电路", tcd[cInter].u16Electric);
                savemethodconfig.WriteProfileInt(sAppName, "极性", tcd[cInter].u16Polarity);
                savemethodconfig.WriteProfileInt(sAppName, "自动调零", tcd[cInter].u16AutoZeroSet);
                savemethodconfig.WriteProfileFloat(sAppName, "加热器设定温度", tcd[cInter].fHeaterTempSet);
                savemethodconfig.WriteProfileFloat(sAppName, "尾气设定值", tcd[cInter].fTaiGasSet);
                savemethodconfig.WriteProfileInt(sAppName, "信号补偿", tcd[cInter].u16SigDeduct);
                savemethodconfig.WriteProfileInt(sAppName, "加热器开关", tcd[cInter].u16HeaterSel);
                savemethodconfig.WriteProfileInt(sAppName, "尾吹气",tcd[cInter].u16TaiGasSel);
            }
            else if (flag == 2)
            {
                sAppName = "后检测器";
                savemethodconfig.WriteProfileString(sAppName, "TCD", tcd[cBehind].sTcdLoc);
                savemethodconfig.WriteProfileFloat(sAppName, "信号值",tcd[cBehind].fSigValve);
                savemethodconfig.WriteProfileInt(sAppName, "桥电路",tcd[cBehind].u16Electric);
                savemethodconfig.WriteProfileInt(sAppName, "极性", tcd[cBehind].u16Polarity);
                savemethodconfig.WriteProfileInt(sAppName, "自动调零", tcd[cBehind].u16AutoZeroSet);
                savemethodconfig.WriteProfileFloat(sAppName, "加热器设定温度",tcd[cBehind].fHeaterTempSet);
                savemethodconfig.WriteProfileFloat(sAppName, "尾气设定值",tcd[cBehind].fTaiGasSet);
                savemethodconfig.WriteProfileInt(sAppName, "信号补偿", tcd[cBehind].u16SigDeduct);
                savemethodconfig.WriteProfileInt(sAppName, "加热器开关", tcd[cBehind].u16HeaterSel);
                savemethodconfig.WriteProfileInt(sAppName, "尾吹气", tcd[cBehind].u16TaiGasSel);
            }
        }

        /// <summary>
        /// 获取FID
        /// </summary>
        /// <param name="flag"></param>
        public void GetFidByID(int flag)  //FID
        {
            ushort iDefault = 0;
            float fDefault = 0.0f;
            string sAppName = "";
            int cFront = 0;
            int cInter = 1;
            int cBehind = 2;

            if (flag == 0)
            {
                sAppName = "前检测器";
                fid[cFront].sFid = methodconfigini.GetProfileString(sAppName, "检测器位置");
                fid[cFront].u16KeyFire = methodconfigini.GetProfileInt(sAppName, "自动点火", iDefault);
                fid[cFront].u16Zero = methodconfigini.GetProfileInt(sAppName, "归零", iDefault);
                fid[cFront].u16Polarity = methodconfigini.GetProfileInt(sAppName, "极性", iDefault);
                fid[cFront].u16Sensitive = methodconfigini.GetProfileInt(sAppName, "灵敏度", iDefault);
                fid[cFront].u16KeyHeater = methodconfigini.GetProfileInt(sAppName, "加热器开关", iDefault);
                fid[cFront].fHeaterTempSet = methodconfigini.GetProfileFloat(sAppName, "加热器设定温度", fDefault);
                fid[cFront].u16KeyH2Flow = methodconfigini.GetProfileInt(sAppName, "氢气燃气流量开关", iDefault);
                fid[cFront].fSetH2Flow = methodconfigini.GetProfileFloat(sAppName, "氢气燃气流量设定值", fDefault);
                fid[cFront].u16KeyAirFlow = methodconfigini.GetProfileInt(sAppName, "空气流量开关", iDefault);
                fid[cFront].fAirFlowSet = methodconfigini.GetProfileFloat(sAppName, "空气流量设定值", fDefault);
                fid[cFront].u16KeyTailGas = methodconfigini.GetProfileInt(sAppName, "尾吹气流量开关", iDefault);
                fid[cFront].fSetTailGas = methodconfigini.GetProfileFloat(sAppName, "尾吹气流量设定值", fDefault);
                fid[cFront].u16SigDeduct = methodconfigini.GetProfileInt(sAppName, "补偿", iDefault);
            }
            else if (flag == 1)
            {
                sAppName = "中检测器";
                fid[cInter].sFid = methodconfigini.GetProfileString(sAppName, "检测器位置");
                fid[cInter].u16KeyFire = methodconfigini.GetProfileInt(sAppName, "自动点火", iDefault);
                fid[cInter].u16Zero = methodconfigini.GetProfileInt(sAppName, "归零", iDefault);
                fid[cInter].u16Polarity = methodconfigini.GetProfileInt(sAppName, "极性", iDefault);
                fid[cInter].u16Sensitive = methodconfigini.GetProfileInt(sAppName, "灵敏度", iDefault);
                fid[cInter].u16KeyHeater = methodconfigini.GetProfileInt(sAppName, "加热器开关", iDefault);
                fid[cInter].fHeaterTempSet = methodconfigini.GetProfileFloat(sAppName, "加热器设定温度", fDefault);
                fid[cInter].u16KeyH2Flow = methodconfigini.GetProfileInt(sAppName, "氢气燃气流量开关", iDefault);
                fid[cInter].fSetH2Flow = methodconfigini.GetProfileFloat(sAppName, "氢气燃气流量设定值", fDefault);
                fid[cInter].u16KeyAirFlow = methodconfigini.GetProfileInt(sAppName, "空气流量开关", iDefault);
                fid[cInter].fAirFlowSet = methodconfigini.GetProfileFloat(sAppName, "空气流量设定值", fDefault);
                fid[cInter].u16KeyTailGas = methodconfigini.GetProfileInt(sAppName, "尾吹气流量开关", iDefault);
                fid[cInter].fSetTailGas = methodconfigini.GetProfileFloat(sAppName, "尾吹气流量设定值", fDefault);
                fid[cInter].u16SigDeduct = methodconfigini.GetProfileInt(sAppName, "补偿", iDefault);
            }
            else if (flag == 2)
            {
                sAppName = "后检测器";
                fid[cBehind].sFid = methodconfigini.GetProfileString(sAppName, "检测器位置");
                fid[cBehind].u16KeyFire = methodconfigini.GetProfileInt(sAppName, "自动点火", iDefault);
                fid[cBehind].u16Zero = methodconfigini.GetProfileInt(sAppName, "归零", iDefault);
                fid[cBehind].u16Polarity = methodconfigini.GetProfileInt(sAppName, "极性", iDefault);
                fid[cBehind].u16Sensitive = methodconfigini.GetProfileInt(sAppName, "灵敏度", iDefault);
                fid[cBehind].u16KeyHeater = methodconfigini.GetProfileInt(sAppName, "加热器开关", iDefault);
                fid[cBehind].fHeaterTempSet = methodconfigini.GetProfileFloat(sAppName, "加热器设定温度", fDefault);
                fid[cBehind].u16KeyH2Flow = methodconfigini.GetProfileInt(sAppName, "氢气燃气流量开关", iDefault);
                fid[cBehind].fSetH2Flow = methodconfigini.GetProfileFloat(sAppName, "氢气燃气流量设定值", fDefault);
                fid[cBehind].u16KeyAirFlow = methodconfigini.GetProfileInt(sAppName, "空气流量开关", iDefault);
                fid[cBehind].fAirFlowSet = methodconfigini.GetProfileFloat(sAppName, "空气流量设定值", fDefault);
                fid[cBehind].u16KeyTailGas = methodconfigini.GetProfileInt(sAppName, "尾吹气流量开关", iDefault);
                fid[cBehind].fSetTailGas = methodconfigini.GetProfileFloat(sAppName, "尾吹气流量设定值", fDefault);
                fid[cBehind].u16SigDeduct = methodconfigini.GetProfileInt(sAppName, "补偿", iDefault);
            }
        }

        /// <summary>
        /// FID设置
        /// </summary>
        /// <param name="flag"></param>
        public void SetFidByID(int flag)
        {
            string sAppName = "";
            const int cFront = 0;
            const int cInter = 1;
            const int cBehind = 2;

            if (flag == 0)
            {
                sAppName = "前检测器";
                savemethodconfig.WriteProfileString(sAppName, "检测器位置", fid[cFront].sFid);
                savemethodconfig.WriteProfileInt(sAppName, "自动点火", fid[cFront].u16KeyFire);
                savemethodconfig.WriteProfileInt(sAppName, "归零", fid[cFront].u16Zero);
                savemethodconfig.WriteProfileInt(sAppName, "极性", fid[cFront].u16Polarity);
                savemethodconfig.WriteProfileInt(sAppName, "灵敏度", fid[cFront].u16Sensitive);
                savemethodconfig.WriteProfileInt(sAppName, "加热器开关", fid[cFront].u16KeyHeater);
                savemethodconfig.WriteProfileFloat(sAppName, "加热器设定温度", fid[cFront].fHeaterTempSet);
                savemethodconfig.WriteProfileInt(sAppName, "氢气燃气流量开关", fid[cFront].u16KeyH2Flow);
                savemethodconfig.WriteProfileFloat(sAppName, "氢气燃气流量设定值", fid[cFront].fSetH2Flow);
                savemethodconfig.WriteProfileInt(sAppName, "空气流量开关", fid[cFront].u16KeyAirFlow);
                savemethodconfig.WriteProfileFloat(sAppName, "空气流量设定值",fid[cFront].fAirFlowSet);
                savemethodconfig.WriteProfileInt(sAppName, "尾吹气流量开关", fid[cFront].u16KeyTailGas);
                savemethodconfig.WriteProfileFloat(sAppName, "尾吹气流量设定值", fid[cFront].fSetTailGas);
                savemethodconfig.WriteProfileInt(sAppName, "补偿", fid[cFront].u16SigDeduct);
            }
            else if (flag == 1)
            {
                sAppName = "中检测器";
                savemethodconfig.WriteProfileString(sAppName, "检测器位置",fid[cInter].sFid);
                savemethodconfig.WriteProfileInt(sAppName, "自动点火", fid[cInter].u16KeyFire);
                savemethodconfig.WriteProfileInt(sAppName, "归零", fid[cInter].u16Zero);
                savemethodconfig.WriteProfileInt(sAppName, "极性", fid[cInter].u16Polarity);
                savemethodconfig.WriteProfileInt(sAppName, "灵敏度", fid[cInter].u16Sensitive);
                savemethodconfig.WriteProfileInt(sAppName, "加热器开关", fid[cInter].u16KeyHeater);
                savemethodconfig.WriteProfileFloat(sAppName, "加热器设定温度", fid[cInter].fHeaterTempSet);
                savemethodconfig.WriteProfileInt(sAppName, "氢气燃气流量开关", fid[cInter].u16KeyH2Flow);
                savemethodconfig.WriteProfileFloat(sAppName, "氢气燃气流量设定值", fid[cInter].fSetH2Flow);
                savemethodconfig.WriteProfileInt(sAppName, "空气流量开关", fid[cInter].u16KeyAirFlow);
                savemethodconfig.WriteProfileFloat(sAppName, "空气流量设定值", fid[cInter].fAirFlowSet);
                savemethodconfig.WriteProfileInt(sAppName, "尾吹气流量开关", fid[cInter].u16KeyTailGas);
                savemethodconfig.WriteProfileFloat(sAppName, "尾吹气流量设定值",fid[cInter].fSetTailGas);
                savemethodconfig.WriteProfileInt(sAppName, "补偿", fid[cInter].u16SigDeduct);
            }
            else if ( flag == 2)
            {
                sAppName = "后检测器";
                savemethodconfig.WriteProfileString(sAppName, "检测器位置", fid[cBehind].sFid);
                savemethodconfig.WriteProfileInt(sAppName, "自动点火", fid[cBehind].u16KeyFire);
                savemethodconfig.WriteProfileInt(sAppName, "归零", fid[cBehind].u16Zero);
                savemethodconfig.WriteProfileInt(sAppName, "极性", fid[cBehind].u16Polarity);
                savemethodconfig.WriteProfileInt(sAppName, "灵敏度", fid[cBehind].u16Sensitive);
                savemethodconfig.WriteProfileInt(sAppName, "加热器开关", fid[cBehind].u16KeyHeater);
                savemethodconfig.WriteProfileFloat(sAppName, "加热器设定温度", fid[cBehind].fHeaterTempSet);
                savemethodconfig.WriteProfileInt(sAppName, "氢气燃气流量开关", fid[cBehind].u16KeyH2Flow);
                savemethodconfig.WriteProfileFloat(sAppName, "氢气燃气流量设定值", fid[cBehind].fSetH2Flow);
                savemethodconfig.WriteProfileInt(sAppName, "空气流量开关", fid[cBehind].u16KeyAirFlow);
                savemethodconfig.WriteProfileFloat(sAppName, "空气流量设定值", fid[cBehind].fAirFlowSet);
                savemethodconfig.WriteProfileInt(sAppName, "尾吹气流量开关", fid[cBehind].u16KeyTailGas);
                savemethodconfig.WriteProfileFloat(sAppName, "尾吹气流量设定值", fid[cBehind].fSetTailGas);
                savemethodconfig.WriteProfileInt(sAppName, "补偿", fid[cBehind].u16SigDeduct);
            }
        }

        /// <summary>
        /// 获取信号
        /// </summary>
        public void GetDevSignalAllPara()
        {
            ushort iDefault = 0;
            string sAppName = "信号";
            int i = 0;

            signal.u16ChannelA = methodconfigini.GetProfileInt(sAppName, "通道A", iDefault);
            signal.u16ChannelB = methodconfigini.GetProfileInt(sAppName, "通道B", iDefault);


            for (i = 0; i < MAX_CHANNEL_NUM; i++)
            {
                signal.uDetA[i] = methodconfigini.GetProfileInt(sAppName, "通道A检测器" + (i + 1).ToString(), iDefault);
                signal.uDetB[i] = methodconfigini.GetProfileInt(sAppName, "通道B检测器" + (i + 1).ToString(), iDefault);
            }

            for (i = 0; i < MAX_CHANNEL_NUM; i++)
            {
                signal.u16DetTimeLengthA[i] = methodconfigini.GetProfileInt(sAppName, "通道A检测时间" + (i + 1).ToString(), iDefault);
                signal.u16DetTimeLengthB[i] = methodconfigini.GetProfileInt(sAppName, "通道B检测时间" + (i + 1).ToString(), iDefault);
            }
        }

        /// <summary>
        /// 设置信号
        /// </summary>
        public void SetDevSignalAllPara()
        {
            string sAppName = "信号";
            int i = 0;

            savemethodconfig.WriteProfileInt(sAppName, "通道A", signal.u16ChannelA);
            savemethodconfig.WriteProfileInt(sAppName, "通道B", signal.u16ChannelB);

            for (i = 0; i < MAX_CHANNEL_NUM; i++)
            {
                savemethodconfig.WriteProfileInt(sAppName, "通道A检测器" + (i + 1).ToString(), signal.uDetA[i]);
                savemethodconfig.WriteProfileInt(sAppName, "通道B检测器" + (i + 1).ToString(), signal.uDetB[i]);
            }

            for (i = 0; i < MAX_CHANNEL_NUM; i++)
            {
                savemethodconfig.WriteProfileInt(sAppName, "通道A检测时间" + (i + 1).ToString(), signal.u16DetTimeLengthA[i]);
                savemethodconfig.WriteProfileInt(sAppName, "通道B检测时间" + (i + 1).ToString(), signal.u16DetTimeLengthB[i]);
            }
        }

        public void SaveMethodConfig(string filename)
        {
            savemethodconfig = new FileHelper(filename);

            if (System.IO.File.Exists(filename) == false)
            {
                System.IO.StreamWriter sw = new System.IO.StreamWriter(filename, false, System.Text.Encoding.Unicode);
                sw.WriteLine("[方法名称]");
                sw.Close();
            }

            


        }

    }
}
