async void BigDataRun() { int _LampColor = LampColor; int count1 = 0; LampGreenSw.Start(); bool first = true; while (true) { await Task.Delay(1000);//每秒刷新 #region 报警 if (M300 != null && Fx5u_2.Connect) { for (int i = 0; i < AlarmList.Count; i++) { if (M300[i] != AlarmList[i].State && AlarmList[i].Content != "Null" && (LampGreenSw.Elapsed.TotalMinutes > 3 || first)) { first = false; LampGreenSw.Reset(); AlarmList[i].State = M300[i]; if (AlarmList[i].State) { CurrentAlarm = AlarmList[i].Content; AlarmList[i].Start = DateTime.Now; AlarmList[i].End = DateTime.Now; AddMessage(AlarmList[i].Code + AlarmList[i].Content + "发生"); AlarmAction(i);//等待报警结束 } } } } #endregion #region 灯号更新 switch (LampColor) { case 1: LampGreenElapse += 1; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampGreenElapse", LampGreenElapse.ToString()); break; case 2: LampGreenFlickerElapse += 1; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampGreenFlickerElapse", LampGreenFlickerElapse.ToString()); break; case 3: LampYellowElapse += 1; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampYellowElapse", LampYellowElapse.ToString()); break; case 4: LampYellowFlickerElapse += 1; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampYellowFlickerElapse", LampYellowFlickerElapse.ToString()); break; case 5: LampRedElapse += 1; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampRedElapse", LampRedElapse.ToString()); break; default: break; } count1++; if (_LampColor != LampColor || count1 > 60) { if (LampColor == 1 && _LampColor != LampColor) { LampGreenSw.Restart(); } _LampColor = LampColor; count1 = 0; string result = await Task <string> .Run(() => { try { int _result = -999; Mysql mysql = new Mysql(); if (mysql.Connect()) { string currentAlarm = LampColor == 4 ? CurrentAlarm : "NA"; string stm = string.Format("UPDATE HA_F4_LIGHT SET LIGHT = '{3}',SDATE = '{4}',STIME = '{5}',ALARM = '{6}',TIME_1 = '{8}',TIME_2 = '{9}',TIME_3 = '{10}',TIME_4 = '{11}',TIME_5 = '{12}' WHERE PM = '{0}' AND LIGHT_ID = '{1}' AND MACID = '{2}' AND CLASS = '{7}'" , _PM, _LIGHT_ID, _MACID, LampColor.ToString(), DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"), currentAlarm, GetBanci(), ((double)LampGreenElapse / 60).ToString("F2"), ((double)LampGreenFlickerElapse / 60).ToString("F2"), ((double)LampYellowElapse / 60).ToString("F2") , ((double)LampYellowFlickerElapse / 60).ToString("F2"), ((double)LampRedElapse / 60).ToString("F2")); _result = mysql.executeQuery(stm); } mysql.DisConnect(); return(_result.ToString()); } catch (Exception ex) { return(ex.Message); } }); //AddMessage("更新灯信号" + result); } if (LampColor != 1) { LampGreenSw.Reset(); } if (LampColor == 1 && LampGreenSw.Elapsed == TimeSpan.Zero) { LampGreenSw.Restart(); } #endregion #region 机台指标 #endregion GreenElapse.Text = LampGreenSw.Elapsed.TotalMinutes.ToString("F1") + " min"; } }
async void UpdateUI() { while (true) { await Task.Delay(200); #region 更新界面 if (Fx5u.Connect) { EllipsePLCState.Fill = Brushes.Green; } else { EllipsePLCState.Fill = Brushes.Red; } if (Fx5u_2.Connect) { EllipsePLCState2.Fill = Brushes.Green; } else { EllipsePLCState2.Fill = Brushes.Red; } CycleText.Text = SWms.ToString() + " ms"; #endregion #region 换班 if (LastBanci != GetBanci()) { LastBanci = GetBanci(); Inifile.INIWriteValue(iniParameterPath, "Summary", "LastBanci", LastBanci); LampGreenElapse = 0; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampGreenElapse", LampGreenElapse.ToString()); LampGreenFlickerElapse = 0; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampGreenFlickerElapse", LampGreenFlickerElapse.ToString()); LampYellowElapse = 0; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampYellowElapse", LampYellowElapse.ToString()); LampYellowFlickerElapse = 0; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampYellowFlickerElapse", LampYellowFlickerElapse.ToString()); LampRedElapse = 0; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampRedElapse", LampRedElapse.ToString()); await Task.Run(() => { Mysql mysql = new Mysql(); try { int _result = -999; if (mysql.Connect()) { string stm = string.Format("INSERT INTO HA_F4_LIGHT (PM,LIGHT_ID,MACID,CLASS,LIGHT,SDATE,STIME,ALARM,TIME_1,TIME_2,TIME_3,TIME_4,TIME_5,GROUP1,TRACK,WORKSTATION) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','0','0','0','0','0','{8}','{9}','{10}')" , _PM, _LIGHT_ID, _MACID, GetBanci(), LampColor.ToString(), DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"), "NA", _GROUP1, _TRACK, _WORKSTATION); _result = mysql.executeQuery(stm); } this.Dispatcher.Invoke(new Action(() => { AddMessage("插入数据库灯信号" + _result.ToString()); })); } catch (Exception ex) { this.Dispatcher.Invoke(new Action(() => { AddMessage(ex.Message); })); } finally { mysql.DisConnect(); } }); Fx5u_2.SetM("M2606", true); CardLockFlag = true; CardLockTime = DateTime.Now; AddMessage("机台锁定!"); AddMessage(LastBanci + " 换班数据清零"); } #endregion } }