private static void WarmTaskStart() { TaskStop = false; for (int i = 1; i < PLCconnect.WriteOutCold.TsakNumber + 1; i++) { try { WriteOutWarmTime(); GetWeight = false; WeightStatus = false; GetLocation = false; string Location = ""; string FillBottle = ""; string EmptyBottle = ""; string SlotID = ""; CheckOnSite = false; int WarmType = 0; DateTime dt = DateTime.Now; do { if (ATSData.AutomaticModeStatus == ATSData.AutomaticModeStatusType.Stop) { TaskStop = true; } if (ReadSystemStatus.TaskLocation[3] != "0") { Location = ReadSystemStatus.TaskLocation[3]; WarmType = ReadSystemStatus.WarmType[int.Parse(Location) - 1]; WriteOutWarmReplyLocation(Location); GetLocation = true; SlotID = ATS.Models.UserData.Instance.SelectSlotID(Location); } System.Threading.Thread.Sleep(100); if ((DateTime.Now - dt).TotalSeconds > 3000) { ATSData.AutomaticModeStatus = ATSData.AutomaticModeStatusType.Stop; PLCCommon.ShowErrorInformation("回溫庫位對未失敗,請確認是否有機故", "超時提醒"); TaskStop = true; WarmThread.Abort(); break; } }while (GetLocation == false && TaskStop == false); do { if (ReadSystemStatus.PlcStatus[6]) { if (SystemConfig.WeightCheck == "1") { if (Convert.ToInt32(ReadSystemStatus.BottleWeight) == 0) { continue; } else { FillBottle = ReadSystemStatus.BottleWeight; StartSendWeight(FillBottle); GetWeight = true; ATS.Models.UserData.Instance.OutWarmFillWeight(Location, FillBottle); if (WeightEvent != null) { WeightEvent(FillBottle); } } } else { FillBottle = "100"; StartSendWeight("100"); GetWeight = true; ATS.Models.UserData.Instance.OutWarmFillWeight(Location, FillBottle); if (WeightEvent != null) { WeightEvent(FillBottle); } } } if (ATSData.AutomaticModeStatus == ATSData.AutomaticModeStatusType.Stop) { TaskStop = true; } Thread.Sleep(100); if ((DateTime.Now - dt).TotalSeconds > 3000) { ATSData.AutomaticModeStatus = ATSData.AutomaticModeStatusType.Stop; PLCCommon.ShowErrorInformation("超過時間沒有讀取到磅秤重量,請確認是否有機故", "超時提醒"); TaskStop = true; WarmThread.Abort(); break; } }while (GetWeight == false && TaskStop == false); GetWeight = false; dt = DateTime.Now; WeightStatus = true; do { if (ReadSystemStatus.PlcStatus[7]) { if (SystemConfig.WeightCheck == "1") { Thread.Sleep(2000); if (Convert.ToInt32(ReadSystemStatus.BottleWeight) == 0) { continue; } else { EmptyBottle = ReadSystemStatus.BottleWeight; if (Convert.ToInt32(EmptyBottle) / 1000 > Convert.ToInt32(SystemConfig.WeightDownLimit)) { PLCCommon.PLC_WRITE("1840", "1", "1"); PLCCommon.PLC_WRITE("1840", "0", "1"); System.Windows.Forms.MessageBox.Show("倒料失敗,膠材剩餘量過多(剩餘量超過設定值)"); WiseTech.Log.Logger.SystemLog("倒料失敗,膠材剩餘量過多(剩餘量超過設定值)"); TaskStop = true; } else { StartSendWeight(EmptyBottle); GetWeight = true; ATS.Models.UserData.Instance.OutWarmEmptyWeight(Location, EmptyBottle, FillBottle); ATS.Models.UserData.Instance.CreatCSVFile(Convert.ToInt32(Location), WarmType); if (EmptyWeightEvent != null) { EmptyWeightEvent(EmptyBottle); } } } } else { EmptyBottle = "100"; StartSendWeight("100"); GetWeight = true; ATS.Models.UserData.Instance.OutWarmEmptyWeight(Location, EmptyBottle, FillBottle); ATS.Models.UserData.Instance.CreatCSVFile(Convert.ToInt32(Location), WarmType); if (EmptyWeightEvent != null) { EmptyWeightEvent("100"); } } } if (ATSData.AutomaticModeStatus == ATSData.AutomaticModeStatusType.Stop) { TaskStop = true; } System.Threading.Thread.Sleep(100); if ((DateTime.Now - dt).TotalSeconds > 3000) { ATSData.AutomaticModeStatus = ATSData.AutomaticModeStatusType.Pause; PLCCommon.ShowErrorInformation("超過時間沒有讀取到磅秤重量,請確認是否有機故", "超時提醒"); TaskStop = true; WarmThread.Abort(); break; } }while (GetWeight == false && TaskStop == false); do { if (PLCconnect.ReadSystemStatus.PlcStatus[1] && (!PLCconnect.ReadSystemStatus.PlcStatus[2])) { OutWarmSuccess = true; ATS.Models.UserData.Instance.OutWarmSuccess(Location); } System.Threading.Thread.Sleep(1000); if ((DateTime.Now - dt).TotalSeconds > 3000) { ATSData.AutomaticModeStatus = ATSData.AutomaticModeStatusType.Pause; PLCCommon.ShowErrorInformation("丟料失敗,請確認是否有機故", "超時提醒"); TaskStop = true; WarmThread.Abort(); break; } if (ATSData.AutomaticModeStatus == ATSData.AutomaticModeStatusType.Stop) { TaskStop = true; } }while (OutWarmSuccess == false && TaskStop == false); //ATS.Models.UserData.Instance.OutWarmSuccess(Location, FillBottle, EmptyBottle); if (OutWarmSuccess == true || PLCconnect.WriteOutCold.TsakNumber == i) { PLCconnect.ReadSystemStatus.RecycleBottleNum += i; sc.SaveRecycleBottle(ReadSystemStatus.RecycleBottleNum.ToString()); if (RecycleBottleChange != null) { RecycleBottleChange(PLCconnect.ReadSystemStatus.RecycleBottleNum); } if (UpdateEvent != null) { UpdateEvent("", ""); } WarmSuccess success = new WarmSuccess(); success.TitleChange("批號 : " + SlotID + "\r\n 倒料完成 \r\n 完成時間 : " + DateTime.Now.ToString()); success.ShowDialog(); WeightStatus = false; OutWarmSuccess = false; GetWeight = false; } } catch (Exception err) { ATS.LCSCommon.WriteAppErrorLog(err); } } }
private static void TaskStart() { TaskFail = false; TaskSuccess = false; GetBarcoImformation = false; string[] BarcoReaderList = BarcoReader.Split(';'); string Num = WiseTech.Log.Logger.TodayTaskNumber(BarcoReaderList[2]); WriteBarcoNo(BarcoReaderList[2] + "-" + Num); WriteInColdSaveTime(BarcoReaderList[4]); if (PLCconnect.ReadSystemStatus.PlcStatus[1]) { ATSData.AutomaticModeStatusType t = ATSData.AutomaticModeStatus; int bytes = 0; DateTime dt = DateTime.Now; do { if (ATSData.AutomaticModeStatus == ATSData.AutomaticModeStatusType.Stop) { TaskFail = true; } bytes = Sp.BytesToRead; if (bytes > 0) { } if (bytes > 30) { byte[] buffer = new byte[bytes]; Sp.Read(buffer, 0, bytes); data = Encoding.Default.GetString(buffer); GetBarcoImformation = true; //20190318 Add Invokesend(data); } Thread.Sleep(100); if ((DateTime.Now - dt).TotalSeconds > 30) { ATSData.AutomaticModeStatus = ATSData.AutomaticModeStatusType.Pause; PLCCommon.ShowErrorInformation("超過時間沒有讀取到BarcoReader資訊,請確認罐子是否擺放正確", "超時提醒"); WiseTech.Log.Logger.SystemLog("超過時間沒有讀取到BarcoReader資訊,設定時間為 30 秒"); CommonThread.Abort(); break; } }while (GetBarcoImformation == false && !TaskFail); //} } else { ATSData.AutomaticModeStatus = ATSData.AutomaticModeStatusType.Pause; MessageBox.Show("請先等待作業完成,或確認目前是否為連線狀態", "作業運行提示"); WiseTech.Log.Logger.SystemLog("請先等待作業完成,或確認目前是否為連線狀態"); } }