From eaf30f88591d78699fdacf489e4aa45ac6775272 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期一, 24 三月 2025 18:02:53 +0800
Subject: [PATCH] 更新项目配置和业务逻辑

---
 CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerStationJob/CommonStackerStationCraneJob.cs |   88 +++++++++++++++++++++++++++++++++++++-------
 1 files changed, 74 insertions(+), 14 deletions(-)

diff --git a/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerStationJob/CommonStackerStationCraneJob.cs b/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerStationJob/CommonStackerStationCraneJob.cs
index 71c7a8b..713e201 100644
--- a/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerStationJob/CommonStackerStationCraneJob.cs
+++ b/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerStationJob/CommonStackerStationCraneJob.cs
@@ -152,22 +152,41 @@
                     if (content.Status)
                     {
                         var task = content.Data as Dt_Task;
-                        Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationLocation == task.TargetAddress);
-                        IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC);
-                        if (device != null)
+                        if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.TargetAddress == "001-000-001")
                         {
-                            CommonConveyorLine_After conveyorLine = (CommonConveyorLine_After)device;
-                            var proAddress = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == stationManager.stationChildCode).Where(x => x.DeviceProParamName == ConveyorLineDBName_After.InteractiveSignal.ToString()).FirstOrDefault().DeviceProAddress;
-                            string? address = proAddress;
-                            if (!proAddress.Contains(".0"))
+                            Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationLocation == task.TargetAddress);
+                            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC);
+                            if (device != null)
                             {
-                                address = proAddress + ".0";
+                                str = $"鍐欏叆瀹屾垚锛岀粰绾夸綋鍐欏叆涓嬮檷淇″彿";
+                                WriteInfo(commonStackerCrane.DeviceName, str);
+                                ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
+
+                                // 鑾峰彇杈撻�佺嚎瀵硅薄
+                                CommonConveyorLine_After conveyorLine = (CommonConveyorLine_After)device;
+
+                                // 鑾峰彇鍗忚鍦板潃
+                                var proAddress = conveyorLine.DeviceProDTOs
+                                    .FirstOrDefault(x => x.DeviceChildCode == stationManager.stationChildCode && x.DeviceProParamName == ConveyorLineDBName_After.InteractiveSignal.ToString())
+                                    ?.DeviceProAddress;
+
+                                if (proAddress == null)
+                                {
+                                    str = "鏈壘鍒板崗璁湴鍧�";
+                                    WriteInfo(commonStackerCrane.DeviceName, str);
+                                    ConsoleHelper.WriteColorLine(str, ConsoleColor.Red);
+                                    return;
+                                }
+
+                                string address = proAddress.Contains(".0") ? proAddress : proAddress + ".0";
+
+                                // 鍐欏叆 false 淇″彿
+                                WriteSignal(conveyorLine, address, false, commonStackerCrane.DeviceName);
                             }
-                            conveyorLine.Communicator.Write(str, false);
-                        }
-                        else
-                        {
-                            _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鏈壘鍒板嚭搴撶珯鍙般�恵task.NextAddress}銆戝搴旂殑閫氳瀵硅薄锛屾棤娉曟竻闄ゅ嚭搴撶珯鍙伴《鍗囩姸鎬�");
+                            else
+                            {
+                                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鏈壘鍒板嚭搴撶珯鍙般�恵task.NextAddress}銆戝搴旂殑閫氳瀵硅薄锛屾棤娉曟竻闄ゅ嚭搴撶珯鍙伴《鍗囩姸鎬�");
+                            }
                         }
                     }
                 }
@@ -211,7 +230,7 @@
 
             if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
             {
-                if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
+                if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.TargetAddress == "001-000-001")
                 {
                     Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationLocation == task.TargetAddress);
                     IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC);
@@ -361,5 +380,46 @@
 
             return stackerCraneTaskCommand;
         }
+
+        /// <summary>
+        /// 鍐欏叆淇″彿骞堕獙璇佸啓鍏ョ粨鏋�
+        /// </summary>
+        /// <param name="conveyorLine">杈撻�佺嚎瀵硅薄</param>
+        /// <param name="address">鍗忚鍦板潃</param>
+        /// <param name="signal">淇″彿鍊�</param>
+        /// <param name="deviceName">璁惧鍚嶇О</param>
+        void WriteSignal(CommonConveyorLine_After conveyorLine, string address, bool signal, string deviceName)
+        {
+            string str = string.Empty;
+
+            // 鍐欏叆淇″彿
+            conveyorLine.Communicator.Write(address, signal);
+
+            // 楠岃瘉鍐欏叆缁撴灉锛屾渶澶氶噸璇�5娆�
+            for (int i = 0; i < 5; i++)
+            {
+                var isWrite = conveyorLine.Communicator.Read<bool>(address);
+                if (isWrite == signal)
+                {
+                    break;
+                }
+                conveyorLine.Communicator.Write(address, signal);
+            }
+
+            // 鏈�缁堥獙璇佸啓鍏ョ粨鏋�
+            var finalWrite = conveyorLine.Communicator.Read<bool>(address);
+            if (finalWrite == signal)
+            {
+                str = $"{address}-鍐欏叆{signal}鎴愬姛";
+                ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
+                WriteInfo(deviceName, str);
+            }
+            else
+            {
+                str = $"{address}-鍐欏叆{signal}澶辫触";
+                ConsoleHelper.WriteColorLine(str, ConsoleColor.Red);
+                WriteInfo(deviceName, str);
+            }
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3