From 9ce6687843bd5079b7a87925df0bc7e3ddf2d36a Mon Sep 17 00:00:00 2001
From: Admin <Admin@ADMIN>
Date: 星期三, 01 四月 2026 11:53:38 +0800
Subject: [PATCH] 最新

---
 项目代码/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs |  105 +++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 79 insertions(+), 26 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
index 0b268cf..6e37d2e 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
@@ -1,4 +1,5 @@
 锘縰sing Autofac.Core;
+using HslCommunication;
 using Microsoft.AspNetCore.Components.Routing;
 using Microsoft.AspNetCore.Hosting;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
@@ -57,15 +58,8 @@
                 CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
                 if (commonStackerCrane != null)
                 {
-                    //if (!commonStackerCrane.IsEventSubscribed)
-                    //{
-                    //    commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//璁㈤槄浠诲姟瀹屾垚浜嬩欢
-                    //}
-
-                    
-
-
-                    if ((int)commonStackerCrane.StackerCraneWorkStatusValue == 6)
+                    //浠诲姟瀹屾垚StackerCraneWorkStatus
+                    if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.WorkCompleted)
                     {
                         //鍒ゆ柇褰撳墠浠诲姟鏄惁鏄洏鐐�
                         Dt_Task? currtask = _taskService.CurrtaskInfo(commonStackerCrane.CurrentTaskNum);
@@ -86,11 +80,10 @@
                             }
 
                             WebResponseContent webResponse = _taskService.StackCraneTaskCompleted(commonStackerCrane.CurrentTaskNum);
-                            if (webResponse.Status)
-                            {
+                            Console.WriteLine(webResponse.ToJsonString());
 
-                                bool ddjfk = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
-                            }
+
+                            bool ddjfk = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                         }
                     }
 
@@ -99,6 +92,7 @@
                     {
                         if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)
                         {
+
                             Dt_Task? task = GetTask(commonStackerCrane);
                             if (task != null)
                             {
@@ -108,6 +102,8 @@
                                     bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
                                     if (sendFlag)
                                     {
+                                        commonStackerCrane.Communicator.Write("DB105.52", 1);
+
                                         WebResponseContent webResponseContent=_taskService.UpdateTaskStatusToNext(task.TaskNum);
                                     }
                                 }
@@ -162,7 +158,7 @@
                     {
                         if (taskItem.TaskType == (int)TaskTypeEnum.Outbound)
                         {
-                            if (OutTaskStationIsOccupied(taskItem.NextAddress))
+                            if (OutTaskStationIsOccupied(taskItem.NextAddress,taskItem.Roadway))
                             {
                                 return taskItem;
                             }
@@ -188,14 +184,49 @@
         /// </summary>
         /// <param name="task">浠诲姟瀹炰綋</param>
         /// <returns>濡傛灉鏈鍗犵敤锛岃繑鍥炰紶鍏ョ殑浠诲姟淇℃伅锛屽惁鍒欙紝杩斿洖null</returns>
-        private bool OutTaskStationIsOccupied(string NextAddress)
+        private bool OutTaskStationIsOccupied(string NextAddress,string Roadway)
         {
-            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1003");
-            if (device == null) return false;
-            CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
-            DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == NextAddress && x.DeviceProParamName == "StationFree");
-            if (deviceProDTO == null) return false;
-            return conveyorLine.Communicator.Read<bool>(deviceProDTO.DeviceProAddress);
+            try
+            {
+                if (Roadway == "C")
+                {
+                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1004");
+                    if (device == null) return false;
+                    CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
+                    DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == NextAddress && x.DeviceProParamName == "StationNum");
+                    DeviceProDTO? HandShakeprodto = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == NextAddress && x.DeviceProParamName == "HandShake");
+                    if (deviceProDTO == null || HandShakeprodto == null) return false;
+
+                    int StationNum = conveyorLine.Communicator.Read<ushort>(deviceProDTO.DeviceProAddress);
+                    int HandShake = conveyorLine.Communicator.Read<ushort>(HandShakeprodto.DeviceProAddress);
+                    if (StationNum == 0 && HandShake == 0 && Roadway == "C")
+                    {
+                        return true;
+                    }
+                }
+                else
+                {
+                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1003");
+                    if (device == null) return false;
+                    CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
+                    DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == NextAddress && x.DeviceProParamName == "StationNum");
+                    DeviceProDTO? HandShakeprodto = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == NextAddress && x.DeviceProParamName == "HandShake");
+                    if (deviceProDTO == null || HandShakeprodto == null) return false;
+
+                    int StationNum = conveyorLine.Communicator.Read<ushort>(deviceProDTO.DeviceProAddress);
+                    int HandShake = conveyorLine.Communicator.Read<ushort>(HandShakeprodto.DeviceProAddress);
+                    if ((StationNum == 1 && HandShake == 0 && Roadway == "B") || (StationNum == 0 && HandShake == 0 && Roadway != "B"))
+                    {
+                        return true;
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine("璇诲彇绔欏彴淇℃伅閿欒锛�"+ex.Message);
+            }
+
+            return false;
         }
 
 
@@ -208,6 +239,7 @@
         public StackerCraneTaskCommand? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task)
         {
             StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand();
+
 
             stackerCraneTaskCommand.Barcode = task.PalletCode;
             stackerCraneTaskCommand.TaskNum = task.TaskNum;
@@ -236,7 +268,9 @@
                 if (EndCodest.Length == 3)
                 {
                     string EndRow = EndCodest[0].Substring(1);
-                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(EndRow);
+                    string SCEndRow = LaneModification(task.Roadway, int.Parse(EndRow));
+
+                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(SCEndRow );
                     stackerCraneTaskCommand.EndColumn = Convert.ToInt16(EndCodest[1]);
                     stackerCraneTaskCommand.EndLayer = Convert.ToInt16(EndCodest[2]);
                 }
@@ -253,7 +287,8 @@
                 if (sourceCodes.Length == 3)
                 {
                     string StartRow = sourceCodes[0].Substring(1);
-                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(StartRow);
+                    string SCStartRow = LaneModification(task.Roadway, int.Parse(StartRow));
+                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(SCStartRow);
                     stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                     stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
                 }
@@ -265,7 +300,7 @@
                 }
 
                 //鑾峰彇绔欏彴缂栧彿
-                Dt_PlatformStation dt_Platform = _DtPlatformStationService.getStatiomInfo(task.SourceAddress);
+                Dt_PlatformStation dt_Platform = _DtPlatformStationService.getStatiomInfo(task.NextAddress);
                 string[] EndCodest = dt_Platform.Station_storey.Split("-");
                 if (EndCodest.Length == 3)
                 {
@@ -293,12 +328,15 @@
                 if (EndCodest.Length == 3)
                 {
                     string EndRow = EndCodest[0].Substring(1);
-                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(EndRow);
-                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(EndCodest[1]);
+                   string SCEnRow=LaneModification(task.Roadway,int.Parse(EndRow));
+
+                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(SCEnRow);
+                    stackerCraneTaskCommand.EndColumn = (short)(Convert.ToInt16(EndCodest[1]) + 1);
                     stackerCraneTaskCommand.EndLayer = Convert.ToInt16(EndCodest[2]);
                 }
                 else
                 {
+                    
                     //鏁版嵁閰嶇疆閿欒
                     _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"绉诲簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�");
                     return null;
@@ -308,5 +346,20 @@
             }
             return stackerCraneTaskCommand;
         }
+
+        public string LaneModification(string Roadway,int SCRow)
+        {
+            if (Roadway == "G")
+            {
+                return SCRow == 1 ? "3" : "4";
+            }else if(Roadway == "C")
+            {
+                return SCRow == 1 ? "5" : "6";
+            }
+            else
+            {
+                return SCRow.ToString();
+            }
+        }
     }
 }

--
Gitblit v1.9.3