/// <summary> /// 提交用户的配置到到XML文件中 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { try { //写入产品名称 BussinessFacde.SetConfigXml("ProductionType", productionType.Text); // OPC.WriteItem(17, productionType.Text); //写入产品种类 BussinessFacde.SetConfigXml("materialType", materialType.Text); // OPC.WriteItem(18, materialType.Text); //写入来料方式 BussinessFacde.SetConfigXml("materialWay", materialWay.Text); // OPC.WriteItem(19, materialWay.Text); //写入物料PN BussinessFacde.SetConfigXml("materialPn", materialPn.Text); // OPC.WriteItem(20, materialPn.Text); //写入今日计划 BussinessFacde.SetConfigXml("TodayPlan", number.Text); //写入页面速度 BussinessFacde.SetConfigXml("Speed", speed.Text); //关闭窗口 this.Dispose(); this.Close(); //重新启动 Application.Restart(); } catch { MessageBox.Show("写入数据出错,请检查基础配置是否正确或是否有中文!"); } }
/// <summary> /// 显示产品状态的业务方法 /// </summary> /// <param name="source"></param> /// <param name="e"></param> public void showProductionState(object source, System.Timers.ElapsedEventArgs e) { OverrideTimer tt = (OverrideTimer)source; tt.Stop(); try { //显示产品种类 BeginInvoke((MethodInvoker) delegate() { LB_ProductionType.Text = productionTypeconfig; }); //显示今日计划 BeginInvoke((MethodInvoker) delegate() { LB_TodayPlan.Text = productionTodayPlan + " ea"; }); //显示已经完成的产量 int fishedControl = Convert.ToInt32(BussinessFacde.GetOpcConfigXml("", "1", "2")); //if(Convert.ToInt32(OPC.ReadItem(fishedControl).ToString())==1) //{ string sql = "select distinct sn from OfflinePack where DT between '" + DateTime.Now.ToString("yyyy.MM.dd") + " 00:00:00 ' and '" + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss") + "'"; DataTable dt = new DataTable(); dt = db.ExecuteDataTable(sql); int finishedNumber = dt.Rows.Count; BeginInvoke((MethodInvoker) delegate() { LB_Fished.Text = finishedNumber + " ea"; }); double fishedP = (double)finishedNumber / Convert.ToInt32(productionTodayPlan); BeginInvoke((MethodInvoker) delegate() { LB_FishenP.Text = fishedP.ToString("P"); }); //} int moduleAddr = Convert.ToInt32(BussinessFacde.GetOpcConfigXml("", "4", "2")); string moduleS = OPC.ReadItem(moduleAddr).ToString(); if (moduleS == "1") { BeginInvoke((MethodInvoker) delegate() { moduleStatus.Text = showText; }); BeginInvoke((MethodInvoker) delegate() { moduleStatus.ForeColor = Color.Red; }); } else { BeginInvoke((MethodInvoker) delegate() { moduleStatus.Text = ""; }); } } catch { } finally { tt.Start(); } }
private void DataConfig_Load(object sender, EventArgs e) { try { OPC = new OPCCreate(); productionType.Text = BussinessFacde.GetConfigXml("ProductionType"); materialType.Text = BussinessFacde.GetConfigXml("materialType"); //写入来料方式 materialWay.Text = BussinessFacde.GetConfigXml("materialWay"); //写入物料PN materialPn.Text = BussinessFacde.GetConfigXml("materialPn"); number.Text = BussinessFacde.GetConfigXml("TodayPlan"); speed.Text = BussinessFacde.GetConfigXml("Speed"); } catch { //关闭窗口 this.Dispose(); this.Close(); } }
/// <summary> /// 显示设备状态信息 /// </summary> /// <param name="source"></param> /// <param name="e"></param> public void ShowBusinessProcess(object source, System.Timers.ElapsedEventArgs e) { OverrideTimer tt = (OverrideTimer)source; tt.Stop(); try { String pruductionType = tt.Type; String todayPlan = tt.Plan; String station = tt.Station; StationPenalControl spc = tt.Spc; TimeHelper myTime = tt.MYTIME; //显示工位 // BeginInvoke((MethodInvoker)delegate() { spc.LB_PanelStation.Text = "OP "+station; }); int eqstateControl = Convert.ToInt32(BussinessFacde.GetOpcConfigXml(station, "1", "1")); String eqstate = OPC.ReadItem(eqstateControl).ToString(); //获取PLC传过来的设备状态信息 if (eqstate == "1") //表示设备正常 { BeginInvoke((MethodInvoker) delegate() { spc.panel1.BackColor = System.Drawing.Color.Lime; }); if (spc.LB_ErrorTimes.Text != "") { BeginInvoke((MethodInvoker) delegate() { spc.LB_ErrorTimes.Text = ""; }); BeginInvoke((MethodInvoker) delegate() { spc.LB_ErrorNotice.Text = ""; }); myTime.Close(); } } else if (eqstate == "2") //设备故障 { BeginInvoke((MethodInvoker) delegate() { spc.panel1.BackColor = System.Drawing.Color.Red; }); BeginInvoke((MethodInvoker) delegate() { spc.LB_ErrorNotice.Text = "停机时间:"; }); //显示停机时间 //for (int i = 1; i <= 100; i++) //{ // if (i == 100) // { // stopSecondTimes++; // } // stopMinTimers = i; // BeginInvoke((MethodInvoker)delegate() { spc.LB_ErrorTimes.Text = stopSecondTimes + "'" + stopMinTimers+"''"; }); //} if (spc.LB_ErrorTimes.Text != "") { } else { myTime.Open(); } } else if (eqstate == "3") //设备缺料 { BeginInvoke((MethodInvoker) delegate() { spc.panel1.BackColor = System.Drawing.Color.Yellow; }); BeginInvoke((MethodInvoker) delegate() { spc.LB_ErrorNotice.Text = "等待时间:"; }); //显示等待时间 //for (int i = 1; i <= 100; i++) //{ // if (i == 100) // { // stopSecondTimes++; // } // stopMinTimers = i; // BeginInvoke((MethodInvoker)delegate() { spc.LB_ErrorTimes.Text = stopSecondTimes + "'" + stopMinTimers + "''"; }); //} if (spc.LB_ErrorTimes.Text != "") { } else { myTime.Open(); } } } catch { } finally { tt.Start(); } }
/// <summary> /// 开启业务处理的线程 /// </summary> public void StartBussinessThread() { //开启页面跳转线程 String speed = BussinessFacde.GetConfigXml("Speed"); //获取配置的页面跳转速度 if (!String.IsNullOrEmpty(speed) && Convert.ToInt32(speed) > 0) //配置的速度不为空 { OverrideTimer tt = new OverrideTimer(); //将用户配置的时间转换为毫秒 int speedControl = Convert.ToInt32(speed) * 1000; tt.Interval = speedControl; tt.Elapsed += new System.Timers.ElapsedEventHandler(ChangePageBusinessProcess); tt.Enabled = true; tt.AutoReset = false; } else //如果用户没有配置,则默认10秒切换页面 { OverrideTimer tt = new OverrideTimer(); //将用户配置的时间转换为毫秒 tt.Interval = 10000; tt.Elapsed += new System.Timers.ElapsedEventHandler(ChangePageBusinessProcess); tt.Enabled = true; tt.AutoReset = false; } //开启地址监听线程,实时刷新看板数据 String stationText = BussinessFacde.GetConfigXml("Station"); if (!String.IsNullOrEmpty(stationText)) { String[] stationArray = stationText.Split(','); for (int i = 0; i < stationArray.Length; i++) { if (i < 8) //一个页面放8个工位的图片 { if (i < 4) { StationPenalControl spc = new StationPenalControl(); panel1.Controls.Add(spc); spc.Location = new Point(28 + 200 * i, 139); spc.LB_PanelStation.Text = "OP" + stationArray[i]; TimeSpan time = TimeSpan.Parse("00:00:00"); TimeHelper myTime = new TimeHelper(time, spc.LB_ErrorTimes); OverrideTimer tt = new OverrideTimer(); tt.MYTIME = myTime; tt.Spc = spc; tt.Type = "1"; tt.Station = stationArray[i]; tt.Interval = 1000; tt.Elapsed += new System.Timers.ElapsedEventHandler(ShowBusinessProcess); tt.Enabled = true; tt.AutoReset = false; } else { StationPenalControl spc = new StationPenalControl(); spc.LB_PanelStation.Text = "OP" + stationArray[i]; panel1.Controls.Add(spc); spc.Location = new Point(28 + 200 * (i - 4), 139 * 2); TimeSpan time = TimeSpan.Parse("00:00:00"); TimeHelper myTime = new TimeHelper(time, spc.LB_ErrorTimes); OverrideTimer tt = new OverrideTimer(); tt.MYTIME = myTime; tt.Spc = spc; tt.Type = "1"; tt.Station = stationArray[i]; tt.Interval = 1000; tt.Elapsed += new System.Timers.ElapsedEventHandler(ShowBusinessProcess); tt.Enabled = true; tt.AutoReset = false; } } else if (i >= 8 && i < 16) { if (i < 12) { StationPenalControl spc = new StationPenalControl(); panel16.Controls.Add(spc); spc.Location = new Point(28 + 200 * (i - 8), 139); spc.LB_PanelStation.Text = "OP" + stationArray[i]; TimeSpan time = TimeSpan.Parse("00:00:00"); TimeHelper myTime = new TimeHelper(time, spc.LB_ErrorTimes); OverrideTimer tt = new OverrideTimer(); tt.MYTIME = myTime; tt.Spc = spc; tt.Type = "1"; tt.Station = stationArray[i]; tt.Interval = 1000; tt.Elapsed += new System.Timers.ElapsedEventHandler(ShowBusinessProcess); tt.Enabled = true; tt.AutoReset = false; } else { StationPenalControl spc = new StationPenalControl(); panel16.Controls.Add(spc); spc.Location = new Point(28 + 200 * (i - 12), 139 * 2); spc.LB_PanelStation.Text = "OP" + stationArray[i]; TimeSpan time = TimeSpan.Parse("00:00:00"); TimeHelper myTime = new TimeHelper(time, spc.LB_ErrorTimes); OverrideTimer tt = new OverrideTimer(); tt.MYTIME = myTime; tt.Spc = spc; tt.Type = "1"; tt.Station = stationArray[i]; tt.Interval = 1000; tt.Elapsed += new System.Timers.ElapsedEventHandler(ShowBusinessProcess); tt.Enabled = true; tt.AutoReset = false; } } // tt.Type = BussinessFacde.GetConfigXml("ProductionType"); // tt.Plan = BussinessFacde.GetConfigXml("TodayPlan"); } } //开启产品上产状态线程 OverrideTimer t1 = new OverrideTimer(); //将用户配置的时间转换为毫秒 t1.Interval = 2000; t1.Elapsed += new System.Timers.ElapsedEventHandler(showProductionState); t1.Enabled = true; t1.AutoReset = false; }