From de7dbe7cf85aa01abb64040aae1c04dfba74c135 Mon Sep 17 00:00:00 2001 From: schangxiang@126.com <schangxiang@126.com> Date: 周二, 01 4月 2025 10:48:50 +0800 Subject: [PATCH] 优化 和plc交互问题 --- CC/iWareCC_ASRS/ThreadService/02_BZ39工位(补板后工位)/Outbound/2、DataProcess_RobotBuffer_IssueOutboundTask.cs | 144 ++++++++++++++++++++++++++++++++++------------- 1 files changed, 104 insertions(+), 40 deletions(-) diff --git "a/CC/iWareCC_ASRS/ThreadService/02_BZ39\345\267\245\344\275\215\357\274\210\350\241\245\346\235\277\345\220\216\345\267\245\344\275\215\357\274\211/Outbound/2\343\200\201DataProcess_RobotBuffer_IssueOutboundTask.cs" "b/CC/iWareCC_ASRS/ThreadService/02_BZ39\345\267\245\344\275\215\357\274\210\350\241\245\346\235\277\345\220\216\345\267\245\344\275\215\357\274\211/Outbound/2\343\200\201DataProcess_RobotBuffer_IssueOutboundTask.cs" index 6411f28..fef2874 100644 --- "a/CC/iWareCC_ASRS/ThreadService/02_BZ39\345\267\245\344\275\215\357\274\210\350\241\245\346\235\277\345\220\216\345\267\245\344\275\215\357\274\211/Outbound/2\343\200\201DataProcess_RobotBuffer_IssueOutboundTask.cs" +++ "b/CC/iWareCC_ASRS/ThreadService/02_BZ39\345\267\245\344\275\215\357\274\210\350\241\245\346\235\277\345\220\216\345\267\245\344\275\215\357\274\211/Outbound/2\343\200\201DataProcess_RobotBuffer_IssueOutboundTask.cs" @@ -24,17 +24,18 @@ /// </summary> public static class DataProcess_RobotBuffer_IssueOutboundTask { + public static async void Handler() { var alertMsg = ""; LogType logType = LogType.DataProcess_RobotBuffer_IssueOutboundTask; while (true) { - Thread.Sleep(2000);//浼戠湢2绉掞紝灏嗕紤鐪犲啓鍒板墠闈紝鏄负浜嗕笅闈㈢殑continue鏂规硶鎵ц鍚庝笉鏄剧ず閿欒淇℃伅鐨勬彁绀猴紒锛侊紒銆怑ditBy shaocx,2022-05-24銆� + Thread.Sleep(1000);//浼戠湢2绉掞紝灏嗕紤鐪犲啓鍒板墠闈紝鏄负浜嗕笅闈㈢殑continue鏂规硶鎵ц鍚庝笉鏄剧ず閿欒淇℃伅鐨勬彁绀猴紒锛侊紒銆怑ditBy shaocx,2022-05-24銆� SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = string.Empty; try - { - if (SystemValue.isAllowRuning_DataProcess_RobotBuffer_IssueOutboundTask && SystemValue.isStartedModel) + {//SystemValue.isAllowRuning_DataProcess_RobotBuffer_IssueOutboundTask && + if (SystemValue.isStartedModel) { var rgvLocation = StationLocationEnum.BZ39.ToString(); /* @@ -44,27 +45,64 @@ using (WmsDBModel wmsDB = new WmsDBModel()) { + var noFinishOutTask = TaskHandler.ValidateIssueTaskForNoFinishTaskByOutStore(wmsDB); + if (noFinishOutTask == true) + {//琛ㄧず娌℃湁鏈粨鏉熺殑鍑哄簱浠诲姟锛岄偅涔堝氨 鍒濆鍖栬姹傚嚭搴撴寚浠� + using (StationServiceClient client = new StationServiceClient()) + { + var res = await client.WriteOutStoreTaskInfoAsync(true, (int)EDevice.Station, rgvLocation, "", 0); + if (!res.result) + { + SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = $"{rgvLocation.ToString()}-鍒濆鍖栬姹傚嚭搴撴寚浠� 澶辫触,WriteOutStoreTaskInfoAsync 杩斿洖:{res.resMsg}"; + continue; + } + else + { + //Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-鍒濆鍖栬姹傚嚭搴撴寚浠� 鎴愬姛,WriteOutStoreTaskInfoAsync锛屽弬鏁�: 绔欑偣{rgvLocation}"); + } + } + } + //瑕佹槸鏈夊凡涓嬪彂鐨勪换鍔★紝灏变笉瑕佹墽琛� - var isValidate = TaskHandler.ValidateIssueTaskForRobotBuffer(wmsDB); + var isValidate = TaskHandler.ValidateIssueOutTaskForRobotBuffer(wmsDB); if (!isValidate) { - SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = $"{rgvLocation.ToString()}-鏈夆�樺凡涓嬪彂鈥欑殑浠诲姟锛屼笉鑳藉鐞�,姝ゆ寰幆缁撴潫"; + SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = $" 褰撳墠鏈夆�樺凡涓嬪彂鈥欑殑鍑哄簱浠诲姟锛屼笉鑳藉啀娆″鐞嗕笅鍙戜换鍔�,姝ゆ寰幆缁撴潫"; continue; } //鍙栧垱寤烘椂闂存渶鏃╃殑閭d釜瑕佸嚭搴撶殑鍖� - var firstTask = wmsDB.wms_rbline_task.Where(x => - x.RbTaskType == (int)RbTaskTypeEnum.鍑哄簱浠诲姟 - && x.TaskStatus == (int)TaskStatusEnum.鏂板缓).OrderBy(x => x.CreateTime).FirstOrDefault(); - if (firstTask == null) + if (string.IsNullOrEmpty(FormCC.currHandlerPackageCodeForIssueOutboundTask)) { - SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = $"{rgvLocation.ToString()},鏍规嵁 娌℃湁鎵惧埌 鏂板缓 鐨勪换鍔� "; - continue; + var firstTask = wmsDB.wms_rbline_task.Where(x => + (x.RbTaskType == (int)RbTaskTypeEnum.榻愬寘鍑哄簱浠诲姟 || x.RbTaskType == (int)RbTaskTypeEnum.寮哄埗鍑哄簱浠诲姟) + && x.TaskStatus == (int)TaskStatusEnum.鏂板缓).OrderBy(x => x.CreateTime).FirstOrDefault(); + if (firstTask == null) + { + SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = $"{rgvLocation.ToString()},鏍规嵁 娌℃湁鎵惧埌 鏂板缓 鐨勪换鍔� "; + FormCC.currHandlerPackageCodeForIssueOutboundTask = ""; + continue; + } + FormCC.currHandlerPackageCodeForIssueOutboundTask = firstTask.PackageCode; + } + else + { + var firstTask = wmsDB.wms_rbline_task.Where(x => + (x.RbTaskType == (int)RbTaskTypeEnum.榻愬寘鍑哄簱浠诲姟 || x.RbTaskType == (int)RbTaskTypeEnum.寮哄埗鍑哄簱浠诲姟) + && x.TaskStatus == (int)TaskStatusEnum.鏂板缓 + && x.PackageCode == FormCC.currHandlerPackageCodeForIssueOutboundTask + ).OrderBy(x => x.CreateTime).FirstOrDefault(); + if (firstTask == null) + { + SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = $"{rgvLocation.ToString()},鏍规嵁 娌℃湁鎵惧埌 鏂板缓 鐨勪换鍔� "; + FormCC.currHandlerPackageCodeForIssueOutboundTask = ""; + continue; + } } var taskList = wmsDB.wms_rbline_task.Where(x => - x.RbTaskType == (int)RbTaskTypeEnum.鍑哄簱浠诲姟 - && x.TaskStatus == (int)TaskStatusEnum.鏂板缓).Where(x => x.PackageCode == firstTask.PackageCode).OrderBy(x => x.CreateTime).ToList(); + (x.RbTaskType == (int)RbTaskTypeEnum.榻愬寘鍑哄簱浠诲姟 || x.RbTaskType == (int)RbTaskTypeEnum.寮哄埗鍑哄簱浠诲姟) + && x.TaskStatus == (int)TaskStatusEnum.鏂板缓).Where(x => x.PackageCode == FormCC.currHandlerPackageCodeForIssueOutboundTask).OrderBy(x => x.CreateTime).ToList(); if (taskList == null) { SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = $"{rgvLocation.ToString()},鏍规嵁 娌℃湁鎵惧埌 鏂板缓 鐨勪换鍔� "; @@ -74,37 +112,63 @@ var doTask = taskList.FirstOrDefault(); - //杩欓噷涓嬪彂 鍑哄簱浠诲姟 - using (StationServiceClient client = new StationServiceClient()) - { - //棣栧厛瑕佹竻鐞� - var res = await client.OutboundFinishConfirmAsync((int)EDevice.Station, false, rgvLocation); - if (!res.result) - { - SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()}-涓嬪彂鍑哄簱浠诲姟 澶辫触,OutboundFinishConfirmAsync 杩斿洖:{res.resMsg}"; - continue; - } - else - { - Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-涓嬪彂鍑哄簱浠诲姟 鎴愬姛,OutboundFinishConfirmAsync锛屽弬鏁�: 绔欑偣{rgvLocation}"); - } + ////杩欓噷涓嬪彂 鍑哄簱浠诲姟 + //using (StationServiceClient client = new StationServiceClient()) + //{ + // //棣栧厛瑕佹竻鐞� + // //var res = await client.OutboundFinishConfirmAsync((int)EDevice.Station, false, rgvLocation); + // //if (!res.result) + // //{ + // // SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()}-涓嬪彂鍑哄簱浠诲姟 澶辫触,OutboundFinishConfirmAsync 杩斿洖:{res.resMsg}"; + // // continue; + // //} + // //else + // //{ + // // Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-涓嬪彂鍑哄簱浠诲姟 鎴愬姛,OutboundFinishConfirmAsync锛屽弬鏁�: 绔欑偣{rgvLocation}"); + // //} - res = await client.WriteOutStoreTaskInfoAsync((int)EDevice.Station, rgvLocation, doTask.PlaceCode, Convert.ToInt32(doTask.TaskNo)); - if (!res.result) - { - SystemWarningMsg._lbl_alert_DataProcess_BZ39 = $"{rgvLocation.ToString()}-涓嬪彂鍑哄簱浠诲姟 澶辫触,WriteOutStoreTaskInfoAsync 杩斿洖:{res.resMsg}"; - continue; - } - else - { - Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-涓嬪彂鍑哄簱浠诲姟 鎴愬姛,WriteOutStoreTaskInfoAsync锛屽弬鏁�: 绔欑偣{rgvLocation}"); - } - } + // var res = await client.WriteOutStoreTaskInfoAsync(false, (int)EDevice.Station, rgvLocation, doTask.PlaceCode, Convert.ToInt32(doTask.TaskNo)); + // if (!res.result) + // { + // SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = $"{rgvLocation.ToString()}-涓嬪彂鍑哄簱浠诲姟 澶辫触,WriteOutStoreTaskInfoAsync 杩斿洖:{res.resMsg}"; + // continue; + // } + // else + // { + // Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-涓嬪彂鍑哄簱浠诲姟 鎴愬姛,WriteOutStoreTaskInfoAsync锛屽弬鏁�: 绔欑偣{rgvLocation}"); + // } + //} doTask.TaskStatus = (int)TaskStatusEnum.宸蹭笅鍙�; - doTask.TaskStatusName = TaskStatusEnum.宸蹭笅鍙�.ToString(); + doTask.IssueTime = DateTime.Now; - wmsDB.SaveChanges(); + int changeNum = wmsDB.SaveChanges(); + if (changeNum > 0) + { + //蹇呴』瑕佺粰PLC涓嬪彂鎴愬姛,瑙e喅鍙兘浼氱粰PLC閲嶅涓嬪彂浠诲姟鐨勬儏鍐� + var isRight = true; + while (isRight) + { + //杩欓噷涓嬪彂 鍑哄簱浠诲姟 + using (StationServiceClient client = new StationServiceClient()) + { + + var res = await client.WriteOutStoreTaskInfoAsync(false, (int)EDevice.Station, rgvLocation, doTask.PlaceCode, Convert.ToInt32(doTask.TaskNo)); + if (!res.result) + { + SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = $"{rgvLocation.ToString()}-涓嬪彂鍑哄簱浠诲姟 澶辫触,WriteOutStoreTaskInfoAsync 杩斿洖:{res.resMsg}鍙傛暟: PlaceCode:{doTask.PlaceCode},TaskNo:{doTask.TaskNo}"; + Log4NetHelper.WriteErrorLog(logType, $"{rgvLocation.ToString()}-涓嬪彂鍑哄簱浠诲姟 澶辫触,WriteOutStoreTaskInfoAsync锛屽弬鏁�: PlaceCode:{doTask.PlaceCode},TaskNo:{doTask.TaskNo},鏉$爜:{doTask.Upi}"); + continue; + } + else + { + Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-涓嬪彂鍑哄簱浠诲姟 鎴愬姛,WriteOutStoreTaskInfoAsync锛屽弬鏁�: PlaceCode:{doTask.PlaceCode},TaskNo:{doTask.TaskNo},鏉$爜:{doTask.Upi}"); + isRight = false; + } + } + Thread.Sleep(1000); + } + } } } -- Gitblit v1.9.3