From 14aaca9a2e1da2849d602487a52094ee26bbe30a Mon Sep 17 00:00:00 2001 From: duyongjia <adu_555@163.com> Date: 星期二, 03 十二月 2024 13:40:41 +0800 Subject: [PATCH] 生产试运行稳定版本提交 --- 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs | 341 ++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 217 insertions(+), 124 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" index 3e63582..da7be29 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" @@ -1,14 +1,20 @@ 锘縰sing HslCommunication; using Microsoft.AspNetCore.Components.Routing; +using Newtonsoft.Json; using Quartz; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; +using System.Reflection.Metadata; using System.Text; +using System.Threading; using System.Threading.Tasks; +using WIDESEAWCS_Common.LocationEnum; +using WIDESEAWCS_Common.ServiceLog; using WIDESEAWCS_Common.TaskEnum; using WIDESEAWCS_Communicator; +using WIDESEAWCS_Core; using WIDESEAWCS_Core.Enums; using WIDESEAWCS_DTO.TaskInfo; using WIDESEAWCS_IBasicRepository; @@ -47,25 +53,31 @@ public Task Execute(IJobExecutionContext context) { - CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams"); + + WriteDebug("绾跨▼缁熻鏃ュ織", "绾跨▼鏁�" + ThreadPool.ThreadCount); + //CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams"); + CommonStackerCrane commonStackerCrane = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "SC01") as CommonStackerCrane; try { if (commonStackerCrane != null) { - if (!commonStackerCrane.IsEventSubscribed) - { - commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//璁㈤槄浠诲姟瀹屾垚浜嬩欢 - } + //WriteDebug("澶у爢鍨涙満杩愯鏃ュ織", $"澶у爢鍨涙満浠诲姟鎵ц涓�..."); + //if (!commonStackerCrane.IsEventSubscribed) + //{ + // commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//璁㈤槄浠诲姟瀹屾垚浜嬩欢 + //} if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal) { - commonStackerCrane.CheckStackerCraneTaskCompleted();//闃叉浠诲姟瀹屾垚浜嬩欢鐩戞祴瓒呮椂锛屽啀鎵嬪姩瑙﹀彂涓�娆� + // commonStackerCrane.CheckStackerCraneTaskCompleted();//闃叉浠诲姟瀹屾垚浜嬩欢鐩戞祴瓒呮椂锛屽啀鎵嬪姩瑙﹀彂涓�娆� if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby) { Dt_Task? task = GetTask(commonStackerCrane); if (task != null) { + + WriteDebug(nameof(CommonStackerCraneJob), $"澶у爢鍨涙満浠诲姟鍙穥task.TaskNum}"); StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task); if (stackerCraneTaskCommand != null) { @@ -83,6 +95,17 @@ _taskService.UpdateTaskStatus(task.TaskId, (int)TaskOutStatusEnum.SC_OutExecuting); _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"鍫嗗灈鏈哄嚭搴撴墽琛屼腑"); } + + //绌鸿溅鍑哄簱鍛戒护鍙戦�佹垚鍔熷悗锛屽洖浼� status=1锛� + if (task.TaskType == (int)TaskOutboundTypeEnum.OutPick) + { + Dt_LocationInfo srcLocation = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.SourceAddress); + srcLocation.LocationStatus = (int)LocationStatusEnum.Free; + _locationInfoRepository.UpdateData(srcLocation); + MESSendCMD sendcmd = new MESSendCMD { cmd = 201, task_id = task.TaskNum, status = 1 }; + MESResponse res = ApiInvoke.SendTaskCMD(sendcmd); + WriteDebug(nameof(CommonStackerCraneJob), $"鍫嗗灈鏈哄洖浼燬tatus:1,鐢ㄤ簬鐢熸垚鍑哄簱浠诲姟,浠诲姟鍙穥task.TaskNum}"); + } } else { @@ -94,6 +117,10 @@ } } } + else + { + WriteDebug(nameof(DoubleStackerCraneJob), "鏈煡璇㈠埌褰撳墠鍙互鎵ц涓婃枡浠诲姟鐨勫ぇ鍫嗗灈鏈猴紒"); + } } catch (Exception ex) { @@ -101,150 +128,212 @@ } - //鏌ヨ鎻愬崌鏈�/缁勭珛鏈轰俊鍙� - //Task.Run(delegate - //{ - try + + try + { + if (commonStackerCrane != null) { - - if (commonStackerCrane != null) + //璇诲彇澶у爢鍨涙満浠诲姟鍙峰拰浠诲姟瀹屾垚纭鐘舵�侊紙鍥犱负灏佽鐨勪簨浠剁粡甯镐笉瑙﹀彂锛屾墍浠ュ姞涓洿鎺ヨ鐨勯�昏緫锛屼互鍏嶅嚭鐜板爢鍨涙満涓�鐩存帴澶勪簬绛夊緟wcs纭锛� + byte IsOver = commonStackerCrane.Communicator.Read<byte>("DB106.22"); + int tasknum = commonStackerCrane.Communicator.Read<int>("DB106.18"); + WriteDebug(nameof(CommonStackerCraneJob), $"澶у爢鍨涙満SC01浠诲姟鍙峰爢鍨涙満浠诲姟鍙凤細{tasknum}鐘舵�侊細{IsOver}"); + if (IsOver == 6) { - Dt_Task? task1001 = _taskService.QueryStackerCraneTaskByAGVRequest("SC01"); - if (task1001 != null) + if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5) { - //璇诲彇鎻愬崌鏈轰俊鍙凤紝纭畾鏄惁鍙互杩涘叆 - int IsAllow = 0; - if (task1001.SourceAddress == "SC01-002-000-001")//WMS 1001绔欑偣 + _taskService.StackCraneTaskCompleted(tasknum); + Console.Out.WriteLine("TaskCompleted" + tasknum); + bool issuccess = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5); + if(issuccess) { - IsAllow = commonStackerCrane.Communicator.Read<short>("DB2.0.0"); - } - else if (task1001.SourceAddress == "SC01-002-000-002")//WMS 1002绔欑偣 - { - IsAllow = commonStackerCrane.Communicator.Read<short>("DB2.8.0"); - } - if (IsAllow == 1)//濡傛灉涓�1锛屽垯鍏佽AGV杩涘叆锛屽洖浼燱MS - { - MESSendCMD sendcmd = new MESSendCMD { cmd = 2001, task_id = task1001.TaskNum, status = 6 }; - MESResponse res = ApiInvoke.SendTaskCMD(sendcmd); - if (res != null && res.code != 0) + WriteDebug(nameof(CommonStackerCraneJob), $"澶у爢鍨涙満SC01浠诲姟鍙峰爢鍨涙満浠诲姟鍙凤細{tasknum},鍥炲啓5鎴愬姛"); + //鏌ヨ褰撳墠浠诲姟鍙凤紝鏄笉鏄嚭搴擄紙姝e父搴撲綅-->鏆傚瓨浣嶏級 + Dt_Task tasktemp = _taskService.QueryStackerCraneTaskByRelotion(tasknum); + if (tasktemp != null&&!string.IsNullOrEmpty(tasktemp.Remark.Trim())) { - WriteDebug(nameof(CommonStackerCraneJob), $"鎻愬崌鏈烘彁鍗囧畬鎴愶紝鍥炰紶WMS澶辫触锛佷换鍔″彿{task1001.TaskNum}"); - } - } - } - Dt_Task? task3001 = _taskService.QueryStackerCraneTaskByAGVPutFinish("SC01"); - if (task3001 != null) - { - int IsFinish = 0; - int IsWriteOne = 0; - int IsWriteTwo = 0; - if (task3001.SourceAddress == "SC01-002-000-001")//WMS 1001绔欑偣 - { - //鍐欏叆鎻愬崌淇℃伅 - IsWriteOne = commonStackerCrane.Communicator.Read<short>("DB1.0.0"); - if(IsWriteOne == 0) - { - - commonStackerCrane.Communicator.Write<short>("DB1.0.0", 1); - } - //璇诲彇鎻愬崌鏈轰俊鍙凤紝纭畾鏄惁鎻愬崌瀹屾垚 - - commonStackerCrane.Communicator.Read<short>("DB2.2.0"); - } - else if (task3001.SourceAddress == "SC01-002-000-002")//WMS 1002绔欑偣 - { - //鍐欏叆鎻愬崌淇℃伅 - IsWriteTwo = commonStackerCrane.Communicator.Read<short>("DB1.6.0"); - if (IsWriteTwo == 0) - { - commonStackerCrane.Communicator.Write<short>("DB1.6.0", 1); - } - //璇诲彇鎻愬崌鏈轰俊鍙凤紝纭畾鏄惁鎻愬崌瀹屾垚 - IsFinish = commonStackerCrane.Communicator.Read<short>("DB2.10.0"); - } - if (IsFinish == 1)//濡傛灉涓�1锛屽垯琛ㄧず鎻愬崌瀹屾垚锛屽洖浼燱MS - { - MESSendCMD sendcmd = new MESSendCMD { cmd = 2002, task_id = task3001.TaskNum, status = 6 }; - MESResponse res = ApiInvoke.SendTaskCMD(sendcmd); - if (res != null && res.code != 0) - { - WriteDebug(nameof(CommonStackerCraneJob), $"鎻愬崌鏈烘彁鍗囧畬鎴愶紝鍥炰紶WMS澶辫触锛佷换鍔″彿{task3001.TaskNum}"); - } - - } - } - - //灏忓爢鍨涙満鍑哄簱瀹屾垚浠诲姟 - Dt_Task? taskSmall = _taskService.QueryStackerCraneFinishTask(); - if(taskSmall != null) - { - //鏍规嵁浠诲姟婧愬湴鍧�纭畾鍐欏叆PLC浣嶇疆 Depth - Dt_LocationInfo location = _locationInfoRepository.QueryFirst(x=>x.LocationCode==taskSmall.SourceAddress); - if(location != null) - { - string[] Levels = taskSmall.Remark.Split("-"); - if (Levels.Length == 2) - { - if (!string.IsNullOrEmpty(Levels[0]) && !string.IsNullOrEmpty(Levels[1])) + //鏍规嵁浠诲姟鐩爣鍦板潃纭畾鍐欏叆PLC浣嶇疆 Depth + Dt_LocationInfo location = _locationInfoRepository.QueryFirst(x => x.LocationCode == tasktemp.TargetAddress); + if (commonStackerCrane != null && location != null) { - int level = Convert.ToInt16(Levels[0]) - Convert.ToInt16(Levels[1]); - //鍓╀綑灞傛暟鍐欏叆 - bool issuccess = commonStackerCrane.Communicator.Write<short>("DB28." + location.Depth + ".0", Convert.ToInt16(level)); - //濡傛灉褰撳墠鎻愬彇灞傛暟绛変簬鎬诲眰鏁帮紝鍒欒〃绀烘枡杞︽墍鏈夌殑灞傛暟鍙栧畬 - if (level == 0) + bool issuccess2 = commonStackerCrane.Communicator.Write<short>("DB28." + location.Depth + ".0", 9); + if (issuccess2) { - //婧愬湴鍧�锛堟殏瀛樹綅锛夊搴旂殑鐩爣鍦板潃锛堢粍绔嬫満锛塴ocation.Remark - if (!string.IsNullOrEmpty(location.Remark)) - { - //鏍规嵁鐩爣鍦板潃鏌ヨ缁勭珛鏈虹珯鐐逛俊鎭紝鑾峰彇鍐欏叆鏁磋溅瀹屾垚鐨凞B鍧� Depth - Dt_LocationInfo location2 = _locationInfoRepository.QueryFirst(x => x.LocationCode == location.Remark); - //鏁磋溅瀹屾垚鍐欏叆 - bool issuccess2 = commonStackerCrane.Communicator.Write<short>("DB28." + location.Depth+".0", 1); - if (issuccess2&&issuccess) - { - _taskService.UpdateTaskStatus(taskSmall.TaskId, (int)TaskOutStatusEnum.OutFinish); - _taskExecuteDetailService.AddTaskExecuteDetail(taskSmall.TaskId, $"鍑哄簱浠诲姟瀹屾垚"); - } - else - { - WriteDebug(nameof(CommonStackerCraneJob), $"鏁磋溅瀹屾垚淇″彿鍐欏叆澶辫触锛佷换鍔″彿{taskSmall.TaskNum}"); - } - } - + ServiceLogger.WriteDebug("TaskService", $"鍘熸枡鍑哄簱鍚庡啓鍏ユ爣璇嗘垚鍔燂紒"); } else { + ServiceLogger.WriteDebug("TaskService", $"鍘熸枡鍑哄簱鍚庡啓鍏ユ爣璇嗗け璐ワ紒"); + } + } + } + } + else + { + WriteDebug(nameof(CommonStackerCraneJob), $"澶у爢鍨涙満SC01浠诲姟鍙峰爢鍨涙満浠诲姟鍙凤細{tasknum},鍥炲啓5澶辫触"); + } - if (issuccess) + } + } + + + + //鎻愬崌鏈轰氦浜� + Dt_Task? task1001 = _taskService.QueryStackerCraneTaskByAGVRequest("SC01"); + if (task1001 != null) + { + //璇诲彇鎻愬崌鏈轰俊鍙凤紝纭畾鏄惁鍙互杩涘叆 + int IsAllow = 0; + if (task1001.SourceAddress == "SC01-002-000-001")//WMS 1001绔欑偣 + { + IsAllow = commonStackerCrane.Communicator.Read<short>("DB2.0.0"); + } + else if (task1001.SourceAddress == "SC01-002-000-002")//WMS 1002绔欑偣 + { + IsAllow = commonStackerCrane.Communicator.Read<short>("DB2.8.0"); + } + if (IsAllow == 1)//濡傛灉涓�1锛屽垯鍏佽AGV杩涘叆锛屽洖浼燱MS + { + MESSendCMD sendcmd = new MESSendCMD { cmd = 2001, task_id = task1001.TaskNum, status = 6 }; + MESResponse res = ApiInvoke.SendTaskCMD(sendcmd); + } + } + Dt_Task? task3001 = _taskService.QueryStackerCraneTaskByAGVPutFinish("SC01"); + if (task3001 != null) + { + int IsFinish = 0; + int IsWriteOne = 0; + int IsWriteTwo = 0; + if (task3001.SourceAddress == "SC01-002-000-001")//WMS 1001绔欑偣 + { + //鎻愬崌鏈烘槸鍚﹀浜庡氨缁姸鎬� + + int IsReady = commonStackerCrane.Communicator.Read<short>("DB2.0.0"); + WriteDebug(nameof(CommonStackerCraneJob), $"鎻愬崌鏈虹姸鎬侊細{IsReady}浠诲姟鍙凤細{task3001.TaskNum}"); + //鍐欏叆鎻愬崌淇℃伅 + IsWriteOne = commonStackerCrane.Communicator.Read<short>("DB1.0.0"); + if (IsWriteOne == 0 && IsReady == 1) + { + commonStackerCrane.Communicator.Write<short>("DB1.0.0", 1); + } + + //璇诲彇鎻愬崌鏈轰俊鍙凤紝纭畾鏄惁鎻愬崌瀹屾垚 + + IsFinish = commonStackerCrane.Communicator.Read<short>("DB2.2.0"); + } + else if (task3001.SourceAddress == "SC01-002-000-002")//WMS 1002绔欑偣 + { + //鎻愬崌鏈烘槸鍚﹀浜庡氨缁姸鎬� + + int IsReady = commonStackerCrane.Communicator.Read<short>("DB2.0.0"); + WriteDebug(nameof(CommonStackerCraneJob), $"鎻愬崌鏈虹姸鎬侊細{IsReady}浠诲姟鍙凤細{task3001.TaskNum}"); + //鍐欏叆鎻愬崌淇℃伅 + IsWriteTwo = commonStackerCrane.Communicator.Read<short>("DB1.6.0"); + if (IsWriteTwo == 0 && IsReady == 1) + { + commonStackerCrane.Communicator.Write<short>("DB1.6.0", 1); + } + + //璇诲彇鎻愬崌鏈轰俊鍙凤紝纭畾鏄惁鎻愬崌瀹屾垚 + IsFinish = commonStackerCrane.Communicator.Read<short>("DB2.10.0"); + } + if (IsFinish == 1)//濡傛灉涓�1锛屽垯琛ㄧず鎻愬崌瀹屾垚锛屽洖浼燱MS + { + MESSendCMD sendcmd = new MESSendCMD { cmd = 2002, task_id = task3001.TaskNum, status = 6 }; + MESResponse res = ApiInvoke.SendTaskCMD(sendcmd); + string inparam = JsonConvert.SerializeObject(sendcmd); + WriteDebug(nameof(CommonStackerCraneJob), $"鎻愬崌鏈烘彁鍗囧畬鎴愶紝鍥炰紶WMS,鍏ュ弬锛歿inparam}"); + + if (res != null && res.code != 0) + { + WriteDebug(nameof(CommonStackerCraneJob), $"鎻愬崌鏈烘彁鍗囧畬鎴愶紝鍥炰紶WMS澶辫触锛佷换鍔″彿{task3001.TaskNum}"); + } + } + + } + + //灏忓爢鍨涙満鍑哄簱瀹屾垚浠诲姟 + Dt_Task? taskSmall = _taskService.QueryStackerCraneFinishTask(); + if (taskSmall != null) + { + //鏍规嵁浠诲姟婧愬湴鍧�纭畾鍐欏叆PLC浣嶇疆 Depth + Dt_LocationInfo location = _locationInfoRepository.QueryFirst(x => x.LocationCode == taskSmall.SourceAddress); + if (location != null) + { + string[] Levels = taskSmall.Remark.Split("-"); + if (Levels.Length == 2) + { + if (!string.IsNullOrEmpty(Levels[0]) && !string.IsNullOrEmpty(Levels[1])) + { + int level = Convert.ToInt16(Levels[0]) - Convert.ToInt16(Levels[1]); + + //鍓╀綑灞傛暟鍐欏叆 + bool issuccess = commonStackerCrane.Communicator.Write<short>("DB28." + location.Depth + ".0", Convert.ToInt16(level)); + WriteDebug(nameof(CommonStackerCraneJob), $"鍓╀綑灞傛暟淇″彿鍐欏叆{level}-浠诲姟鍙穥taskSmall.TaskNum}"); + + + //濡傛灉褰撳墠鎻愬彇灞傛暟绛変簬鎬诲眰鏁帮紝鍒欒〃绀烘枡杞︽墍鏈夌殑灞傛暟鍙栧畬 + if (level == 0) + { + //婧愬湴鍧�锛堟殏瀛樹綅锛夊搴旂殑鐩爣鍦板潃锛堢粍绔嬫満锛塴ocation.Remark + if (!string.IsNullOrEmpty(location.Remark)) + { + //鏍规嵁鐩爣鍦板潃鏌ヨ缁勭珛鏈虹珯鐐逛俊鎭紝鑾峰彇鍐欏叆鏁磋溅瀹屾垚鐨凞B鍧� Depth + Dt_LocationInfo location2 = _locationInfoRepository.QueryFirst(x => x.LocationCode == location.Remark); + //鏁磋溅瀹屾垚鍐欏叆灞傛暟 + int sn = 0; + if (taskSmall.SourceAddress == "SC01-001-006-001" || taskSmall.SourceAddress == "SC01-001-012-001" || taskSmall.SourceAddress == "SC01-001-018-001" || taskSmall.SourceAddress == "SC01-001-022-001" || taskSmall.SourceAddress == "SC01-001-026-001") + { + sn = 1; + } + else if (taskSmall.SourceAddress == "SC01-001-007-001" || taskSmall.SourceAddress == "SC01-001-013-001" || taskSmall.SourceAddress == "SC01-001-019-001" || taskSmall.SourceAddress == "SC01-001-023-001" || taskSmall.SourceAddress == "SC01-001-027-001") + { + sn = 2; + } + else + { + sn = 3; + } + bool issuccess2 = commonStackerCrane.Communicator.Write<short>("DB28." + location2.Depth + ".0", Convert.ToInt16(sn)); + if (issuccess2 && issuccess) { _taskService.UpdateTaskStatus(taskSmall.TaskId, (int)TaskOutStatusEnum.OutFinish); _taskExecuteDetailService.AddTaskExecuteDetail(taskSmall.TaskId, $"鍑哄簱浠诲姟瀹屾垚"); } else { - WriteDebug(nameof(CommonStackerCraneJob), $"鍓╀綑灞傛暟淇″彿鍐欏叆澶辫触锛佷换鍔″彿{taskSmall.TaskNum}"); + WriteDebug(nameof(CommonStackerCraneJob), $"鏁磋溅瀹屾垚淇″彿鍐欏叆澶辫触锛佷换鍔″彿{taskSmall.TaskNum}"); } } } + else + { + + if (issuccess) + { + _taskService.UpdateTaskStatus(taskSmall.TaskId, (int)TaskOutStatusEnum.OutFinish); + _taskExecuteDetailService.AddTaskExecuteDetail(taskSmall.TaskId, $"鍑哄簱浠诲姟瀹屾垚"); + } + else + { + WriteDebug(nameof(CommonStackerCraneJob), $"鍓╀綑灞傛暟淇″彿鍐欏叆澶辫触锛佷换鍔″彿{taskSmall.TaskNum}"); + } + } + } } - } - } + + + } - catch (Exception ex) - { - WriteError(nameof(CommonStackerCraneJob), "鏌ヨ鎴栧啓鍏LC鐘舵�佸け璐ワ紒", ex); - } - - - //}); - - - + } + catch (Exception ex) + { + WriteError(nameof(CommonStackerCraneJob), "鎵ц寮傚父锛�", ex); + } return Task.CompletedTask; } @@ -262,7 +351,11 @@ { Console.Out.WriteLine("TaskCompleted" + e.TaskNum); _taskService.StackCraneTaskCompleted(e.TaskNum); - commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5); + bool issuccess=commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5); + if (issuccess) + { + WriteDebug(nameof(CommonStackerCraneJob), $"浠诲姟鍙峰啓鍏ヤ换鍔″畬鎴愮‘璁ゅ��5鎴愬姛{e.TaskNum}"); + } } } } -- Gitblit v1.9.3