From 2cc749ec598c39f9172f9b989979f6218ec256b1 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <1247017146@qq.com>
Date: 星期四, 27 三月 2025 11:06:24 +0800
Subject: [PATCH] 1

---
 CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerStationJob/CommonStackerStationCraneJob.cs |  138 ++++++++++++++++++++++++++++++++++++---------
 1 files changed, 109 insertions(+), 29 deletions(-)

diff --git a/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerStationJob/CommonStackerStationCraneJob.cs b/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerStationJob/CommonStackerStationCraneJob.cs
index 6852e39..7bc6ebb 100644
--- a/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerStationJob/CommonStackerStationCraneJob.cs
+++ b/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerStationJob/CommonStackerStationCraneJob.cs
@@ -1,4 +1,4 @@
-锘縰sing HslCommunication;
+锘縰sing Masuit.Tools.Systems;
 using Newtonsoft.Json;
 using Quartz;
 using System.Diagnostics.CodeAnalysis;
@@ -9,20 +9,17 @@
 using WIDESEAWCS_Core.Caches;
 using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_Core.HttpContextUser;
-using WIDESEAWCS_DTO.MOM;
 using WIDESEAWCS_IProcessRepository;
 using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_ITaskInfoService;
-using WIDESEAWCS_Model;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
 using WIDESEAWCS_QuartzJob.DeviceBase;
-using WIDESEAWCS_QuartzJob.Models;
 using WIDESEAWCS_QuartzJob.Service;
 using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
 using WIDESEAWCS_SignalR;
+using WIDESEAWCS_Tasks.ConveyorLineJob;
 using WIDESEAWCS_Tasks.StackerCraneJob;
-using WIDESEAWCS_Common;
 
 namespace WIDESEAWCS_Tasks
 {
@@ -76,15 +73,15 @@
                                     bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
                                     if (sendFlag)
                                     {
-                                        StringBuilder builder = new StringBuilder();
-                                        builder.AppendLine();
-                                        builder.AppendLine($"銆恵commonStackerCrane.DeviceName}銆戝爢鍨涙満鐘舵�侊細銆恵commonStackerCrane.StackerCraneStatusDes}銆�,鏃堕棿锛氥�恵DateTime.Now}銆�");
-                                        builder.AppendLine($"銆恵commonStackerCrane.DeviceName}銆戞墜鑷姩鐘舵�侊細銆恵commonStackerCrane.StackerCraneAutoStatusDes}銆�,鏃堕棿锛氥�恵DateTime.Now}銆�");
-                                        builder.AppendLine($"銆恵commonStackerCrane.DeviceName}銆戜綔涓氱姸鎬侊細銆恵commonStackerCrane.StackerCraneWorkStatusDes}銆�,鏃堕棿锛氥�恵DateTime.Now}銆�");
-                                        builder.AppendLine($"銆恵commonStackerCrane.DeviceName}銆戜笅鍙戜换鍔℃垚鍔�,銆恵JsonConvert.SerializeObject(stackerCraneTaskCommand, Formatting.Indented)}銆�");
-                                        builder.AppendLine($"鏃堕棿锛氥�恵DateTime.Now}銆�");
-                                        builder.AppendLine();
-                                        ConsoleHelper.WriteColorLine(builder, ConsoleColor.Blue);
+                                        //StringBuilder builder = new StringBuilder();
+                                        //builder.AppendLine();
+                                        //builder.AppendLine($"銆恵commonStackerCrane.DeviceName}銆戝爢鍨涙満鐘舵�侊細銆恵commonStackerCrane.StackerCraneStatusDes}銆�,鏃堕棿锛氥�恵DateTime.Now}銆�");
+                                        //builder.AppendLine($"銆恵commonStackerCrane.DeviceName}銆戞墜鑷姩鐘舵�侊細銆恵commonStackerCrane.StackerCraneAutoStatusDes}銆�,鏃堕棿锛氥�恵DateTime.Now}銆�");
+                                        //builder.AppendLine($"銆恵commonStackerCrane.DeviceName}銆戜綔涓氱姸鎬侊細銆恵commonStackerCrane.StackerCraneWorkStatusDes}銆�,鏃堕棿锛氥�恵DateTime.Now}銆�");
+                                        //builder.AppendLine($"銆恵commonStackerCrane.DeviceName}銆戜笅鍙戜换鍔℃垚鍔�,銆恵JsonConvert.SerializeObject(stackerCraneTaskCommand, Formatting.Indented)}銆�");
+                                        //builder.AppendLine($"鏃堕棿锛氥�恵DateTime.Now}銆�");
+                                        //builder.AppendLine();
+                                        //ConsoleHelper.WriteColorLine(builder, ConsoleColor.Blue);
                                         commonStackerCrane.LastTaskType = task.TaskType;
                                         _taskService.UpdateTaskStatusToNext(task.TaskNum);
                                     }
@@ -151,6 +148,47 @@
                     str = $"{commonStackerCrane.DeviceName}銆慦MS|WCS浠诲姟瀹屾垚锛氥�恵content.Status}銆�,鍫嗗灈鏈哄畬鎴愪俊鍙峰啓鍏ワ細銆恵isWorkType}銆�,浠诲姟鍙凤細銆恵e.TaskNum}銆戞椂闂淬�恵DateTime.Now}銆�";
                     WriteInfo(commonStackerCrane.DeviceName, str);
                     ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
+
+                    if (content.Status)
+                    {
+                        var task = content.Data as Dt_Task;
+                        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);
+                            if (device != null)
+                            {
+                                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);
+                            }
+                            else
+                            {
+                                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鏈壘鍒板嚭搴撶珯鍙般�恵task.NextAddress}銆戝搴旂殑閫氳瀵硅薄锛屾棤娉曟竻闄ゅ嚭搴撶珯鍙伴《鍗囩姸鎬�");
+                            }
+                        }
+                    }
                 }
             }
         }
@@ -192,16 +230,20 @@
 
             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);
                     if (device != null)
                     {
                         CommonConveyorLine_After conveyorLine = (CommonConveyorLine_After)device;
-                        string str = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == stationManager.stationChildCode).Select(x => x.DeviceProAddress) + ".0";
+                        var proAddress = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == stationManager.stationChildCode).Where(x => x.DeviceProParamName == ConveyorLineDBName_After.InteractiveSignal.ToString()).FirstOrDefault().DeviceProAddress;
+                        string? str = proAddress;
+                        if (!proAddress.Contains(".0"))
+                        {
+                            str = proAddress + ".0";
+                        }
                         conveyorLine.Communicator.Write(str, true);
-                        return task;
                     }
                     else
                     {
@@ -209,20 +251,17 @@
                         return null;
                     }
                 }
+                // 妫�鏌ュ綋鍓嶅嚭搴撲换鍔$珯鍙版槸鍚﹀厑璁告斁璐�
+                var occupiedStation = OutTaskStationIsOccupied(task);
+                if (occupiedStation == null)
+                {
+                    // 濡傛灉褰撳墠鍑哄簱浠诲姟绔欏彴涓嶅厑璁告斁璐э紝鎺掗櫎褰撳墠浠诲姟锛屾煡鎵惧叾浠栧嚭搴撲换鍔�
+                    ConsoleHelper.WriteErrorLine($"浠诲姟鍙凤細銆恵task.TaskNum}銆戝嚭搴撳湴鍧�锛氥�恵task.NextAddress}銆戜笉鍏佽鏀捐揣");
+                    task = FindAnotherOutboundTask(commonStackerCrane.DeviceCode, task);
+                }
                 else
                 {
-                    // 妫�鏌ュ綋鍓嶅嚭搴撲换鍔$珯鍙版槸鍚﹀厑璁告斁璐�
-                    var occupiedStation = OutTaskStationIsOccupied(task);
-                    if (occupiedStation == null)
-                    {
-                        // 濡傛灉褰撳墠鍑哄簱浠诲姟绔欏彴涓嶅厑璁告斁璐э紝鎺掗櫎褰撳墠浠诲姟锛屾煡鎵惧叾浠栧嚭搴撲换鍔�
-                        ConsoleHelper.WriteErrorLine($"浠诲姟鍙凤細銆恵task.TaskNum}銆戝嚭搴撳湴鍧�锛氥�恵task.NextAddress}銆戜笉鍏佽鏀捐揣");
-                        task = FindAnotherOutboundTask(commonStackerCrane.DeviceCode, task);
-                    }
-                    else
-                    {
-                        return task;
-                    }
+                    return task;
                 }
 
                 if (task == null)
@@ -341,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