zoukankan      html  css  js  c++  java
  • 工业控制系统之葡萄酒保温发酵控制系统

    简单介绍一下项目背景:

    大家喜爱的葡萄酒需要经过原料选择→分选→去梗→破碎→消毒→前发酵→压榨→调整酒度→后发酵→贮藏→沉清过滤→装瓶、杀菌这几个过程,

    保温发酵控制系统是其中重要一环,葡萄酒经过前期工艺后,在发酵罐常期进行发酵,温度必须保证在一定范围,温度高时需要制冷。温度高了需要

    进行搅拌,不至于结冰。往复的过程。

    在项目中运用到数据库、多线程、现场采集、液位显示等。

    动态显示每个发酵罐或者保温罐相关信息与参数,可以设定制定控制还是手动控制。

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using ZedGraph;
    
    namespace work
    {
    	public partial class FormDisplay : Form
    	{
    		// Starting time in milliseconds
    		int tickStart = 0;
            string obj_gh;
            string device;
            public DataSet ds;
            private System.Windows.Forms.DataGridTableStyle ts;
    		public FormDisplay(string gh)
    		{
                obj_gh = gh;
           
    			InitializeComponent();
    		}
            private void FillData(string gh)
            {
                DataSet dsmatno;
                string selectmatno = " select mname from matno ";
                selectmatno = selectmatno + " order by matnoid desc";
                dsmatno = Narnu.GetDataSetByOleDbString(selectmatno);
                cb_pm.DataSource = dsmatno.Tables[0];
                cb_pm.DisplayMember = "mname";
                datagrid.TableStyles.Clear();
                ts = new DataGridTableStyle();
                ts.RowHeadersVisible = false;
    
                DataSet ds;
                string selectgh = " select * from wd ";
                selectgh =selectgh + " where gh = '" + gh.ToString()+  "'" + " order by tkdat1 desc";
                ds = Narnu.GetDataSetByOleDbString(selectgh);
    
                ts.MappingName = ds.Tables[0].TableName;
                //ts.AlternatingBackColor = Color.LightSkyBlue;
                ts.AllowSorting = false;
                //id, palno, addre, addre_desc, trans, trans_ssj, trans_ddj, deviceno,
                //xd, statu, deviceno_desc, port, port_desc, ssj, ddj, pri, error, fflag, tkdat
                setcolumn("gh", "罐号", 120);
                setcolumn("op", "操作", 120);
                setcolumn("sdwd", "设定温度", 120);
                setcolumn("sjwd1", "高位温度", 120);
                setcolumn("sjwd2", "低位温度", 120);
                setcolumn("tkdat1", "时间", 120);
                setcolumn("deviceno", "设备号", 40);
                setcolumn("trans", "电报", 150);
                setcolumn("statu", "状态", 50);
                setcolumn("error", "故障信息", 150);
                setcolumn("tkdat", "产生时间", 120);
                setcolumn("xd", "巷道", 50);
                setcolumn("port", "口地址", 50);
                setcolumn("if_do", "状态", 40);
                setcolumn("alock", "锁定状态", 40);
                setcolumn("sectn", "库区", 40);
    
    
                datagrid.TableStyles.Add(ts);
                this.datagrid.DataSource = ds.Tables[0];
                this.dataGridView1.DataSource = ds.Tables[0];
            }
            private void FillDataTk(string gh,DateTime tk)
            {
    
                datagrid.TableStyles.Clear();
                ts = new DataGridTableStyle();
                ts.RowHeadersVisible = false;
    
                DataSet ds;
                string selectgh = " select * from wd ";
                selectgh = selectgh + " where gh = '" + gh.ToString() + "'" + " and tkdat1>=Cdate('" + tk + "')" + " order by tkdat1 desc";
             
                ds = Narnu.GetDataSetByOleDbString(selectgh);
    
                ts.MappingName = ds.Tables[0].TableName;
                //ts.AlternatingBackColor = Color.LightSkyBlue;
                ts.AllowSorting = false;
                //id, palno, addre, addre_desc, trans, trans_ssj, trans_ddj, deviceno,
                //xd, statu, deviceno_desc, port, port_desc, ssj, ddj, pri, error, fflag, tkdat
                setcolumn("sdwd", "设定温度", 120);
                setcolumn("sjwd1", "高位温度", 120);
                setcolumn("sjwd2", "低位温度", 120);
                setcolumn("gh", "罐号", 120);
                setcolumn("op", "操作", 120);
                setcolumn("tkdat1", "时间", 120);
                setcolumn("deviceno", "设备号", 40);
                setcolumn("trans", "电报", 150);
                setcolumn("statu", "状态", 50);
                setcolumn("error", "故障信息", 150);
                setcolumn("tkdat", "产生时间", 120);
                setcolumn("xd", "巷道", 50);
                setcolumn("port", "口地址", 50);
                setcolumn("if_do", "状态", 40);
                setcolumn("alock", "锁定状态", 40);
                setcolumn("sectn", "库区", 40);
    
    
                datagrid.TableStyles.Add(ts);
                this.datagrid.DataSource = ds.Tables[0];
                this.dataGridView1.DataSource = ds.Tables[0];
            }
            private void setcolumn(string name, string text, int width)
            {
                DataGridTextBoxColumn C = new DataGridTextBoxColumn();
                //			DataGridColumnStyle	CStyle = new DataGridColumnStyle();
                //youFirstFieldName是你的Table里的某个字段名  
                C.MappingName = name;
                //youHeaderName是你希望将上面这个字段显示在DataGrid里时的标题
                C.HeaderText = text;
                C.Width = width;
                C.Alignment = HorizontalAlignment.Center;
                //响应鼠标单击与双击事件
                //			C.TextBox.MouseDown += new MouseEventHandler(TextBoxMouseDownHandler);
    
                ts.GridColumnStyles.Add(C);
                C.Dispose();
            }
    
    		private void Form1_Load( object sender, EventArgs e )
    		{
                // TODO: 这行代码将数据加载到表“bookShopDataSet.wd”中。您可以根据需要移动或移除它。
                //this.wdTableAdapter.Fill(this.bookShopDataSet.wd);
                //foreach (Form froms in this)//检查窗体是否存在
                //{
                //    if (froms is work.FormDisplay)
                //    {
                //        froms.Focus();//获得焦点 
                //        return;//退出过程 
                //    }
                //}
               // MessageBox.Show(obj_gh);
                dateTimePicker1.Value = DateTime.Now.AddDays(-1);
                string gh = "";
                lb_gh.Text = obj_gh.Substring(0, 4).ToUpper() ;
                gh = obj_gh.Substring(0, 4).ToUpper();
                device = obj_gh.Substring(5, 2);
               // MessageBox.Show(device);
    			GraphPane myPane = zedGraphControl1.GraphPane;
    			myPane.Title.Text = "温度实时曲线
    ";
    			myPane.XAxis.Title.Text = "时间, 秒";
    			myPane.YAxis.Title.Text = "温度";
                old_wd.Text = MainForm.pMainWin.sdwd[Convert.ToInt32(device) - 1];
                sd_wd.Text = MainForm.pMainWin.sdwd[Convert.ToInt32(device) - 1];
    			// Save 1200 points.  At 50 ms sample rate, this is one minute
    			// The RollingPointPairList is an efficient storage class that always
    			// keeps a rolling set of point data without needing to shift any data values
                //设置1200个点,假设每50毫秒更新一次,刚好检测1分钟
                //一旦构造后将不能更改这个值
                RollingPointPairList list = new RollingPointPairList( 1200 );
    
    			// Initially, a curve is added with no data points (list is empty)
    			// Color is blue, and there will be no symbols
                //开始,增加的线是没有数据点的(也就是list为空)
                //增加一条名称:Voltage,颜色Color.Bule,无符号,无数据的空线条
    			LineItem curve = myPane.AddCurve( "温度", list, Color.Blue, SymbolType.None );
    
    			// Sample at 50ms intervals
                //设置timer控件的间隔为50毫秒
    
    			timer1.Interval = 50;
    			timer1.Enabled = true;
    			timer1.Start();
    
    			// Just manually control the X axis range so it scrolls continuously
    			// instead of discrete step-sized jumps
    			myPane.XAxis.Scale.Min = 0;
                //X轴最小值0
    			myPane.XAxis.Scale.Max = 30;
                //X轴最大30
    			myPane.XAxis.Scale.MinorStep = 1;
                //X轴小步长1,也就是小间隔
    			myPane.XAxis.Scale.MajorStep = 5;
                //X轴大步长为5,也就是显示文字的大间隔
    
    			// Scale the axes
                //改变轴的刻度
    			zedGraphControl1.AxisChange();
        
    			// Save the beginning time for reference
                //保存开始时间
    			tickStart = Environment.TickCount;
    
                //
                DataSet ds;
                string selectgh = " select * from gh where gh = '" + gh + "'" + " and finish='" + "1" + "' order by tkdat1 desc";
                ds = Narnu.GetDataSetByOleDbString(selectgh);
                if (ds.Tables["gh"].Rows.Count == 0)
                {
                    cb_pm.Text = "";
                    tb_batch.Text = "";
                    bt_st.Enabled = true;
                    bt_com.Enabled = false;
                    //cb_pm
                }
                else
                {
                    cb_pm.Text = ds.Tables["gh"].Rows[0][6].ToString();
                    tb_batch.Text = ds.Tables["gh"].Rows[0][5].ToString();
                    bt_st.Enabled = false;
                    bt_com.Enabled = true;
                }
                FillData(gh.ToString());
                //string gh = "";
                lb_gh.Text = obj_gh.Substring(0, 4).ToUpper();
                gh = obj_gh.Substring(0, 4).ToUpper();
                device = obj_gh.Substring(5, 2);
                DateTime tk;
                //DataSet ds;
                tk = Convert.ToDateTime(dateTimePicker1.Value);
                // selectgh = " select * from gh where gh = '" + gh + "'" + " and tkdat1>=Cdate('" + tk + "')" + " and finish='" + "1" + "' order by tkdat1 desc";
                //ds = Narnu.GetDataSetByOleDbString(selectgh);
                //if (ds.Tables["gh"].Rows.Count == 0)
                //{
                //    cb_pm.Text = "";
                //    tb_batch.Text = "";
                //    bt_st.Enabled = true;
                //    bt_com.Enabled = false;
                //    //cb_pm
                //}
                //else
                //{
                //    cb_pm.Text = ds.Tables["gh"].Rows[0][6].ToString();
                //    tb_batch.Text = ds.Tables["gh"].Rows[0][5].ToString();
                //    bt_st.Enabled = false;
                //    bt_com.Enabled = true;
                //}
                FillDataTk(gh.ToString(), tk);
                    
    		}
    
    		private void timer1_Tick( object sender, EventArgs e )
    		{
                if (MainForm.pMainWin.zhileng[Convert.ToInt32(device)-1] == 1)
                {
                    if (sg22_17_01.State != LBSoft.IndustrialCtrls.Leds.LBLed.LedState.Blink)
                    {
                        sg22_17_01.State = LBSoft.IndustrialCtrls.Leds.LBLed.LedState.Blink;
                    }
                }
                if (MainForm.pMainWin.zhileng[Convert.ToInt32(device)-1] == 0)
                {
                    sg22_17_01.State = LBSoft.IndustrialCtrls.Leds.LBLed.LedState.Off;
                    //LBSoft.IndustrialCtrls.Leds.LBLed.LedState.Off; ;
                }
                if (MainForm.pMainWin.jiaoban[Convert.ToInt32(device)-1] == 1)
                {
                    if (sf09_12_dj.State != LBSoft.IndustrialCtrls.Leds.LBLed.LedState.Blink)
                    {
                        sf09_12_dj.State = LBSoft.IndustrialCtrls.Leds.LBLed.LedState.Blink;
                    }
                }
                if (MainForm.pMainWin.jiaoban[Convert.ToInt32(device)-1] == 0)
                {
                    sf09_12_dj.State = LBSoft.IndustrialCtrls.Leds.LBLed.LedState.Off;
                }
                // Make sure that the curvelist has at least one curve
                //确保CurveList不为空
                double var=3;
                var = Convert.ToDouble(MainForm.pMainWin.sjwd1[Convert.ToInt32(device)-1]);
    			if ( zedGraphControl1.GraphPane.CurveList.Count <= 0 )
    				return;
    
    			// Get the first CurveItem in the graph
                //取Graph第一个曲线,也就是第一步:在GraphPane.CurveList集合中查找CurveItem
    			LineItem curve = zedGraphControl1.GraphPane.CurveList[0] as LineItem;
    			if ( curve == null )
    				return;
    
    			// Get the PointPairList
                //第二步:在CurveItem中访问PointPairList(或者其它的IPointList),根据自己的需要增加新数据或修改已存在的数据
    			IPointListEdit list = curve.Points as IPointListEdit;
    			// If this is null, it means the reference at curve.Points does not
    			// support IPointListEdit, so we won't be able to modify it
    			if ( list == null )
    				return;
    
    			// Time is measured in seconds
    			double time = ( Environment.TickCount - tickStart ) / 10000.0;
    
    			// 3 seconds per cycle
    			//list.Add( time, Math.Sin( 2.0 * Math.PI * time / 3.0 ) );
                list.Add(time,var);
                //var = MainForm.pMainWin.
    			// Keep the X scale at a rolling 30 second interval, with one
    			// major step between the max X value and the end of the axis
    			Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale;
    			if ( time > xScale.Max - xScale.MajorStep )
    			{
    				xScale.Max = time + xScale.MajorStep;
    				xScale.Min = xScale.Max - 30.0;
    			}
    
    			// Make sure the Y axis is rescaled to accommodate actual data
                //第三步:调用ZedGraphControl.AxisChange()方法更新X和Y轴的范围
    			zedGraphControl1.AxisChange();
    			// Force a redraw
                //第四步:调用Form.Invalidate()方法更新图表
    			zedGraphControl1.Invalidate();
    		}
    
    		private void Form1_Resize( object sender, EventArgs e )
    		{
    			//SetSize();
    		}
    
    		// Set the size and location of the ZedGraphControl
    		private void SetSize()
    		{
              
    		}
    
            private void button1_Click(object sender, EventArgs e)
            {
                string device_write="";
                int deviceno;
                deviceno = Convert.ToInt32(device);
               
                if (deviceno == 1)
                {
                    device_write = "64";
                }
                if (deviceno == 2)
                {
                    device_write = "65";
                }
                if (deviceno == 3)
                {
                    device_write = "66";
                }
                if (deviceno == 4)
                {
                    device_write = "67";
                }
    
                if (deviceno == 5)
                {
                    device_write = "44";
                }
                if (deviceno == 6)
                {
                    device_write = "45";
                }
                if (deviceno == 7)
                {
                    device_write = "46";
                }
                if (deviceno == 8)
                {
                    device_write = "47";
                }
    
                if (deviceno == 9)
                {
                    device_write = "52";
                }
                if (deviceno == 10)
                {
                    device_write = "53";
                }
                if (deviceno == 11)
                {
                    device_write = "54";
                }
                if (deviceno == 12)
                {
                    device_write = "55";
                }
    
                if (deviceno == 13)
                {
                    device_write = "60";
                }
                if (deviceno == 14)
                {
                    device_write = "61";
                }
                if (deviceno == 15)
                {
                    device_write = "62";
                }
                if (deviceno == 16)
                {
                    device_write = "63";
                }
    
                if (deviceno == 17)
                {
                    device_write = "68";
                }
                if (deviceno == 18)
                {
                    device_write = "69";
                }
                if (deviceno == 19)
                {
                    device_write = "70";
                }
                if (deviceno == 20)
                {
                    device_write = "71";
                }
              
                DialogResult result = MainForm.pMainWin.ls_IniFile.ShowDeleteAlert("是否关闭电磁阀" + "
    ");
                if (result == DialogResult.No)
                {
                    return;
                }
                MainForm.pMainWin.objPlc1.Writeplc(device_write, "0");
    
                string tkdat1 = "";
                string tkdat2 = "";
                string userid = "admin";
                string pm = "";
                string batch = "";
                string gh = "";
                string SetValue;
                string insertgh;
                string sdwd_t = "";
                string sjwd1_t = "";
                string sjwd2_t = "";
                string yali_t = "";
                string op_t = "";
                op_t ="关闭电磁阀";
                //string updategh = "update gh set " + "pm ='" + pm + "'," + "gh='" + gh + "'," + "batch='" + batch + "'," + "tkdat1='" + tkdat1 + "'," + "tkdat2='" + tkdat2 + "'," + "userid='" + userid + "' where gh ='" +gh + "'";
                  tkdat1 = DateTime.Now.ToString();
                    tkdat2 = DateTime.Now.ToString();
                    gh = obj_gh.Substring(0, 4).ToUpper();
                    yali_t = MainForm.pMainWin.yl[Convert.ToInt32(device) - 1]; ;
                    sdwd_t = MainForm.pMainWin.sdwd[Convert.ToInt32(device) - 1]; ;
                    sjwd1_t = MainForm.pMainWin.sjwd1[Convert.ToInt32(device) - 1]; ;
                    sjwd2_t = MainForm.pMainWin.sjwd2[Convert.ToInt32(device) - 1]; ;
                    
                    SetValue = "('" + pm + "','" + gh + "','" + batch + "','" + tkdat1 + "','" + tkdat2 + "','" + userid + "','" + "1" + "','" + yali_t + "','" + sdwd_t + "','" + sjwd1_t + "','"+ op_t + "','" + sjwd2_t + "')";
                    insertgh = "insert into wd (pm,gh,batch,tkdat1,tkdat2,userid,finish,yl,sdwd,sjwd1,op,sjwd2) values " + SetValue;
                    try
                    {
                        Narnu.DoOleDbString(insertgh);
    
                    }
                    catch (Exception ex)
                    {
    
                        MainForm.pMainWin.ls_IniFile.WriteLog("write1", ex.Message.ToString());
                        return;
                    }
              
            }
    
            private void button5_Click(object sender, EventArgs e)
            {
                string device_write = "";
                int deviceno;
                deviceno = Convert.ToInt32(device);
    
                if (deviceno == 1)
                {
                    device_write = "64";
                }
                if (deviceno == 2)
                {
                    device_write = "65";
                }
                if (deviceno == 3)
                {
                    device_write = "66";
                }
                if (deviceno == 4)
                {
                    device_write = "67";
                }
    
                if (deviceno == 5)
                {
                    device_write = "44";
                }
                if (deviceno == 6)
                {
                    device_write = "45";
                }
                if (deviceno == 7)
                {
                    device_write = "46";
                }
                if (deviceno == 8)
                {
                    device_write = "47";
                }
    
                if (deviceno == 9)
                {
                    device_write = "52";
                }
                if (deviceno == 10)
                {
                    device_write = "53";
                }
                if (deviceno == 11)
                {
                    device_write = "54";
                }
                if (deviceno == 12)
                {
                    device_write = "55";
                }
    
                if (deviceno == 13)
                {
                    device_write = "60";
                }
                if (deviceno == 14)
                {
                    device_write = "61";
                }
                if (deviceno == 15)
                {
                    device_write = "62";
                }
                if (deviceno == 16)
                {
                    device_write = "63";
                }
    
                if (deviceno == 17)
                {
                    device_write = "68";
                }
                if (deviceno == 18)
                {
                    device_write = "69";
                }
                if (deviceno == 19)
                {
                    device_write = "70";
                }
                if (deviceno == 20)
                {
                    device_write = "71";
                }
                //device
                //zhileng[0] = Convert.ToInt32(objPlc1.ReadPlc("64"));
                //MessageBox.Show(zhileng[0].ToString());
                //zhileng[1] = Convert.ToInt32(objPlc1.ReadPlc("65"));
                //zhileng[2] = Convert.ToInt32(objPlc1.ReadPlc("66"));
                //zhileng[3] = Convert.ToInt32(objPlc1.ReadPlc("67"));
    
                //zhileng[4] = Convert.ToInt32(objPlc1.ReadPlc("44"));
                //zhileng[5] = Convert.ToInt32(objPlc1.ReadPlc("45"));
                //zhileng[6] = Convert.ToInt32(objPlc1.ReadPlc("46"));
                //zhileng[7] = Convert.ToInt32(objPlc1.ReadPlc("47"));
    
                //zhileng[8] = Convert.ToInt32(objPlc1.ReadPlc("52"));
                //zhileng[9] = Convert.ToInt32(objPlc1.ReadPlc("53"));
                //zhileng[10] = Convert.ToInt32(objPlc1.ReadPlc("54"));
                //zhileng[11] = Convert.ToInt32(objPlc1.ReadPlc("55"));
    
                //zhileng[12] = Convert.ToInt32(objPlc1.ReadPlc("60"));
                //zhileng[13] = Convert.ToInt32(objPlc1.ReadPlc("61"));
                //zhileng[14] = Convert.ToInt32(objPlc1.ReadPlc("62"));
                //zhileng[15] = Convert.ToInt32(objPlc1.ReadPlc("63"));
    
                //zhileng[16] = Convert.ToInt32(objPlc1.ReadPlc("68"));
                //zhileng[17] = Convert.ToInt32(objPlc1.ReadPlc("69"));
                //zhileng[18] = Convert.ToInt32(objPlc1.ReadPlc("70"));
                //zhileng[19] = Convert.ToInt32(objPlc1.ReadPlc("71"));
                DialogResult result = MainForm.pMainWin.ls_IniFile.ShowDeleteAlert("是否开启电磁阀" + "
    ");
                if (result == DialogResult.No)
                {
                    return;
                }
                MainForm.pMainWin.objPlc1.Writeplc(device_write, "1");
    
                string tkdat1 = "";
                string tkdat2 = "";
                string userid = "admin";
                string pm = "";
                string batch = "";
                string gh = "";
                string SetValue;
                string insertgh;
                string sdwd_t = "";
                string sjwd1_t = "";
                string sjwd2_t = "";
                string yali_t = "";
                string op_t = "";
                op_t = "开启电磁阀";
                //string updategh = "update gh set " + "pm ='" + pm + "'," + "gh='" + gh + "'," + "batch='" + batch + "'," + "tkdat1='" + tkdat1 + "'," + "tkdat2='" + tkdat2 + "'," + "userid='" + userid + "' where gh ='" +gh + "'";
                tkdat1 = DateTime.Now.ToString();
                tkdat2 = DateTime.Now.ToString();
                gh = obj_gh.Substring(0, 4).ToUpper();
                yali_t = MainForm.pMainWin.yl[Convert.ToInt32(device) - 1]; ;
                sdwd_t = MainForm.pMainWin.sdwd[Convert.ToInt32(device) - 1]; ;
                sjwd1_t = MainForm.pMainWin.sjwd1[Convert.ToInt32(device) - 1]; ;
                sjwd2_t = MainForm.pMainWin.sjwd2[Convert.ToInt32(device) - 1]; ;
    
                SetValue = "('" + pm + "','" + gh + "','" + batch + "','" + tkdat1 + "','" + tkdat2 + "','" + userid + "','" + "1" + "','" + yali_t + "','" + sdwd_t + "','" + sjwd1_t + "','" + op_t + "','" + sjwd2_t + "')";
                insertgh = "insert into wd (pm,gh,batch,tkdat1,tkdat2,userid,finish,yl,sdwd,sjwd1,op,sjwd2) values " + SetValue;
                try
                {
                    Narnu.DoOleDbString(insertgh);
    
                }
                catch (Exception ex)
                {
    
                    MainForm.pMainWin.ls_IniFile.WriteLog("write1", ex.Message.ToString());
                    return;
                }
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                string device_write="";
                int deviceno;
                deviceno = Convert.ToInt32(device);
                if (deviceno == 1)
                {
                    device_write="30";
                }
                if (deviceno == 2)
                {
                    device_write="31";
                }
                if (deviceno == 3)
                {
                    device_write="32";
                }
                if (deviceno == 4)
                {
                    device_write="33";
                }
                if (deviceno == 5)
                {
                    device_write="34";
                }
                if (deviceno == 6)
                {
                    device_write="35";
                }
                if (deviceno == 7)
                {
                    device_write = "36";
                }
                if (deviceno == 8)
                {
                    device_write="37";
                }
    
                if (deviceno ==9)
                {
                    device_write="40";
                }
                if (deviceno == 10)
                {
                    device_write="41";
                }
                if (deviceno == 11)
                {
                    device_write = "42";
                }
                if (deviceno == 12)
                {
                    device_write = "43";
                }
    
                if (deviceno == 13)
                {
                    device_write = "48";
                }
                if (deviceno == 14)
                {
                    device_write = "49";
                }
                if (deviceno == 15)
                {
                    device_write = "50";
                }
                if (deviceno == 16)
                {
                    device_write = "51";
                }
    
                if (deviceno == 17)
                {
                    device_write = "56";
                }
                if (deviceno == 18)
                {
                    device_write = "57";
                }
                if (deviceno == 19)
                {
                    device_write = "58";
                }
                if (deviceno == 20)
                {
                    device_write = "59";
                }
                //device
                //jiaoban[0] = Convert.ToInt32(objPlc1.ReadPlc("30"));
                //jiaoban[1] = Convert.ToInt32(objPlc1.ReadPlc("31"));
                //jiaoban[2] = Convert.ToInt32(objPlc1.ReadPlc("32"));
                //jiaoban[3] = Convert.ToInt32(objPlc1.ReadPlc("33"));
                //jiaoban[4] = Convert.ToInt32(objPlc1.ReadPlc("34"));
                //jiaoban[5] = Convert.ToInt32(objPlc1.ReadPlc("35"));
                //jiaoban[6] = Convert.ToInt32(objPlc1.ReadPlc("36"));
                //jiaoban[7] = Convert.ToInt32(objPlc1.ReadPlc("37"));
    
                //jiaoban[8] = Convert.ToInt32(objPlc1.ReadPlc("40"));
                //jiaoban[9] = Convert.ToInt32(objPlc1.ReadPlc("41"));
                //jiaoban[10] = Convert.ToInt32(objPlc1.ReadPlc("42"));
                //jiaoban[11] = Convert.ToInt32(objPlc1.ReadPlc("43"));
    
                //jiaoban[12] = Convert.ToInt32(objPlc1.ReadPlc("48"));
                //jiaoban[14] = Convert.ToInt32(objPlc1.ReadPlc("50"));
                //jiaoban[15] = Convert.ToInt32(objPlc1.ReadPlc("51"));
    
                //jiaoban[16] = Convert.ToInt32(objPlc1.ReadPlc("56"));
                //jiaoban[17] = Convert.ToInt32(objPlc1.ReadPlc("57"));
                //jiaoban[18] = Convert.ToInt32(objPlc1.ReadPlc("58"));
                //jiaoban[19] = Convert.ToInt32(objPlc1.ReadPlc("59"));
                DialogResult result = MainForm.pMainWin.ls_IniFile.ShowDeleteAlert("是否关闭搅拌" + "
    ");
                if (result == DialogResult.No)
                {
                    return;
                }
                MainForm.pMainWin.objPlc1.Writeplc(device_write, "0");
    
                string tkdat1 = "";
                string tkdat2 = "";
                string userid = "admin";
                string pm = "";
                string batch = "";
                string gh = "";
                string SetValue;
                string insertgh;
                string sdwd_t = "";
                string sjwd1_t = "";
                string sjwd2_t = "";
                string yali_t = "";
                string op_t = "";
                op_t = "关闭搅拌";
                //string updategh = "update gh set " + "pm ='" + pm + "'," + "gh='" + gh + "'," + "batch='" + batch + "'," + "tkdat1='" + tkdat1 + "'," + "tkdat2='" + tkdat2 + "'," + "userid='" + userid + "' where gh ='" +gh + "'";
                tkdat1 = DateTime.Now.ToString();
                tkdat2 = DateTime.Now.ToString();
                gh = obj_gh.Substring(0, 4).ToUpper();
                yali_t = MainForm.pMainWin.yl[Convert.ToInt32(device) - 1]; ;
                sdwd_t = MainForm.pMainWin.sdwd[Convert.ToInt32(device) - 1]; ;
                sjwd1_t = MainForm.pMainWin.sjwd1[Convert.ToInt32(device) - 1]; ;
                sjwd2_t = MainForm.pMainWin.sjwd2[Convert.ToInt32(device) - 1]; ;
    
                SetValue = "('" + pm + "','" + gh + "','" + batch + "','" + tkdat1 + "','" + tkdat2 + "','" + userid + "','" + "1" + "','" + yali_t + "','" + sdwd_t + "','" + sjwd1_t + "','" + op_t + "','" + sjwd2_t + "')";
                insertgh = "insert into wd (pm,gh,batch,tkdat1,tkdat2,userid,finish,yl,sdwd,sjwd1,op,sjwd2) values " + SetValue;
                try
                {
                    Narnu.DoOleDbString(insertgh);
    
                }
                catch (Exception ex)
                {
    
                    MainForm.pMainWin.ls_IniFile.WriteLog("write1", ex.Message.ToString());
                    return;
                }
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                string device_write="";
                int deviceno;
                deviceno = Convert.ToInt32(device);
                if (deviceno == 1)
                {
                    device_write = "30";
                }
                if (deviceno == 2)
                {
                    device_write = "31";
                }
                if (deviceno == 3)
                {
                    device_write = "32";
                }
                if (deviceno == 4)
                {
                    device_write = "33";
                }
                if (deviceno == 5)
                {
                    device_write = "34";
                }
                if (deviceno == 6)
                {
                    device_write = "35";
                }
                if (deviceno == 7)
                {
                    device_write = "36";
                }
                if (deviceno == 8)
                {
                    device_write = "37";
                }
    
                if (deviceno == 9)
                {
                    device_write = "40";
                }
                if (deviceno == 10)
                {
                    device_write = "41";
                }
                if (deviceno == 11)
                {
                    device_write = "42";
                }
                if (deviceno == 12)
                {
                    device_write = "43";
                }
    
                if (deviceno == 13)
                {
                    device_write = "48";
                }
                if (deviceno == 14)
                {
                    device_write = "49";
                }
                if (deviceno == 15)
                {
                    device_write = "50";
                }
                if (deviceno == 16)
                {
                    device_write = "51";
                }
    
                if (deviceno == 17)
                {
                    device_write = "56";
                }
                if (deviceno == 18)
                {
                    device_write = "57";
                }
                if (deviceno == 19)
                {
                    device_write = "58";
                }
                if (deviceno == 20)
                {
                    device_write = "59";
                }
                //device
                //jiaoban[0] = Convert.ToInt32(objPlc1.ReadPlc("30"));
                //jiaoban[1] = Convert.ToInt32(objPlc1.ReadPlc("31"));
                //jiaoban[2] = Convert.ToInt32(objPlc1.ReadPlc("32"));
                //jiaoban[3] = Convert.ToInt32(objPlc1.ReadPlc("33"));
                //jiaoban[4] = Convert.ToInt32(objPlc1.ReadPlc("34"));
                //jiaoban[5] = Convert.ToInt32(objPlc1.ReadPlc("35"));
                //jiaoban[6] = Convert.ToInt32(objPlc1.ReadPlc("36"));
                //jiaoban[7] = Convert.ToInt32(objPlc1.ReadPlc("37"));
    
                //jiaoban[8] = Convert.ToInt32(objPlc1.ReadPlc("40"));
                //jiaoban[9] = Convert.ToInt32(objPlc1.ReadPlc("41"));
                //jiaoban[10] = Convert.ToInt32(objPlc1.ReadPlc("42"));
                //jiaoban[11] = Convert.ToInt32(objPlc1.ReadPlc("43"));
    
                //jiaoban[12] = Convert.ToInt32(objPlc1.ReadPlc("48"));
                //jiaoban[14] = Convert.ToInt32(objPlc1.ReadPlc("50"));
                //jiaoban[15] = Convert.ToInt32(objPlc1.ReadPlc("51"));
    
                //jiaoban[16] = Convert.ToInt32(objPlc1.ReadPlc("56"));
                //jiaoban[17] = Convert.ToInt32(objPlc1.ReadPlc("57"));
                //jiaoban[18] = Convert.ToInt32(objPlc1.ReadPlc("58"));
                //jiaoban[19] = Convert.ToInt32(objPlc1.ReadPlc("59"));
                DialogResult result = MainForm.pMainWin.ls_IniFile.ShowDeleteAlert("是否开启搅拌" + "
    ");
                if (result == DialogResult.No)
                {
                    return;
                }
                MainForm.pMainWin.objPlc1.Writeplc(device_write, "1");
                string tkdat1 = "";
                string tkdat2 = "";
                string userid = "admin";
                string pm = "";
                string batch = "";
                string gh = "";
                string SetValue;
                string insertgh;
                string sdwd_t = "";
                string sjwd1_t = "";
                string sjwd2_t = "";
                string yali_t = "";
                string op_t = "";
                op_t = "开启搅拌";
                //string updategh = "update gh set " + "pm ='" + pm + "'," + "gh='" + gh + "'," + "batch='" + batch + "'," + "tkdat1='" + tkdat1 + "'," + "tkdat2='" + tkdat2 + "'," + "userid='" + userid + "' where gh ='" +gh + "'";
                tkdat1 = DateTime.Now.ToString();
                tkdat2 = DateTime.Now.ToString();
                gh = obj_gh.Substring(0, 4).ToUpper();
                yali_t = MainForm.pMainWin.yl[Convert.ToInt32(device) - 1]; ;
                sdwd_t = MainForm.pMainWin.sdwd[Convert.ToInt32(device) - 1]; ;
                sjwd1_t = MainForm.pMainWin.sjwd1[Convert.ToInt32(device) - 1]; ;
                sjwd2_t = MainForm.pMainWin.sjwd2[Convert.ToInt32(device) - 1]; ;
    
                SetValue = "('" + pm + "','" + gh + "','" + batch + "','" + tkdat1 + "','" + tkdat2 + "','" + userid + "','" + "1" + "','" + yali_t + "','" + sdwd_t + "','" + sjwd1_t + "','" + op_t + "','" + sjwd2_t + "')";
                insertgh = "insert into wd (pm,gh,batch,tkdat1,tkdat2,userid,finish,yl,sdwd,sjwd1,op,sjwd2) values " + SetValue;
                try
                {
                    Narnu.DoOleDbString(insertgh);
    
                }
                catch (Exception ex)
                {
    
                    MainForm.pMainWin.ls_IniFile.WriteLog("write1", ex.Message.ToString());
                    return;
                }
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                string op_t = "";
        
                DialogResult result = MainForm.pMainWin.ls_IniFile.ShowDeleteAlert("是否执行操作" + "
    ");
                if (result == DialogResult.No)
                {
                    return;
                }
                if (rb_auto.Checked)
                {
                    MainForm.pMainWin.op[Convert.ToInt32(device) - 1] = 1;
                    MainForm.pMainWin.start[Convert.ToInt32(device) - 1] = 1;
                    op_t = "开启自动";
    
                }
                if (rb_man.Checked)
                {
                    MainForm.pMainWin.op[Convert.ToInt32(device) - 1] = 0;
                    MainForm.pMainWin.start[Convert.ToInt32(device) - 1] = 0;
                    op_t = "开启手动";
                  
                }
                string tkdat1 = "";
                string tkdat2 = "";
                string userid = "admin";
                string pm = "";
                string batch = "";
                string gh = "";
                string SetValue;
                string insertgh;
                string sdwd_t = "";
                string sjwd1_t = "";
                string sjwd2_t = "";
                string yali_t = "";
               
                //string updategh = "update gh set " + "pm ='" + pm + "'," + "gh='" + gh + "'," + "batch='" + batch + "'," + "tkdat1='" + tkdat1 + "'," + "tkdat2='" + tkdat2 + "'," + "userid='" + userid + "' where gh ='" +gh + "'";
                tkdat1 = DateTime.Now.ToString();
                tkdat2 = DateTime.Now.ToString();
                gh = obj_gh.Substring(0, 4).ToUpper();
                yali_t = MainForm.pMainWin.yl[Convert.ToInt32(device) - 1]; 
                sdwd_t = MainForm.pMainWin.sdwd[Convert.ToInt32(device) - 1]; 
                sjwd1_t = MainForm.pMainWin.sjwd1[Convert.ToInt32(device) - 1]; 
                sjwd2_t = MainForm.pMainWin.sjwd2[Convert.ToInt32(device) - 1]; 
                
                SetValue = "('" + pm + "','" + gh + "','" + batch + "','" + tkdat1 + "','" + tkdat2 + "','" + userid + "','" + "1" + "','" + yali_t + "','" + sdwd_t + "','" + sjwd1_t + "','" + op_t + "','" + sjwd2_t + "')";
                insertgh = "insert into wd (pm,gh,batch,tkdat1,tkdat2,userid,finish,yl,sdwd,sjwd1,op,sjwd2) values " + SetValue;
                try
                {
                    Narnu.DoOleDbString(insertgh);
    
                }
                catch (Exception ex)
                {
    
                    MainForm.pMainWin.ls_IniFile.WriteLog("write1", ex.Message.ToString());
                    return;
                }
            }
    
            private void button6_Click(object sender, EventArgs e)
            {
                DialogResult result = MainForm.pMainWin.ls_IniFile.ShowDeleteAlert("是否执行操作" + "
    ");
                if (result == DialogResult.No)
                {
                    return;
                }
                MainForm.pMainWin.sdwd[Convert.ToInt32(device) - 1] = sd_wd.Text;
            }
    
            private void pictureBox1_Click(object sender, EventArgs e)
            {
    
            }
    
            private void button7_Click(object sender, EventArgs e)
            {
                string tkdat1 = DateTime.Now.ToString();
                string tkdat2 = DateTime.Now.ToString();
                string userid = "admin";
                string pm = cb_pm.Text;
                string batch = tb_batch.Text;
                string gh = obj_gh.Substring(0, 4).ToUpper();
                string SetValue = "('" +pm+"','"+gh+"','"+batch+"','"+tkdat1+"','"+tkdat2+"','"+userid+"','"+"1"+ "')"; ;
                string insertgh = "insert into gh (pm,gh,batch,tkdat1,tkdat2,userid,finish) values " + SetValue;
                //string updategh = "update gh set " + "pm ='" + pm + "'," + "gh='" + gh + "'," + "batch='" + batch + "'," + "tkdat1='" + tkdat1 + "'," + "tkdat2='" + tkdat2 + "'," + "userid='" + userid + "' where gh ='" +gh + "'";
                string updategh = "update gh set tkdat2='" + tkdat2 + "'," + " finish ='0',"+ "userid='" + userid + "' where gh ='" + gh + "'";
                string selectgh = " select count(gh) from gh where gh = '" + gh + "'" + " and finish='" +"1"+ "'";
               
                string count="";
                DialogResult result = MainForm.pMainWin.ls_IniFile.ShowDeleteAlert("是否执行操作" + "
    ");
                if (result == DialogResult.No)
                {
                    return;
                }
                try
                {
                    count = Narnu.GetObjectByOleDbString(selectgh).ToString();
                }
                catch(Exception ex)
                {
                    MessageBox.Show("出错!" +ex.ToString());
                    return;
                }
              //  MessageBox.Show(count.ToString());
                if (count == "0")
                {
                    try
                    {
                        Narnu.DoOleDbString(insertgh);
    
                    }
                    catch (Exception ex)
                    {
    
                        MessageBox.Show("保存数据出现错误0!" + ex.ToString());
                        return;
                    }
                }
                else
                {
                    try
                    {
                        Narnu.DoOleDbString(updategh);
    
                    }
                    catch (Exception ex)
                    {
    
                        MessageBox.Show("保存数据出现错误1!" + ex.ToString());
                        return;
                    }
    
                    try
                    {
                        Narnu.DoOleDbString(insertgh);
    
                    }
                    catch (Exception ex)
                    {
    
                        MessageBox.Show("保存数据出现错误2!" + ex.ToString());
                        return;
                    }
                }
                MessageBox.Show("操作成功!");
            }
    
            private void bt_com_Click(object sender, EventArgs e)
            {
                string tkdat1 = DateTime.Now.ToString();
                string tkdat2 = DateTime.Now.ToString();
                string userid = "admin";
                string pm = cb_pm.Text;
                string batch = tb_batch.Text;
                string gh = obj_gh.Substring(0, 4).ToUpper();
                string SetValue = "('" + pm + "','" + gh + "','" + batch + "','" + tkdat1 + "','" + tkdat2 + "','" + userid + "','" + "1" + "')"; ;
                string insertgh = "insert into gh (pm,gh,batch,tkdat1,tkdat2,userid,finish) values " + SetValue;
                //string updategh = "update gh set " + "pm ='" + pm + "'," + "gh='" + gh + "'," + "batch='" + batch + "'," + "tkdat1='" + tkdat1 + "'," + "tkdat2='" + tkdat2 + "'," + "userid='" + userid + "' where gh ='" +gh + "'";
                string updategh = "update gh set tkdat2='" + tkdat2 + "'," + " finish ='0'," + "userid='" + userid + "' where gh ='" + gh + "'";
                string selectgh = " select count(gh) from gh where gh = '" + gh + "'" + " and finish='" + "1" + "'";
               
                DialogResult result = MainForm.pMainWin.ls_IniFile.ShowDeleteAlert("是否执行操作" + "
    ");
                if (result == DialogResult.No)
                {
                    return;
                }
    
                try
                {
                    Narnu.DoOleDbString(updategh);
    
                }
                catch (Exception ex)
                {
    
                    MessageBox.Show("保存数据出现错误1!" + ex.ToString());
                    return;
                }
                MessageBox.Show("操作成功!");
            }
    
            private void button7_Click_1(object sender, EventArgs e)
            {
               
                string gh = "";
                lb_gh.Text = obj_gh.Substring(0, 4).ToUpper();
                gh = obj_gh.Substring(0, 4).ToUpper();
                device = obj_gh.Substring(5, 2);
                DateTime tk;
                DataSet ds;
                tk = Convert.ToDateTime(dateTimePicker1.Value);
                string selectgh = " select * from gh where gh = '" + gh + "'" + " and tkdat1>=Cdate('" +tk  +"')"+ " and finish='" + "1" + "' order by tkdat1 desc";
                ds = Narnu.GetDataSetByOleDbString(selectgh);
                if (ds.Tables["gh"].Rows.Count == 0)
                {
                    cb_pm.Text = "";
                    tb_batch.Text = "";
                    bt_st.Enabled = true;
                    bt_com.Enabled = false;
                    //cb_pm
                }
                else
                {
                    cb_pm.Text = ds.Tables["gh"].Rows[0][6].ToString();
                    tb_batch.Text = ds.Tables["gh"].Rows[0][5].ToString();
                    bt_st.Enabled = false;
                    bt_com.Enabled = true;
                }
                FillDataTk(gh.ToString(),tk);
            }
    
            private void button8_Click(object sender, EventArgs e)
            {
                PrintDGV.Print_DataGridView(this.dataGridView1);
            }
    	}
    }
    

    主要控制程序部分

      1 using System;
      2 using System.Collections.Generic;
      3 using System.ComponentModel;
      4 using System.Data;
      5 using System.Drawing;
      6 using System.Linq;
      7 using System.Text;
      8 using System.Windows.Forms;
      9 using System.Net;
     10 using System.Net.Sockets;
     11 using System.Data.SqlClient;
     12 using System.Data.Sql;
     13 using System.Data.OleDb;
     14 using System.Reflection;
     15 using System.Threading;
     16 using System.Runtime.InteropServices;
     17 using LBSoft.IndustrialCtrls;
     18 using LBSoft.IndustrialCtrls.Meters;
     19 using LBSoft.IndustrialCtrls.Utils;
     20 
     21 
     22 namespace work
     23 {
     24     public partial class FormNew : Form
     25     {
     26         public static FormNew pMainWin = null;
     27 
     28         public Plc objPlc = new Plc();
     29         public PlcSyn objPlc1 = new PlcSyn();
     30         public IniFile ls_IniFile = new IniFile(Environment.CurrentDirectory + "\log.ini");
     31         public Data objData = new Data();
     32         public Mutex mutex;
     33         public string ddj1read = "";
     34         public Thread objThread;
     35 
     36         public string[] sdwd = new string[12];//设定
     37         public string[] sjwd1 = new string[12];//高位
     38         public string[] sjwd2 = new string[12];//低位
     39         public string[] yl = new string[12];//压力
     40         public int[] k_dj = new int[3];
     41         public int[] guzhangshuru = new int[12];
     42         public int[] jiaoban = new int[19];//
     43         public int[] zhileng = new int[12];//制冷
     44         public int[] zhuangtai = new int[12];
     45         public int[] chishu = new int[12];
     46         public int[] op = new int[12];
     47         public string[] opdesc = new string[12];
     48         public Thread objReadwdThread;
     49         public Thread objReadkzThread;
     50         public Thread objFlashztThread;
     51         public int[] jb_time = new int[12];
     52         public int[] sdjb_time = new int[12];
     53 
     54         public int[] zl_time = new int[12];
     55         public int[] flag_30 = new int[12];
     56         public int[] flag_60 = new int[12];
     57         public int[] flag_180 = new int[12];
     58         public int[] flag_10 = new int[12];
     59         public int[] time = new int[12];
     60         public int[] time_flag = new int[12];
     61         public int[] time_zl = new int[12];
     62         public int[] time_zl_flag = new int[12];
     63         public int[] start = new int[12];
     64         public int[] opplc = new int[12];
     65         public int flag42;
     66         public int flag43;
     67         public int flag44;
     68         public string[] pm = new string[12];//压力
     69         public string[] batch = new string[12];//压力
     70         public string[] tkdat = new string[12];//压力
     71         public string gs_userid = "";
     72         public int[] zhileng_temp = new int[12];//制冷
     73 
     74         public int[] op_jb_flag = new int[12];
     75         public int[] op_jb_time = new int[12];
     76         public FormNew(string userid)
     77         {
     78             
     79             InitializeComponent();
     80             pMainWin = this;
     81             mutex = new Mutex(false, "SINGLE_INSTANCE_MUTEX");
     82             if (!mutex.WaitOne(0, false))
     83             {
     84                 mutex.Close();
     85                 mutex = null;
     86             }
     87             this.gs_userid = userid;
     88         }
     89         //判断一个子窗体是否存在
     90         private bool checkChildFrmExist(string childFrmName)
     91         {
     92             foreach (Form childFrm in this.MdiChildren)
     93             {
     94                 //用子窗体的Name进行判断,如果已经存在则将他激活
     95                 if (childFrm.Name == childFrmName)
     96                 {
     97                     if (childFrm.WindowState == FormWindowState.Minimized)
     98                         childFrm.WindowState = FormWindowState.Normal;
     99                     childFrm.Activate();
    100                     return true;
    101                 }
    102             }
    103             return false;
    104         }
    105         public void readwd()
    106         {
    107             int device = 0;
    108             string dev_desc = "";
    109             while (true)
    110             {
    111 
    112                 try
    113                 {
    114                     for (int i = 0; i < 11; i++)
    115                     {
    116                         device = 57 + i * 2;
    117 
    118                         if (i == 11)
    119                         {
    120                             sjwd1[i] = (Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) / 65535 * 50 - 20 + 0.5).ToString("F2");
    121                         }
    122                         if (i == 13)
    123                         {
    124                             sjwd1[i] = (Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) / 65535 * 50 - 20 + 0.5).ToString("F2");
    125                         }
    126                         if (i == 14)
    127                         {
    128                             sjwd1[i] = (Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) / 65535 * 50 - 20 + 0.5).ToString("F2");
    129                         }
    130                         else
    131                         {
    132                             sjwd1[i] = (Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) / 65535 * 50 - 20 + 0.2).ToString("F2");
    133                         }
    134                         if (i < 9)
    135                         {
    136                             dev_desc = "0" + (i + 1).ToString();
    137                             // ii01_011.Text = sjwd1[0];
    138                         }
    139                         else
    140                         {
    141                             dev_desc = (i + 1).ToString();
    142                         }
    143                         if (op[i] == 0)
    144                         {
    145                             opdesc[i] = "手动";
    146                         }
    147                         if (op[i] == 1)
    148                         {
    149                             opdesc[i] = "自动";
    150                         }
    151                         if (op[i] == 2)
    152                         {
    153                             opdesc[i] = "澄清";
    154                         }
    155                         if (op[i] == 3)
    156                         {
    157                             opdesc[i] = "发酵";
    158                         }
    159                         ii01_014.Text = opdesc[0];
    160                         ii02_024.Text = opdesc[1];
    161                         ii03_034.Text = opdesc[2];
    162                         ii04_044.Text = opdesc[3];
    163                         ii05_054.Text = opdesc[4];
    164                         ii06_064.Text = opdesc[5];
    165                         ii07_074.Text = opdesc[6];
    166                         ii08_084.Text = opdesc[7];
    167                         ii09_094.Text = opdesc[8];
    168                         ii10_104.Text = opdesc[9];
    169                         ii11_114.Text = opdesc[10];
    170                    
    171 
    172                         ii01_012.Text = sjwd1[0];
    173                         ii02_022.Text = sjwd1[1];
    174                         ii03_032.Text = sjwd1[2];
    175                         ii04_042.Text = sjwd1[3];
    176                         ii05_052.Text = sjwd1[4];
    177                         ii06_062.Text = sjwd1[5];
    178                         ii07_072.Text = sjwd1[6];
    179                         ii08_082.Text = sjwd1[7];
    180                         ii09_092.Text = sjwd1[8];
    181                         ii10_102.Text = sjwd1[9];
    182                         ii11_112.Text = sjwd1[10];
    183                        
    184                         //
    185                         ii01_011.Text = sdwd[0];
    186                         ii02_021.Text = sdwd[1];
    187                         ii03_031.Text = sdwd[2];
    188                         ii04_041.Text = sdwd[3];
    189                         ii05_051.Text = sdwd[4];
    190                         ii06_061.Text = sdwd[5];
    191                         ii07_071.Text = sdwd[6];
    192                         ii08_081.Text = sdwd[7];
    193                         ii09_091.Text = sdwd[8];
    194                         ii10_101.Text = sdwd[9];
    195                         ii11_111.Text = sdwd[10];
    196                         
    197                         //System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox);
    198                         //FormDisplay FormDisplay = new FormDisplay(pb.Name);
    199                         //FormDisplay.Show();
    200                         // sf01_011.Text = sdwd[0].ToString();
    201                         //  sf01_012.Text = sjwd1[0].ToString();
    202                         //sf01_013.Text = sjwd2[0].ToString();
    203                         // sf01_014.Text = yl[0].ToString();
    204                     }
    205 
    206                     for (int j = 0; j < 11; j++)
    207                     {
    208                         device = 58 + j * 2;
    209                         yl[j] = ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 3.8/ 65535) * 5).ToString("F2");
    210                         if ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 3.9 / 65535) > 4.1)
    211                         {
    212                             yl[j] = ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 3.8/ 65535 - 3.9) * 5 / 4 + 3.8 * 5).ToString("F2");
    213                         }
    214                         else
    215                         {
    216                             yl[j] = ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 3.8 / 65535) * 5).ToString("F2");
    217                         }
    218 
    219                         //
    220                         //if ((Convert.ToDouble(objPlc1.ReadPlc("77")) * 13 / 65535) > 11)
    221                         //{
    222                         //    yl[1] = (((Convert.ToDouble(objPlc1.ReadPlc("77")) * 13 / 65535) - 11) * 20 / 3 + 11 * 23.2 + 0.4).ToString("F2");
    223                         //}
    224                         //else
    225                         //{
    226                         //    yl[1] = ((Convert.ToDouble(objPlc1.ReadPlc("77")) * 13 / 65535) * 23.2 + 0.4).ToString("F2");
    227                         //}
    228                         //if (j == 0)
    229                         //{
    230                         //    yl[j] = ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 4.1 / 65535) * 5.51).ToString("F2");
    231                         //}
    232 
    233                         //if (j == 25)
    234                         //{
    235                         //    if ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 4.5 / 65535) > 11)
    236                         //    {
    237                         //        yl[j] = ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 4.5 / 65535) * 5.61).ToString("F2");
    238                         //    }
    239                         //}
    240 
    241                         //if (j == 26)
    242                         //{
    243                         //    yl[j] = ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 4.5 / 65535) * 5.5).ToString("F2");
    244                         //}
    245                         //if (j == 35)
    246                         //{                        //    yl[j] = ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 4.5 / 65535) * 5.5).ToString("F2");
    247                         //}
    248                         ii01_013.Text = yl[0];
    249                         ii02_023.Text = yl[1];
    250                         ii03_033.Text = yl[2];
    251                         ii04_043.Text = yl[3];
    252                         ii05_053.Text = yl[4];
    253                         ii06_063.Text = yl[5];
    254                         ii07_073.Text = yl[6];
    255                         ii08_083.Text = yl[7];
    256                         ii09_093.Text = yl[8];
    257                         ii10_103.Text = yl[9];
    258                         ii11_113.Text = yl[10];
    259                       
    260                     }
    261 
    262                     for (int k = 0; k < 11; k++)
    263                     {
    264                         device = 19 + k;
    265                         zhileng[k] = Convert.ToInt32(objPlc1.ReadPlc(device.ToString()));
    266                     }
    267 
    268                     for (int m = 0; m < 18; m++)
    269                     {
    270                         device = 1 + m;
    271                         jiaoban[m] = Convert.ToInt32(objPlc1.ReadPlc(device.ToString()));
    272                     }
    273 
    274                     //for (int n = 0; n < 41; n++)
    275                     //{
    276                     //    device = 89 + n;
    277                     //    guzhangshuru[n] = Convert.ToInt32(objPlc1.ReadPlc(device.ToString()));
    278                     //}
    279                     //for (int n = 0; n < 3; n++)
    280                     //{
    281                     //    device = 83 + n;
    282                     //    k_dj[n] = Convert.ToInt32(objPlc1.ReadPlc(device.ToString()));
    283                     //}      
    284                     Thread.Sleep(200);
    285                 }
    286                 catch (Exception e)
    287                 {
    288                     //ls_IniFile.WriteLog("ReadData12", e.Message.ToString());
    289                     continue;
    290                 }
    291 
    292             }
    293         }
    294         private string DateDiff(DateTime DateTime1, DateTime DateTime2)
    295         {
    296             string dateDiff = null;
    297             try
    298             {
    299                 TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
    300                 TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
    301                 TimeSpan ts = ts1.Subtract(ts2).Duration();
    302                 dateDiff = ts.Days.ToString() + ""
    303                 + ts.Hours.ToString() + ""
    304                 + ts.Minutes.ToString() + "";
    305                 //+ ts.Seconds.ToString() + "秒";
    306             }
    307             catch
    308             {
    309 
    310             }
    311             return dateDiff;
    312         }

     仪表显示控件源码 http://files.cnblogs.com/files/meslog/LBIndustrialCtrls_src.zip qq 1153755352

  • 相关阅读:
    重拾web开发JavaScript复习
    Linq GroupBy
    Gotchas 31对目标类型为指涉物为常量的指针类型的类型转换的认识误区
    感谢你遇到的问题
    IDisposable模式的一点理解
    感谢你遇到的问题(2)
    .Net通过OutLook发送邮件,附件的名称太长会显示乱码
    深度学习利器之自动微分(1)
    建议转载的发在文章(Aticles)而不是随笔(Posts)内
    Forum,ForumGroup和my forum的汉译
  • 原文地址:https://www.cnblogs.com/meslog/p/5074632.html
Copyright © 2011-2022 走看看