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 |  119 +++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 78 insertions(+), 41 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 427ab45..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"
@@ -8,7 +8,9 @@
 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;
@@ -51,29 +53,31 @@
 
         public Task Execute(IJobExecutionContext context)
         {
-            WriteDebug("澶у爢鍨涙満杩愯鏃ュ織", "寮�濮嬫椂闂�" + DateTime.Now);
-            WriteDebug("澶у爢鍨涙満杩愯鏃ュ織", $"澶у爢鍨涙満浠诲姟鎵ц涓�...");
-            //CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
-            CommonStackerCrane commonStackerCrane = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "SC01") as CommonStackerCrane;
+            
+             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("澶у爢鍨涙満杩愯鏃ュ織", $"澶у爢鍨涙満浠诲姟鍙穥task.TaskNum}");
+                                
+                                WriteDebug(nameof(CommonStackerCraneJob), $"澶у爢鍨涙満浠诲姟鍙穥task.TaskNum}");
                                 StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
                                 if (stackerCraneTaskCommand != null)
                                 {
@@ -95,8 +99,12 @@
                                         //绌鸿溅鍑哄簱鍛戒护鍙戦�佹垚鍔熷悗锛屽洖浼� 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
@@ -109,6 +117,10 @@
                         }
                     }
                 }
+                else
+                {
+                    WriteDebug(nameof(DoubleStackerCraneJob), "鏈煡璇㈠埌褰撳墠鍙互鎵ц涓婃枡浠诲姟鐨勫ぇ鍫嗗灈鏈猴紒");
+                }
             }
             catch (Exception ex)
             {
@@ -116,14 +128,56 @@
             }
 
 
-            //鏌ヨ鎻愬崌鏈�/缁勭珛鏈轰俊鍙�
-            //Task.Run(delegate
-            //{
+            
             try
             {
                 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)
+                    {
+                        if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5)
+                        {
+                            _taskService.StackCraneTaskCompleted(tasknum);
+                            Console.Out.WriteLine("TaskCompleted" + tasknum);
+                            bool issuccess = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
+                            if(issuccess)
+                            {
+                                WriteDebug(nameof(CommonStackerCraneJob), $"澶у爢鍨涙満SC01浠诲姟鍙峰爢鍨涙満浠诲姟鍙凤細{tasknum},鍥炲啓5鎴愬姛");
+                                //鏌ヨ褰撳墠浠诲姟鍙凤紝鏄笉鏄嚭搴擄紙姝e父搴撲綅-->鏆傚瓨浣嶏級
+                                Dt_Task tasktemp = _taskService.QueryStackerCraneTaskByRelotion(tasknum);
+                                if (tasktemp != null&&!string.IsNullOrEmpty(tasktemp.Remark.Trim()))
+                                {
+                                    //鏍规嵁浠诲姟鐩爣鍦板潃纭畾鍐欏叆PLC浣嶇疆 Depth
+                                    Dt_LocationInfo location = _locationInfoRepository.QueryFirst(x => x.LocationCode == tasktemp.TargetAddress);
+                                    if (commonStackerCrane != null && location != null)
+                                    {
+                                        bool issuccess2 = commonStackerCrane.Communicator.Write<short>("DB28." + location.Depth + ".0", 9);
+                                        if (issuccess2)
+                                        {
+                                            ServiceLogger.WriteDebug("TaskService", $"鍘熸枡鍑哄簱鍚庡啓鍏ユ爣璇嗘垚鍔燂紒");
+                                        }
+                                        else
+                                        {
+                                            ServiceLogger.WriteDebug("TaskService", $"鍘熸枡鍑哄簱鍚庡啓鍏ユ爣璇嗗け璐ワ紒");
+                                        }
+                                    }
+                                }
+                            }
+                            else
+                            {
+                                WriteDebug(nameof(CommonStackerCraneJob), $"澶у爢鍨涙満SC01浠诲姟鍙峰爢鍨涙満浠诲姟鍙凤細{tasknum},鍥炲啓5澶辫触");
+                            }
 
+                        }
+                    }
+
+
+
+                    //鎻愬崌鏈轰氦浜�
                     Dt_Task? task1001 = _taskService.QueryStackerCraneTaskByAGVRequest("SC01");
                     if (task1001 != null)
                     {
@@ -141,18 +195,6 @@
                         {
                             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), $"鍏佽AGV杩涘叆鎻愬崌鏈猴紝鍥炰紶WMS澶辫触锛佷换鍔″彿{task1001.TaskNum}");
-                            }
-                            else
-                            {
-                                WriteDebug(nameof(CommonStackerCraneJob), $"鍏佽AGV杩涘叆鎻愬崌鏈猴紝鍥炰紶WMS鎴愬姛锛佷换鍔″彿{task1001.TaskNum}");
-                            }
-                        }
-                        else
-                        {
-                            WriteDebug(nameof(CommonStackerCraneJob), $"鏈鍙栧埌鎻愬崌鏈哄厑璁¤繘鍏ヤ俊鍙凤紝鏆備笉鍏佽AGV杩涘叆鎻愬崌鏈猴紝浠诲姟鍙穥task1001.TaskNum}");
                         }
                     }
                     Dt_Task? task3001 = _taskService.QueryStackerCraneTaskByAGVPutFinish("SC01");
@@ -173,10 +215,7 @@
                             {
                                 commonStackerCrane.Communicator.Write<short>("DB1.0.0", 1);
                             }
-                            else
-                            {
-                                WriteDebug(nameof(CommonStackerCraneJob), $"鏈啓鍏ユ彁鍗囦俊鍙凤紝鍙兘鏄凡鍐欏叆鎴栬�呮彁鍗囨満鏈鐞嗗氨缁姸鎬�,浠诲姟鍙凤細{task3001.TaskNum}");
-                            }
+                          
                             //璇诲彇鎻愬崌鏈轰俊鍙凤紝纭畾鏄惁鎻愬崌瀹屾垚
 
                             IsFinish = commonStackerCrane.Communicator.Read<short>("DB2.2.0");
@@ -193,10 +232,7 @@
                             {
                                 commonStackerCrane.Communicator.Write<short>("DB1.6.0", 1);
                             }
-                            else
-                            {
-                                WriteDebug(nameof(CommonStackerCraneJob), $"鏈啓鍏ユ彁鍗囦俊鍙凤紝鍙兘鏄俊鍙峰凡鍐欏叆鎴栬�呮彁鍗囨満鏈鐞嗗氨缁姸鎬侊紝浠诲姟鍙凤細{task3001.TaskNum}");
-                            }
+                           
                             //璇诲彇鎻愬崌鏈轰俊鍙凤紝纭畾鏄惁鎻愬崌瀹屾垚
                             IsFinish = commonStackerCrane.Communicator.Read<short>("DB2.10.0");
                         }
@@ -212,10 +248,7 @@
                                 WriteDebug(nameof(CommonStackerCraneJob), $"鎻愬崌鏈烘彁鍗囧畬鎴愶紝鍥炰紶WMS澶辫触锛佷换鍔″彿{task3001.TaskNum}");
                             }
                         }
-                        else
-                        {
-                            WriteDebug(nameof(CommonStackerCraneJob), $"鎻愬崌鏈烘彁鍗囦腑...锛屼换鍔″彿锛歿task3001.TaskNum}");
-                        }
+                       
                     }
 
                     //灏忓爢鍨涙満鍑哄簱瀹屾垚浠诲姟
@@ -293,14 +326,14 @@
 
                     }
 
+
+
                 }
             }
             catch (Exception ex)
             {
-                WriteError(nameof(CommonStackerCraneJob), "鏌ヨ鎴栧啓鍏LC鐘舵�佸け璐ワ紒", ex);
+                WriteError(nameof(CommonStackerCraneJob), "鎵ц寮傚父锛�", ex);
             }
-            WriteDebug("澶у爢鍨涙満杩愯鏃ュ織", "缁撴潫鏃堕棿" + DateTime.Now);
-            //});
             return Task.CompletedTask;
         }
 
@@ -318,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