using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using System.Threading;
using GcDevicePc.IniParam;
using GcDevicePc.ProThread;
using System.Diagnostics;

namespace GcDevicePc
{
    public partial class DataState : DockContent
    {

        public Thread updateth;

    //    GcDataReq m_data;
        GcDataTh mymodbus; 

        public DataState()
        {
            InitializeComponent();

            this.datalist.Width = this.Width;
            this.datalist.Height = this.Height;
        }

        public void Close_Threading()
        {
            if (globaldata.connection_ip != null)
            {
                if (mymodbus != null)
                    mymodbus.ShowDataStop();
                   // m_data.Stop();
            }                   
        }

        private void DataState_Load(object sender, EventArgs e)
        {
            this.datalist.View = View.Details;
            this.datalist.Columns.Add("项目", 120, HorizontalAlignment.Left);
            this.datalist.Columns.Add("状态显示", 120, HorizontalAlignment.Center);

            globaldata.m_profileMethod.GetDevState();
            if(globaldata.connection_ip != null)
            {               
                //m_data = new GcDataReq(globaldata.connection_ip, globaldata.datamodbusport);
                //m_data.Start();

                mymodbus = new GcDataTh(globaldata.connection_ip, globaldata.datamodbusport);
                mymodbus.ShowDataStart();

                System.Windows.Forms.Timer T = new System.Windows.Forms.Timer();
                T.Interval = 100;
                T.Tick += new EventHandler(dataupdate_Tick);
                T.Enabled = true;
            }       
        }

      
        double valueold = 0;
        ListViewItem tempshow;
        private void dataupdate_Tick(object sender, EventArgs e)
        {
            int i;           
            double value = 0 ;

            try
            {
                updataPLC();
                this.datalist.Items.Clear();
                this.datalist.BeginUpdate();

                tempshow = new ListViewItem();
                tempshow.Text = "时间显示";
                tempshow.Font = new Font(tempshow.Font, tempshow.Font.Style | FontStyle.Bold);
                tempshow.SubItems.Add("(min)");
                this.datalist.Items.Add(tempshow);

                tempshow = new ListViewItem();
                tempshow.Text = "运行时间/总时间";
                if (globaldata.MethodRun_Statue == 4 || globaldata.MethodRun_Statue == 5)
                    //  tempshow.SubItems.Add((globaldata.RunTime_Now/60.0f).ToString("0.0") + "/" + (globaldata.RunTotal_Now/60.0f).ToString("0.0"));
                    tempshow.SubItems.Add((globaldata.m_dpbuffer.ShowList.showtime.runtimenow / 60.0f).ToString("0.0") + "/" + (globaldata.m_dpbuffer.ShowList.showtime.alltime / 60.0f).ToString("0.0"));
                else
                    tempshow.SubItems.Add("未运行");

                this.datalist.Items.Add(tempshow);

                tempshow = new ListViewItem();
                this.datalist.Items.Add(tempshow);

                //温度显示
                tempshow = new ListViewItem();
                tempshow.Text = "温度显示";
                tempshow.Font = new Font(tempshow.Font, tempshow.Font.Style | FontStyle.Bold);
                tempshow.SubItems.Add("(℃)");
                this.datalist.Items.Add(tempshow);

                if (CProfileDevice.m_DevParam.syspara.u16InjPortFront == 1)
                {
                    tempshow = new ListViewItem();
                    tempshow.Text = "前进样口";

                    //if (CProfileDevice.m_DevParam.port[0].fHeaterSetTempm == 0.0f)
                    //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.port[0].fHeaterTempActual.ToString("#0.00") + " / " + "等待读取");
                    //else
                    //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.port[0].fHeaterTempActual.ToString("#0.00") + " / " + CProfileDevice.m_DevParam.port[0].fHeaterSetTempm.ToString("0"));
                    if (globaldata.m_dpbuffer.ShowList.showtemp.FPSetTemp == 0.0f)
                        tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.FPActualTemp.ToString("#0.00") + " / " + "等待读取");
                    else
                    {
                        tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.FPActualTemp.ToString("#0.00") + " / " + globaldata.m_dpbuffer.ShowList.showtemp.FPSetTemp.ToString("0"));
                        this.datalist.Items.Add(tempshow);
                    }
                        
                }

                if (CProfileDevice.m_DevParam.syspara.u16InjPortBehind == 1)
                {
                    tempshow = new ListViewItem();
                    tempshow.Text = "后进样口";

                    //if (CProfileDevice.m_DevParam.port[1].fHeaterSetTempm == 0.0f)
                    //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.port[1].fHeaterTempActual.ToString("#0.00") + " / " + "等待读取");
                    //else
                    //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.port[1].fHeaterTempActual.ToString("#0.00") + " / " + CProfileDevice.m_DevParam.port[1].fHeaterSetTempm.ToString("0"));

                    if (globaldata.m_dpbuffer.ShowList.showtemp.BPSetTemp == 0.0f)
                        tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.BPActualTemp.ToString("#0.00") + " / " + "等待读取");
                    else
                    {
                        tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.BPActualTemp.ToString("#0.00") + " / " + globaldata.m_dpbuffer.ShowList.showtemp.BPSetTemp.ToString("0"));
                        this.datalist.Items.Add(tempshow);
                    }
                       
                }

                if (CProfileDevice.m_DevParam.syspara.u16Col == 1)
                {
                    tempshow = new ListViewItem();
                    tempshow.Text = "柱箱";

                    //if (CProfileDevice.m_DevParam.col.fColTempSet == 0.0f)
                    //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.col.fCurTemp.fCurTemp.ToString("#0.00") + " / " + "等待读取");
                    //else
                    //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.col.fCurTemp.fCurTemp.ToString("#0.00") + " / " + CProfileDevice.m_DevParam.col.fColTempSet.ToString("0"));

                    if (globaldata.m_dpbuffer.ShowList.showtemp.ColSetTemp == 0.0f)
                        tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.ColActualTemp.ToString("#0.00") + " / " + "等待读取");
                    else
                    {
                        tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.ColActualTemp.ToString("#0.00") + " / " + globaldata.m_dpbuffer.ShowList.showtemp.ColSetTemp.ToString("0"));
                        this.datalist.Items.Add(tempshow);
                    }
                     
                }


                if (CProfileDevice.m_DevParam.syspara.u16DetNum >= 1)
                {
                    if (CProfileDevice.m_DevParam.syspara.u16DetFront == 1)
                    {
                        tempshow = new ListViewItem();
                        if (CProfileDevice.m_DevParam.syspara.u16DetFrontType == 0)  //TCD
                        {

                            tempshow.Text = "TCD1";
                            //if (CProfileDevice.m_DevParam.tcd[0].fHeaterTempSet == 0.0f)
                            //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.tcd[0].fHeaterTempActual.ToString("#0.00") + " / " + "等待读取");
                            //else
                            //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.tcd[0].fHeaterTempActual.ToString("#0.00") + " / " + CProfileDevice.m_DevParam.tcd[0].fHeaterTempSet.ToString("0"));
                            //this.datalist.Items.Add(tempshow);

                        }
                        else if (CProfileDevice.m_DevParam.syspara.u16DetFrontType == 1)
                        {
                            // tempshow = new ListViewItem();
                            tempshow.Text = "FID1";
                            //if (CProfileDevice.m_DevParam.fid[0].fHeaterTempSet == 0.0f)
                            //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.fid[0].fHeaterActualTemp.ToString("#0.00") + " / " + "等待读取");
                            //else
                            //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.fid[0].fHeaterActualTemp.ToString("#0.00") + " / " + CProfileDevice.m_DevParam.fid[0].fHeaterTempSet.ToString("0"));
                            //this.datalist.Items.Add(tempshow);
                        }

                        if (globaldata.m_dpbuffer.ShowList.showtemp.fDetSetTemp == 0.0f)
                            tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.fDetActualTemp.ToString("#0.00") + " / " + "等待读取");
                        else
                        {
                            tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.fDetActualTemp.ToString("#0.00") + " / " + globaldata.m_dpbuffer.ShowList.showtemp.fDetSetTemp.ToString("0"));
                            this.datalist.Items.Add(tempshow);
                        }                          
                    }


                    if (CProfileDevice.m_DevParam.syspara.u16DetInter == 1)
                    {
                        tempshow = new ListViewItem();
                        if (CProfileDevice.m_DevParam.syspara.u16DetInterType == 0)  //TCD
                        {

                            tempshow.Text = "TCD2";
                            //if (CProfileDevice.m_DevParam.tcd[1].fHeaterTempSet == 0.0f)
                            //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.tcd[1].fHeaterTempActual.ToString("#0.00") + " / " + "等待读取");
                            //else
                            //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.tcd[1].fHeaterTempActual.ToString("#0.00") + " / " + CProfileDevice.m_DevParam.tcd[1].fHeaterTempSet.ToString("0"));

                            //this.datalist.Items.Add(tempshow);
                        }
                        else if (CProfileDevice.m_DevParam.syspara.u16DetInterType == 1)
                        {
                            //tempshow = new ListViewItem();
                            tempshow.Text = "FID2";
                            //if (CProfileDevice.m_DevParam.fid[1].fHeaterTempSet == 0.0f)
                            //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.fid[1].fHeaterActualTemp.ToString("#0.00") + " / " + "等待读取");
                            //else
                            //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.fid[1].fHeaterActualTemp.ToString("#0.00") + " / " + CProfileDevice.m_DevParam.fid[1].fHeaterTempSet.ToString("0"));                        
                            //this.datalist.Items.Add(tempshow);
                        }


                        if (globaldata.m_dpbuffer.ShowList.showtemp.iDetSetTemp == 0.0f)
                            tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.iDetActualTemp.ToString("#0.00") + " / " + "等待读取");
                        else
                        {
                            tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.iDetActualTemp.ToString("#0.00") + " / " + globaldata.m_dpbuffer.ShowList.showtemp.iDetSetTemp.ToString("0"));
                            this.datalist.Items.Add(tempshow);
                        }
                          
                    }

                    if (CProfileDevice.m_DevParam.syspara.u16DetBehind == 1)
                    {
                        tempshow = new ListViewItem();
                        if (CProfileDevice.m_DevParam.syspara.u16DetBehindType == 0)
                        {

                            tempshow.Text = "TCD3";
                            //if (CProfileDevice.m_DevParam.tcd[2].fHeaterTempSet == 0.0f)
                            //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.tcd[2].fHeaterTempActual.ToString("#0.00") + " / " + "等待读取");
                            //else
                            //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.tcd[2].fHeaterTempActual.ToString("#0.00") + " / " + CProfileDevice.m_DevParam.tcd[2].fHeaterTempSet.ToString("0"));
                            //this.datalist.Items.Add(tempshow);
                        }
                        else if (CProfileDevice.m_DevParam.syspara.u16DetBehindType == 1)
                        {
                            //tempshow = new ListViewItem();
                            tempshow.Text = "FID3";
                            //if (CProfileDevice.m_DevParam.fid[2].fHeaterTempSet == 0.0f)
                            //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.fid[2].fHeaterActualTemp.ToString("#0.00") + " / " + "等待读取");
                            //else
                            //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.fid[2].fHeaterActualTemp.ToString("#0.00") + " / " + CProfileDevice.m_DevParam.fid[2].fHeaterTempSet.ToString("0"));
                            //this.datalist.Items.Add(tempshow);
                        }

                        if (globaldata.m_dpbuffer.ShowList.showtemp.bDetSetTemp == 0.0f)
                            tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.bDetActualTemp.ToString("#0.00") + " / " + "等待读取");
                        else
                        {
                            tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.bDetActualTemp.ToString("#0.00") + " / " + globaldata.m_dpbuffer.ShowList.showtemp.bDetSetTemp.ToString("0"));
                            this.datalist.Items.Add(tempshow);
                        }
                           
                    }
                }

                if (CProfileDevice.m_DevParam.syspara.u16AuxHeaterNum > 0)
                {
                    if (CProfileDevice.m_DevParam.syspara.u16AuxHeater1 == 1)  //TCD
                    {
                        tempshow = new ListViewItem();
                        if (CProfileDevice.m_DevParam.syspara.u16AuxHeaterName1 != null)
                            tempshow.Text = CProfileDevice.m_DevParam.syspara.u16AuxHeaterName1;
                        else
                            tempshow.Text = "未命名";

                        if (globaldata.m_dpbuffer.ShowList.showtemp.AuxSetTemp1 == 0.0f)
                            tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.AuxActualTemp1.ToString("#0.00") + " / " + "等待读取");
                        else
                        {
                            tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.AuxActualTemp1.ToString("#0.00") + " / " + globaldata.m_dpbuffer.ShowList.showtemp.AuxSetTemp1.ToString("0"));
                            this.datalist.Items.Add(tempshow);
                        }
                            

                        //if (CProfileDevice.m_DevParam.aux.fSetTemp_HeatArea1 == 0.0f)
                        //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.aux.fActualTemp_HeatArea1.ToString("#0.00") + " / " + "等待读取");               
                        //else
                        //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.aux.fActualTemp_HeatArea1.ToString("#0.00") + " / " + CProfileDevice.m_DevParam.aux.fSetTemp_HeatArea1.ToString("0"));
                        //this.datalist.Items.Add(tempshow);
                    }

                    if (CProfileDevice.m_DevParam.syspara.u16AuxHeater2 == 1)
                    {
                        tempshow = new ListViewItem();
                        if (CProfileDevice.m_DevParam.syspara.u16AuxHeaterName1 != null)
                            tempshow.Text = CProfileDevice.m_DevParam.syspara.u16AuxHeaterName2;
                        else
                            tempshow.Text = "未命名";

                        if (globaldata.m_dpbuffer.ShowList.showtemp.AuxSetTemp2 == 0.0f)
                            tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.AuxActualTemp2.ToString("#0.00") + " / " + "等待读取");
                        else
                        {
                            tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.AuxActualTemp2.ToString("#0.00") + " / " + globaldata.m_dpbuffer.ShowList.showtemp.AuxSetTemp2.ToString("0"));
                            this.datalist.Items.Add(tempshow);
                        }
                           

                        //if (CProfileDevice.m_DevParam.aux.fSetTemp_HeatArea2 == 0.0f)
                        //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.aux.fActualTemp_HeatArea2.ToString("#0.00") + " / " + "等待读取");                                              
                        //else
                        //    tempshow.SubItems.Add(CProfileDevice.m_DevParam.aux.fActualTemp_HeatArea2.ToString("#0.00") + " / " + CProfileDevice.m_DevParam.aux.fSetTemp_HeatArea2.ToString("0"));
                        //this.datalist.Items.Add(tempshow);
                    }
                }

                //////////////////////////////////////////////////////////////////////////////////

                //阀状态显示
                tempshow = new ListViewItem();
                this.datalist.Items.Add(tempshow);
                tempshow = new ListViewItem();
                tempshow.Text = "事件显示";
                tempshow.Font = new Font(tempshow.Font, tempshow.Font.Style | FontStyle.Bold);
                tempshow.SubItems.Add(" ");
                this.datalist.Items.Add(tempshow);
                bool valveflag = false;
                bool openflag = false;

                for (i = 0; i < 4; i++)
                {

                    switch (i)
                    {
                        case 0:
                            {
                                valveflag = (CProfileDevice.m_DevParam.syspara.u16ValveOne == 1) ? true : false;
                                openflag = globaldata.m_dpbuffer.ShowList.showValve.u16ValveOne;
                            }
                            break;
                        case 1:
                            {
                                valveflag = (CProfileDevice.m_DevParam.syspara.u16ValveTwo == 1) ? true : false;
                                openflag = globaldata.m_dpbuffer.ShowList.showValve.u16ValveTwo;
                            }
                            break;
                        case 2:
                            {
                                valveflag = (CProfileDevice.m_DevParam.syspara.u16ValveThree == 1) ? true : false;
                                openflag = globaldata.m_dpbuffer.ShowList.showValve.u16ValveThree;
                            }
                            break;
                        case 3:
                            {
                                valveflag = (CProfileDevice.m_DevParam.syspara.u16ValveFour == 1) ? true : false;
                                openflag = globaldata.m_dpbuffer.ShowList.showValve.u16ValveFour;
                            }
                            break;
                        default:
                            {
                                valveflag = false;
                                openflag = false;
                            }
                            break;
                    }

                    if (valveflag)
                    {
                        tempshow = new ListViewItem();
                        tempshow.Text = "阀" + (i + 1);
                        tempshow.SubItems.Add(openflag ? "开" : "关");
                        this.datalist.Items.Add(tempshow);
                        valveflag = false;
                        openflag = false;

                        tempshow = new ListViewItem();
                        tempshow.Text = "start/end(min)";
                        tempshow.SubItems.Add((CProfileDevice.m_DevParam.valve.u16ValveSetTime1[i] / 100.0f).ToString("0.00") + " / " + (CProfileDevice.m_DevParam.valve.u16ValveSetTime2[i] / 100.0f).ToString("0.00"));
                        this.datalist.Items.Add(tempshow);

                        if (CProfileDevice.m_DevParam.valve.u16ValveSetTime3[i] != 0)
                        {
                            tempshow = new ListViewItem();
                            tempshow.Text = " ";
                            tempshow.SubItems.Add((CProfileDevice.m_DevParam.valve.u16ValveSetTime3[i] / 100.0f).ToString("0.00") + " / " + (CProfileDevice.m_DevParam.valve.u16ValveSetTime4[i] / 100.0f).ToString("0.00"));
                            this.datalist.Items.Add(tempshow);
                        }

                        if (CProfileDevice.m_DevParam.valve.u16ValveSetTime5[i] != 0)
                        {
                            tempshow = new ListViewItem();
                            tempshow.Text = " ";
                            tempshow.SubItems.Add((CProfileDevice.m_DevParam.valve.u16ValveSetTime5[i] / 100.0f).ToString("0.00") + " / " + (CProfileDevice.m_DevParam.valve.u16ValveSetTime6[i] / 100.0f).ToString("0.00"));
                            this.datalist.Items.Add(tempshow);
                        }

                        if (CProfileDevice.m_DevParam.valve.u16ValveSetTime7[i] != 0)
                        {
                            tempshow = new ListViewItem();
                            tempshow.Text = " ";
                            tempshow.SubItems.Add((CProfileDevice.m_DevParam.valve.u16ValveSetTime7[i] / 100.0f).ToString("0.00") + " / " + (CProfileDevice.m_DevParam.valve.u16ValveSetTime8[i] / 100.0f).ToString("0.00"));
                            this.datalist.Items.Add(tempshow);
                        }
                    }
                }

                //进样口
                tempshow = new ListViewItem();
                this.datalist.Items.Add(tempshow);
                tempshow = new ListViewItem();
                tempshow.Text = "进样口状态";
                tempshow.Font = new Font(tempshow.Font, tempshow.Font.Style | FontStyle.Bold);
                tempshow.SubItems.Add(" ");
                this.datalist.Items.Add(tempshow);
                tempshow = new ListViewItem();
                tempshow.Text = "前进样口";
                tempshow.SubItems.Add("N/A");
                this.datalist.Items.Add(tempshow);
                tempshow = new ListViewItem();
                tempshow.Text = "后进样口";
                tempshow.SubItems.Add("N/A");
                this.datalist.Items.Add(tempshow);
                tempshow = new ListViewItem();
                this.datalist.Items.Add(tempshow);


                tempshow = new ListViewItem();
                tempshow.Text = "检测器状态";
                tempshow.Font = new Font(tempshow.Font, tempshow.Font.Style | FontStyle.Bold);
                tempshow.SubItems.Add(" ");
                this.datalist.Items.Add(tempshow);

                if (CProfileDevice.m_DevParam.syspara.u16DetFront == 1)
                {
                    if (CProfileDevice.m_DevParam.syspara.u16DetFrontType == 0)  //TCD
                    {
                        tempshow = new ListViewItem();
                        tempshow.Text = "TCD1";
                        tempshow.SubItems.Add(" ");
                        this.datalist.Items.Add(tempshow);
                        tempshow = new ListViewItem();
                        tempshow.Text = "桥流状态";
                        tempshow.SubItems.Add(" ");
                        this.datalist.Items.Add(tempshow);
                        tempshow = new ListViewItem();
                        tempshow.Text = "桥流值";
                        tempshow.SubItems.Add(" ");
                        this.datalist.Items.Add(tempshow);
                    }
                    else if (CProfileDevice.m_DevParam.syspara.u16DetFrontType == 1)
                    {
                        tempshow = new ListViewItem();
                        tempshow.Text = "FID1";

                        //if (  globaldata.Draw_Port.Count > 1)
                        //ThreadGlobal.Draw_portThrad.WaitOne();//等待数据更新
                        Console.WriteLine("状态更新。。。。");
                        if (globaldata.m_signalbuffer.Draw_Port.Count > 1)
                        {
                            // value = (((globaldata.Channel_XY)globaldata.m_signalbuffer.Draw_Port[0]).cdata * 1000.0f);
                            value = globaldata.m_dpbuffer.ShowList.showDet.fDetValue;
                            if (value != 0)
                                valueold = value;
                            else
                                value = valueold;

                            if (value != 0.0f)
                                tempshow.SubItems.Add(value.ToString("0.000") + " mV");
                        }
                        else
                        {
                            tempshow.SubItems.Add(valueold.ToString("0.000") + " mV");
                        }

                        this.datalist.Items.Add(tempshow);

                        tempshow = new ListViewItem();
                        tempshow.Text = "点火状态";

                        // if (CProfileDevice.m_DevParam.fid[0].u16IsFire == 1)
                        if (globaldata.m_dpbuffer.ShowList.showDet.fDetSwitch)
                            tempshow.SubItems.Add("已点火");
                        else
                            tempshow.SubItems.Add("未点火");

                        this.datalist.Items.Add(tempshow);
                        tempshow = new ListViewItem();
                        tempshow.Text = "灵敏度";
                        if (CProfileDevice.m_DevParam.fid[0].u16Sensitive == 0)
                            tempshow.SubItems.Add("第一档");
                        else if (CProfileDevice.m_DevParam.fid[0].u16Sensitive == 1)
                            tempshow.SubItems.Add("第二档");
                        else if (CProfileDevice.m_DevParam.fid[0].u16Sensitive == 2)
                            tempshow.SubItems.Add("第三档");
                        else
                            tempshow.SubItems.Add("未设置");
                        this.datalist.Items.Add(tempshow);
                    }
                }

                if (CProfileDevice.m_DevParam.syspara.u16DetInter == 1)
                {
                    if (CProfileDevice.m_DevParam.syspara.u16DetInterType == 0)  //TCD
                    {
                        tempshow = new ListViewItem();
                        tempshow.Text = "TCD2";
                        tempshow.SubItems.Add(" ");
                        this.datalist.Items.Add(tempshow);

                        tempshow = new ListViewItem();
                        tempshow.Text = "桥流状态";
                        tempshow.SubItems.Add(" ");
                        this.datalist.Items.Add(tempshow);

                        tempshow = new ListViewItem();
                        tempshow.Text = "桥流值";
                        tempshow.SubItems.Add(" ");
                        this.datalist.Items.Add(tempshow);
                    }
                    else if (CProfileDevice.m_DevParam.syspara.u16DetInterType == 1)
                    {
                        tempshow = new ListViewItem();
                        tempshow.Text = "FID2";
                        tempshow.SubItems.Add(" ");
                        this.datalist.Items.Add(tempshow);

                        tempshow = new ListViewItem();
                        tempshow.Text = "点火状态";
                        if (CProfileDevice.m_DevParam.fid[1].u16IsFire == 1)
                            tempshow.SubItems.Add("已点火");
                        else
                            tempshow.SubItems.Add("未点火");
                        this.datalist.Items.Add(tempshow);

                        tempshow = new ListViewItem();
                        tempshow.Text = "灵敏度";
                        if (CProfileDevice.m_DevParam.fid[1].u16Sensitive == 0)
                            tempshow.SubItems.Add("第一档");
                        else if (CProfileDevice.m_DevParam.fid[1].u16Sensitive == 1)
                            tempshow.SubItems.Add("第二档");
                        else if (CProfileDevice.m_DevParam.fid[1].u16Sensitive == 2)
                            tempshow.SubItems.Add("第三档");
                        else
                            tempshow.SubItems.Add("未设置");

                        this.datalist.Items.Add(tempshow);
                    }
                }

                if (CProfileDevice.m_DevParam.syspara.u16DetBehind == 1)
                {
                    if (CProfileDevice.m_DevParam.syspara.u16DetBehindType == 0)  //TCD
                    {
                        tempshow = new ListViewItem();
                        tempshow.Text = "TCD3";
                        tempshow.SubItems.Add(" ");
                        this.datalist.Items.Add(tempshow);

                        tempshow = new ListViewItem();
                        tempshow.Text = "桥流状态";
                        tempshow.SubItems.Add(" ");
                        this.datalist.Items.Add(tempshow);

                        tempshow = new ListViewItem();
                        tempshow.Text = "桥流值";
                        tempshow.SubItems.Add(" ");
                        this.datalist.Items.Add(tempshow);
                    }
                    else if (CProfileDevice.m_DevParam.syspara.u16DetBehindType == 1)
                    {
                        tempshow = new ListViewItem();
                        tempshow.Text = "FID3";
                        tempshow.SubItems.Add(" ");
                        this.datalist.Items.Add(tempshow);

                        tempshow = new ListViewItem();
                        tempshow.Text = "点火状态";
                        if (CProfileDevice.m_DevParam.fid[2].u16IsFire == 1)
                            tempshow.SubItems.Add("已点火");
                        else
                            tempshow.SubItems.Add("未点火");
                        this.datalist.Items.Add(tempshow);

                        tempshow = new ListViewItem();
                        tempshow.Text = "灵敏度";
                        if (CProfileDevice.m_DevParam.fid[2].u16Sensitive == 0)
                            tempshow.SubItems.Add("第一档");
                        else if (CProfileDevice.m_DevParam.fid[2].u16Sensitive == 1)
                            tempshow.SubItems.Add("第二档");
                        else if (CProfileDevice.m_DevParam.fid[2].u16Sensitive == 2)
                            tempshow.SubItems.Add("第三档");
                        else
                            tempshow.SubItems.Add("未设置"); ;
                        this.datalist.Items.Add(tempshow);
                    }
                }
                this.datalist.EndUpdate();
            }
            catch (Exception ex)
            {
                Trace.Write(ex);
            }
            
    
        }

        private void updataPLC()
        {
            try
            {
                lock(ModbusLib.Globaldata.tcpGlobaldata)
                {
                    switch (globaldata.MethodRun_Statue)
                    {
                        case 0:
                            ModbusLib.Globaldata.tcpGlobaldata.rstate = 0x00;
                            ModbusLib.Globaldata.tcpGlobaldata.runtime = 0f;
                            break;
                        case 1:
                        case 2:                            
                        case 3:
                             ModbusLib.Globaldata.tcpGlobaldata.rstate = 0x01;
                             ModbusLib.Globaldata.tcpGlobaldata.runtime = 0f;
                            break;
                        case 4:
                        case 5:
                            ModbusLib.Globaldata.tcpGlobaldata.rstate = 0x02;
                            ModbusLib.Globaldata.tcpGlobaldata.runtime = globaldata.m_dpbuffer.ShowList.showtime.runtimenow;
                            break;
                        case 6:
                        case 7:
                            ModbusLib.Globaldata.tcpGlobaldata.rstate = 0x04;
                            ModbusLib.Globaldata.tcpGlobaldata.runtime = 0f;
                            break;
                            
                    }
                    //点火状态
                    if (globaldata.m_dpbuffer.ShowList.showDet.fDetSwitch)
                        ModbusLib.Globaldata.tcpGlobaldata.fstate = 0x03;
                    else
                        ModbusLib.Globaldata.tcpGlobaldata.fstate = 0x04;
                    ModbusLib.Globaldata.tcpGlobaldata.temp1 = globaldata.m_dpbuffer.ShowList.showtemp.ColActualTemp;
                    ModbusLib.Globaldata.tcpGlobaldata.temp3 = globaldata.m_dpbuffer.ShowList.showtemp.fDetActualTemp;
                }

            }
            catch (Exception ex)
            {
                Trace.Write(ex);
            }
        }
  

    }
}
