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;
        }

        ~DataState()
        {
            try
            {
                if (mymodbus != null)
                    mymodbus.ShowDataStop();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

        }

        public void Close_Threading()
        {
            try
            {
                if (mymodbus != null)
                    mymodbus.ShowDataStop();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

        }

        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 (!String.IsNullOrEmpty(globaldata.connection_ip))
            {               
                //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 fDetvalueold = 0;
       // double iDetvalueold = 0;
       // double bDetvalueold = 0;
        ListViewItem tempshow;
        private void dataupdate_Tick(object sender, EventArgs e)
        {
            int i;           
            double fDetvalue = 0;
            //double iDetvalue = 0;
            //double bDetvalue = 0;

            string errinfo;
            string gasno="";

            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.00") + "/" + (globaldata.m_dpbuffer.ShowList.showtime.alltime / 60.0f).ToString("0.00"));
                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);
                errinfo = null;
                if (globaldata.m_hmibuffer.gcinfo.ErrorStatus[0] == 1)
                    errinfo = "通讯板";
                if (globaldata.m_hmibuffer.gcinfo.ErrorStatus[1] == 1)
                    errinfo += "检测板";
                if (globaldata.m_hmibuffer.gcinfo.ErrorStatus[2] == 1)
                    errinfo += "电源板";
                if (globaldata.m_hmibuffer.gcinfo.ErrorStatus[3] == 1)
                    errinfo += "异常温度";
                if (globaldata.m_hmibuffer.gcinfo.ErrorStatus[4] == 1)
                    errinfo += "主机通讯";

                if (errinfo != null)
                {
                    errinfo += "报错";
                }else
                {
                    errinfo = "未发现错误";
                }
                tempshow.SubItems.Add(errinfo.ToString());
                this.datalist.Items.Add(tempshow);
                //errinfo = null;

                tempshow = new ListViewItem();
                tempshow.Text = " ";
                //tempshow.Font = new Font(tempshow.Font, tempshow.Font.Style | FontStyle.Bold);
                errinfo = "气路";
                if (globaldata.m_hmibuffer.gcinfo.ErrorStatus[5] == 1)
                    gasno = "1 ";
                if (globaldata.m_hmibuffer.gcinfo.ErrorStatus[6] == 1)
                    gasno += "2 ";
                if (globaldata.m_hmibuffer.gcinfo.ErrorStatus[7] == 1)
                    gasno += "3";
                if (globaldata.m_hmibuffer.gcinfo.ErrorStatus[8] == 1)
                    gasno += "4";

                if (gasno != "")
                {
                    errinfo = gasno +"报警";
                }
                else
                {
                    errinfo += "正常";
                }

                //备用
                if (gasno != "")
                {
                    tempshow.SubItems.Add(errinfo.ToString());
                    this.datalist.Items.Add(tempshow);
                }
                
                errinfo = null;

                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 (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 (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 (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";
                        }
                        else if (CProfileDevice.m_DevParam.syspara.u16DetFrontType == 1)
                        {
                            tempshow.Text = "FID1";
                        }

                        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";
                          
                        }
                        else if (CProfileDevice.m_DevParam.syspara.u16DetInterType == 1)
                        {
                            
                            tempshow.Text = "FID2";
                        }

                        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";  
                        }
                        else if (CProfileDevice.m_DevParam.syspara.u16DetBehindType == 1)
                        {
                            tempshow.Text = "FID3";
                           
                        }

                        if (globaldata.m_dpbuffer.ShowList.showtemp.bDetSetTemp == 0.0f)
                        {
                            tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showtemp.bDetActualTemp.ToString("#0.00") + " / " + "等待读取");
                            this.datalist.Items.Add(tempshow);
                        }
                        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.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);
                        }
                    }
                }

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

                //阀状态显示
                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 < 6; 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;
                        case 4:
                            {
                                valveflag = (CProfileDevice.m_DevParam.syspara.u16ValveFive == 1) ? true : false;
                                openflag = globaldata.m_dpbuffer.ShowList.showValve.u16ValveFive;
                            }
                            break;
                        case 5:
                            {
                                valveflag = (CProfileDevice.m_DevParam.syspara.u16ValveSix == 1) ? true : false;
                                openflag = globaldata.m_dpbuffer.ShowList.showValve.u16ValveSix;
                            }
                            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(" ");

                        if (globaldata.m_signalbuffer.Draw_Port.Count > 1)
                        {
                            fDetvalue = globaldata.m_dpbuffer.ShowList.showDet.fDetValue;
                            
                            if (fDetvalue != 0)
                                fDetvalueold = fDetvalue;
                            else
                                fDetvalue = fDetvalueold;

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

                        this.datalist.Items.Add(tempshow);
                        tempshow = new ListViewItem();
                        tempshow.Text = "桥流状态";
                        if (globaldata.m_dpbuffer.ShowList.showDet.fDetSwitch)
                        {
                            tempshow.SubItems.Add("开");
                        }else{
                            tempshow.SubItems.Add("关");
                        }
                        
                        this.datalist.Items.Add(tempshow);
                        tempshow = new ListViewItem();
                        tempshow.Text = "桥流值";
                        tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showDet.fDetStatue.ToString());
                        this.datalist.Items.Add(tempshow);
                    }
                    else if (CProfileDevice.m_DevParam.syspara.u16DetFrontType == 1)
                    {
                        tempshow = new ListViewItem();
                        tempshow.Text = "FID1";
            
                        if (globaldata.m_signalbuffer.Draw_Port.Count > 1)
                        {                           
                            fDetvalue = globaldata.m_dpbuffer.ShowList.showDet.fDetValue;

                            if (fDetvalue != 0)
                                fDetvalueold = fDetvalue;
                            else
                                fDetvalue = fDetvalueold;

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

                        this.datalist.Items.Add(tempshow);

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

                        string tmpstr = null;
                        switch (globaldata.m_dpbuffer.ShowList.showDet.fDetStatue)
                        {
                            case 0:
                                tmpstr = "未点火";
                                break;
                            case 1:
                                tmpstr = "点火中";
                                break;
                            case 2:
                                tmpstr = "点火成功";
                                break;
                            case 3:
                                tmpstr = "点火失败";
                                break;
                            case 4:
                                tmpstr = "火焰熄灭";
                                break;
                            case 5:
                                tmpstr = "重新点火";
                                break;
                            default:
                                tmpstr = "状态错误";
                                break;
                        }
                        tempshow.SubItems.Add(tmpstr);

                        //// 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);
                    }
                }

                tempshow = new ListViewItem();
                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";

                //        if (globaldata.m_signalbuffer.Draw_Port2.Count > 1)
                //        {
                //            iDetvalue = globaldata.m_dpbuffer.ShowList.showDet.iDetValue;

                //            if (iDetvalue != 0)
                //                iDetvalueold = iDetvalue;
                //            else
                //                iDetvalue = iDetvalueold;

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

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

                //        tempshow = new ListViewItem();
                //        tempshow.Text = "桥流状态";
                //        if (globaldata.m_dpbuffer.ShowList.showDet.iDetSwitch)
                //        {
                //            tempshow.SubItems.Add("开");
                //        }
                //        else
                //        {
                //            tempshow.SubItems.Add("关");
                //        }

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

                //        tempshow = new ListViewItem();
                //        tempshow.Text = "桥流值";
                //        tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showDet.iDetStatue.ToString());
                //        this.datalist.Items.Add(tempshow);
                //    }
                //    else if (CProfileDevice.m_DevParam.syspara.u16DetInterType == 1)
                //    {
                //        tempshow = new ListViewItem();
                //        tempshow.Text = "FID2";
                      
                //        if (globaldata.m_signalbuffer.Draw_Port2.Count > 1)
                //        {  
                //            iDetvalue = globaldata.m_dpbuffer.ShowList.showDet.iDetValue;
                //            if (iDetvalue != 0)
                //                iDetvalueold = iDetvalue;
                //            else
                //                iDetvalue = iDetvalueold;

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

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

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

                //        string tmpstr = null;
                //        switch (globaldata.m_dpbuffer.ShowList.showDet.iDetStatue)
                //        {
                //            case 0:
                //                tmpstr = "未点火";
                //                break;
                //            case 1:
                //                tmpstr = "点火中";
                //                break;
                //            case 2:
                //                tmpstr = "点火成功";
                //                break;
                //            case 3:
                //                tmpstr = "点火失败";
                //                break;
                //            case 4:
                //                tmpstr = "火焰熄灭";
                //                break;
                //            case 5:
                //                tmpstr = "重新点火";
                //                break;
                //            default:
                //                tmpstr = "状态错误";
                //                break;
                //        }
                //        tempshow.SubItems.Add(tmpstr);
                //        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);
                //    }
                //}

                //tempshow = new ListViewItem();
                //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";

                //        if (globaldata.m_signalbuffer.Draw_Port3.Count > 1)
                //        {
                //            bDetvalue = globaldata.m_dpbuffer.ShowList.showDet.bDetValue;

                //            if (bDetvalue != 0)
                //                bDetvalueold = bDetvalue;
                //            else
                //                bDetvalue = bDetvalueold;

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

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

                //        tempshow = new ListViewItem();
                //        tempshow.Text = "桥流状态";
                //        if (globaldata.m_dpbuffer.ShowList.showDet.bDetSwitch)
                //        {
                //            tempshow.SubItems.Add("开");
                //        }
                //        else
                //        {
                //            tempshow.SubItems.Add("关");
                //        }

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

                //        tempshow = new ListViewItem();
                //        tempshow.Text = "桥流值";

                //        tempshow.SubItems.Add(globaldata.m_dpbuffer.ShowList.showDet.bDetStatue.ToString());
                //        this.datalist.Items.Add(tempshow);
                //    }
                    //else if (CProfileDevice.m_DevParam.syspara.u16DetBehindType == 1)
                    //{
                    //    tempshow = new ListViewItem();
                    //    tempshow.Text = "FID3";

                    //    if (globaldata.m_signalbuffer.Draw_Port3.Count > 1)
                    //    {
                    //        bDetvalue = globaldata.m_dpbuffer.ShowList.showDet.bDetValue;

                    //        if (bDetvalue != 0)
                    //            bDetvalueold = bDetvalue;
                    //        else
                    //            bDetvalue = bDetvalueold;

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

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

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

                    //    string tmpstr = null;
                    //    switch (globaldata.m_dpbuffer.ShowList.showDet.bDetStatue)
                    //    {
                    //        case 0:
                    //            tmpstr = "未点火";
                    //            break;
                    //        case 1:
                    //            tmpstr = "点火中";
                    //            break;
                    //        case 2:
                    //            tmpstr = "点火成功";
                    //            break;
                    //        case 3:
                    //            tmpstr = "点火失败";
                    //            break;
                    //        case 4:
                    //            tmpstr = "火焰熄灭";
                    //            break;
                    //        case 5:
                    //            tmpstr = "重新点火";
                    //            break;
                    //        default:
                    //            tmpstr = "状态错误";
                    //            break;
                    //    }
                    //    tempshow.SubItems.Add(tmpstr);

                    //    //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;
                    switch (globaldata.m_dpbuffer.ShowList.showDet.fDetStatue)
                    {
                        case 0:
                            ModbusLib.Globaldata.tcpGlobaldata.fstate=0x00;
                            break;
                        case 1:
                            ModbusLib.Globaldata.tcpGlobaldata.fstate=0x02;
                            break;
                        case 2:
                           
                            ModbusLib.Globaldata.tcpGlobaldata.fstate=0x03;
                            break;
                        case 3:
                            ModbusLib.Globaldata.tcpGlobaldata.warningcount.Add((byte)194); 
                            ModbusLib.Globaldata.tcpGlobaldata.fstate=0x04;
                            break;
                        case 4:
                            ModbusLib.Globaldata.tcpGlobaldata.warningcount.Add((byte)196); 
                            ModbusLib.Globaldata.tcpGlobaldata.fstate=0x05;
                            break;
                        case 5:
                            ModbusLib.Globaldata.tcpGlobaldata.fstate=0x01;  //点火准备好
                            break;
                        default:
                            ModbusLib.Globaldata.tcpGlobaldata.warningcount.Add((byte)193);  //传感器错误
                            break;
                    }

                    //子状态
                    if (globaldata.m_hmibuffer.gcinfo.TenRelay[0] == 1 && globaldata.m_hmibuffer.gcinfo.TenRelay[1] == 1 && globaldata.m_hmibuffer.gcinfo.TenRelay[4] == 1 && globaldata.m_hmibuffer.gcinfo.TenRelay[5]==1)
                    {
                        ModbusLib.Globaldata.tcpGlobaldata.rcount = 0x02;
                    }
                    else if (globaldata.m_hmibuffer.gcinfo.TenRelay[2] == 1 && globaldata.m_hmibuffer.gcinfo.TenRelay[3] == 1 && globaldata.m_hmibuffer.gcinfo.TenRelay[4] == 1 && globaldata.m_hmibuffer.gcinfo.TenRelay[5] == 1)
                    {
                        ModbusLib.Globaldata.tcpGlobaldata.rcount = 0x04;
                    }
                    else
                    {
                        ModbusLib.Globaldata.tcpGlobaldata.rcount = 0x00;
                    }
                    ModbusLib.Globaldata.tcpGlobaldata.temp1 = globaldata.m_dpbuffer.ShowList.showtemp.ColActualTemp;
                    ModbusLib.Globaldata.tcpGlobaldata.temp2 = globaldata.m_dpbuffer.ShowList.showtemp.AuxActualTemp1;
                    ModbusLib.Globaldata.tcpGlobaldata.temp3 = globaldata.m_dpbuffer.ShowList.showtemp.fDetActualTemp;
                    //仪器状态
                    if (CProfileDevice.m_DevParam.valve.u16ValveSetTime2[2] > 0)
                        ModbusLib.Globaldata.tcpGlobaldata.ppmstate = 0x03;  //标定
                    else if (CProfileDevice.m_DevParam.valve.u16ValveSetTime2[3] > 0)
                        ModbusLib.Globaldata.tcpGlobaldata.ppmstate = 0x01;  //零气
                    else ModbusLib.Globaldata.tcpGlobaldata.ppmstate = 0x01;
                    
                }

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

    }
}
