From 4d7c377173784d6ec495b2c4178395a65f4e2a76 Mon Sep 17 00:00:00 2001
From: zhangchengsong <zhangchengsong@hnkhzn.com>
Date: 星期三, 22 四月 2026 19:55:18 +0800
Subject: [PATCH] 1

---
 项目代码/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs |  285 ++++++++++++++++++++++++++++++--------------------------
 1 files changed, 153 insertions(+), 132 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 a16b52a..f90cde9 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"
@@ -2,6 +2,7 @@
 using HslCommunication;
 using Microsoft.AspNetCore.Components.Routing;
 using Microsoft.AspNetCore.Hosting;
+using Newtonsoft.Json;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
 using Quartz;
 using System;
@@ -17,6 +18,7 @@
 using System.Text;
 using System.Threading.Tasks;
 using System.Transactions;
+using WIDESEA_Comm.Http;
 using WIDESEA_Common.Log;
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Core;
@@ -35,6 +37,7 @@
 using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
 using WIDESEAWCS_TaskInfoService;
 using WIDESEAWCS_Tasks.StackerCraneJob;
+using static WIDESEAWCS_Model.Models.System.JobError;
 
 namespace WIDESEAWCS_Tasks
 {
@@ -53,18 +56,50 @@
             _taskExecuteDetailService = taskExecuteDetailService;
             _taskRepository = taskRepository;
             _routerService = routerService;
-            _DtPlatformStationService= dt_PlatformStationService;
+            _DtPlatformStationService = dt_PlatformStationService;
         }
+        private static readonly Dictionary<string, bool> _deviceLastStatus = new Dictionary<string, bool>();
+        public string urlWMSdeverror = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlWMSdeverror"];
+
 
         public Task Execute(IJobExecutionContext context)
         {
             try
             {
                 CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
-                
-
                 if (commonStackerCrane != null)
                 {
+                WriteLog.Write_Log("鍫嗗灈鏈哄綋鍓嶇姸鎬佷俊鎭�", $"{commonStackerCrane.DeviceCode}搴撳爢鍨涙満褰撳墠鐘舵��",
+                                                $"鍫嗗灈鏈鸿澶囩姸鎬佸湴鍧�:銆怐B105.2.0銆�,璇诲彇鐨勬暟鎹細銆恵commonStackerCrane.StackerCraneAutoStatusDes}銆慭n" +
+                                               $"鍫嗗灈鏈哄伐浣滄ā寮忓湴鍧�:銆怐B105.3.0銆�,璇诲彇鐨勬暟鎹細銆恵commonStackerCrane.StackerCraneStatusDes}銆慭n" +
+                                               $"鍫嗗灈鏈轰綔涓氱姸鎬佸湴鍧�:銆怐B105.22.0銆�,璇诲彇鐨勬暟鎹細銆恵commonStackerCrane.StackerCraneWorkStatusDes}銆慭n" +
+                                               $"鍫嗗灈鏈哄綋鍓嶄换鍔℃墽琛屼腑鍦板潃:銆怐B105.18.0銆�,璇诲彇鐨勬暟鎹細銆恵commonStackerCrane.CurrentTaskNum}銆慭n");
+                    // 鑾峰彇褰撳墠鐘舵��
+                    bool isFaultNow = commonStackerCrane.StackerCraneStatusDes.Equals("鏁呴殰");
+                    string deviceCode = commonStackerCrane.DeviceCode;
+
+                    if (!_deviceLastStatus.ContainsKey(deviceCode))
+                    {
+                        _deviceLastStatus[deviceCode] = isFaultNow;
+                        if (isFaultNow)
+                        {
+                            SendDevError(commonStackerCrane, "66", "start", ReadStackerFaults(commonStackerCrane));
+                        }
+                    }
+                    else
+                    {
+                        bool lastStatus = _deviceLastStatus[deviceCode];
+                        if (!lastStatus && isFaultNow)
+                        {
+                            SendDevError(commonStackerCrane, "66", "start", ReadStackerFaults(commonStackerCrane));
+                            _deviceLastStatus[deviceCode] = true;
+                        }
+                        else if (lastStatus && !isFaultNow)
+                        {
+                            SendDevError(commonStackerCrane, "99", "stop", "鍫嗗灈鏈烘仮澶嶆甯�");
+                            _deviceLastStatus[deviceCode] = false;
+                        }
+                    }
 
                     UpdateHandShake(commonStackerCrane.CurrentTaskNum, commonStackerCrane.StackerCraneWorkStatusDes);
                     //浠诲姟瀹屾垚StackerCraneWorkStatus
@@ -89,20 +124,13 @@
                             WebResponseContent webResponse = _taskService.StackCraneTaskCompleted(commonStackerCrane.CurrentTaskNum, PalletCode);
                             if (webResponse.Status)
                             {
-                                WriteLog.Write_Log("鍫嗗灈鏈轰换鍔′笂鎶ュ畬鎴愪俊鎭�", "鍫嗗灈鏈轰换鍔′笂鎶ュ畬鎴愪俊鎭�", $"銆恵commonStackerCrane.DeviceCode}銆戝簱鍫嗗灈鏈轰笂鎶ヤ换鍔″彿:銆恵commonStackerCrane.CurrentTaskNum}銆戝畬鎴愪俊鍙凤紒");
+                                Task.Run(() => WriteLog.Write_Log("鍫嗗灈鏈轰换鍔′笂鎶ュ畬鎴愪俊鎭�", "鍫嗗灈鏈轰换鍔′笂鎶ュ畬鎴愪俊鎭�", $"銆恵commonStackerCrane.DeviceCode}銆戝簱鍫嗗灈鏈轰笂鎶ヤ换鍔″彿:銆恵commonStackerCrane.CurrentTaskNum}銆戝畬鎴愪俊鍙凤紒"));
 
                                 bool ddjfk = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                             }
                         }
                     }
 
-                    WriteLog.Write_Log("鍫嗗灈鏈哄綋鍓嶇姸鎬�", "鍫嗗灈鏈哄綋鍓嶇姸鎬佷俊鎭�", $"鍫嗗灈鏈鸿澶囧湴鍧�:銆怐B105.2.0銆�,璇诲彇鐨勬暟鎹細銆恵commonStackerCrane.StackerCraneAutoStatusDes}銆慭n" +
-                           $"鍫嗗灈鏈哄伐浣滄ā寮忓湴鍧�:銆怐B105.3.0銆�,璇诲彇鐨勬暟鎹細銆恵commonStackerCrane.StackerCraneStatusDes}銆慭n" +
-                           $"鍫嗗灈鏈轰綔涓氱姸鎬佸湴鍧�:銆怐B105.22.0銆�,璇诲彇鐨勬暟鎹細銆恵commonStackerCrane.StackerCraneWorkStatusDes}銆慭n" +
-                           $"鍫嗗灈鏈哄綋鍓嶄换鍔℃墽琛屼腑鍦板潃:銆怐B105.18.0銆�,璇诲彇鐨勬暟鎹細銆恵commonStackerCrane.CurrentTaskNum}銆慭n");
-
-                  
-                   
 
                     if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal)
                     {
@@ -140,23 +168,43 @@
         }
 
         /// <summary>
-        /// 浠诲姟瀹屾垚浜嬩欢璁㈤槄鐨勬柟娉�
+        /// 鏁呴殰涓婃姤锛堟敼涓篴wait璋冪敤锛屼慨澶嶅紓姝UG锛�
         /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="e"></param>
-        private void CommonStackerCrane_StackerCraneTaskCompletedEventHandler(object? sender, WIDESEAWCS_QuartzJob.StackerCrane.StackerCraneTaskCompletedEventArgs e)
+        public void SendDevError(CommonStackerCrane crane, string errorcode, string dealType, string errorInfo = "")
         {
-            CommonStackerCrane? commonStackerCrane = sender as CommonStackerCrane;
-            if (commonStackerCrane != null)
+            CommandResult commandResult = new CommandResult();
+            try
             {
-                if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5 && e.TaskNum !=0)
+                DeviceErrorRequest deviceErrorRequest = new DeviceErrorRequest
                 {
-                    //Console.Out.WriteLine("TaskCompleted" + e.TaskNum);
-                    //_taskService.StackCraneTaskCompleted(e.TaskNum,);
-                    commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
-                }
+                    devErrorJsons = new List<DeviceErrorInfo>
+                    {
+                        new DeviceErrorInfo
+                        {
+                            devuuid = crane.DeviceCode,
+                            id = "",
+                            errorcode = errorcode,
+                            errorinfo = errorInfo,
+                            erroraddress = "DB107",
+                            warehouse = crane.DeviceCode == "B" ? "ZR17":(crane.DeviceCode == "G"?"ZR18":"ZR16"),
+                            remark = dealType == "start" ? "璁惧寮傚父" : "璁惧鎭㈠",
+                            devname =  $"{crane.DeviceCode}搴撳爢鍨涙満",
+                        }
+                    },
+                    dealType = dealType,
+                    psd = "akjfapjfpadaoif",
+                };
+                
+                commandResult = HttpHelper.Post<CommandResult>(urlWMSdeverror, deviceErrorRequest, "璁惧鏁呴殰鍥炶皟");
+                WriteLog.Write_Log("鍚屾缁欎笂娓歌澶囨晠闅滀俊鎭�", "璁惧鏁呴殰淇℃伅", $"璁惧id锛氥�恵crane.DeviceCode}銆戯紝鎴愬姛", $"璁惧鍥炶皟鐘舵�侊細銆恵dealType}銆戯紝寮傚父淇℃伅锛氥�恵errorInfo}銆慭n" +
+                    $"璋冪敤涓婃父杩斿洖缁撴灉淇℃伅锛氥�恵commandResult?.ToJsonString() ?? "杩斿洖缁撴灉涓簄ull"}銆�");
+            }
+            catch (Exception ex)
+            {
+                WriteLog.Write_Log("鏁呴殰涓婃姤澶辫触", "閿欒", ex.ToString());
             }
         }
+
 
         /// <summary>
         /// 鑾峰彇浠诲姟
@@ -183,9 +231,9 @@
                                 return taskItem;
                             }
                         }
-                        else if (taskItem.TaskType == (int)TaskTypeEnum.Inbound || taskItem.TaskType == (int)TaskTypeEnum.Inventorybound)
+                        else if ((InTaskStationIsOccupied(taskItem.SourceAddress, taskItem.Roadway) && taskItem.TaskType == (int)TaskTypeEnum.Inbound) || taskItem.TaskType == (int)TaskTypeEnum.Inventorybound)
                         {
-                            InTaskStationIsOccupied(taskItem.SourceAddress, taskItem.Roadway);
+                            
                             return taskItem;
                         }
                     }
@@ -209,90 +257,55 @@
         {
             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;
+                    CommonConveyorLine? conveyorLine = null;
+                    string deviceCode = Roadway == "C" ? "1004" : "1003";
+                    conveyorLine = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceCode) as CommonConveyorLine;
+                if (conveyorLine == null) return false;
 
-                    int StationNum = conveyorLine.Communicator.Read<ushort>(deviceProDTO.DeviceProAddress);
-                    int HandShake = conveyorLine.Communicator.Read<ushort>(HandShakeprodto.DeviceProAddress);
-                     conveyorLine.Communicator.Write<short>(HandShakeprodto.DeviceProAddress, 1);
+                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;
 
-                    WriteLog.Write_Log("鍑哄簱搴撳彛鐘舵�佷俊鎭�", "鍑哄簱搴撳彛鐘舵�佷俊鎭�", $"搴撳彛鏄�恵NextAddress}銆戯紝鐢宠鐘舵�佸湴鍧�锛氥�恵HandShakeprodto.DeviceProAddress}銆�,璇诲彇鐨勬暟鎹細銆恵HandShake}銆慭n" +
-                         $"搴撳彛鏄惁鏈夎揣鐘舵�佸湴鍧�锛氥�恵deviceProDTO.DeviceProAddress}銆戯紝璇诲彇鐨勬暟鎹�恵StationNum}銆�");
-                    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);
 
-                    int StationNum = conveyorLine.Communicator.Read<ushort>(deviceProDTO.DeviceProAddress);
-                    int HandShake = conveyorLine.Communicator.Read<ushort>(HandShakeprodto.DeviceProAddress);
-                    WriteLog.Write_Log("鍑哄簱搴撳彛鐘舵�佷俊鎭�", "鍑哄簱搴撳彛鐘舵�佷俊鎭�", $"搴撳彛鏄�恵NextAddress}銆戯紝鐢宠鐘舵�佸湴鍧�锛氥�恵HandShakeprodto.DeviceProAddress}銆�,璇诲彇鐨勬暟鎹細銆恵HandShake}銆慭n" +
-                        $"搴撳彛鏄惁鏈夎揣鐘舵�佸湴鍧�锛氥�恵deviceProDTO.DeviceProAddress}銆戯紝璇诲彇鐨勬暟鎹�恵StationNum}銆�");
-
-                    if ((StationNum == 1 && HandShake == 0 && Roadway == "B") || (StationNum == 0 && HandShake == 0 && Roadway != "B"))
-                    {
-                        return true;
-                    }
-                }
+                WriteLog.Write_Log("鍑哄簱搴撳彛鐘舵�佷俊鎭�", "鍑哄簱搴撳彛鐘舵�佷俊鎭�", $"搴撳彛鏄�恵NextAddress}銆戯紝鐢宠鐘舵�佸湴鍧�锛氥�恵HandShakeprodto.DeviceProAddress}銆�,璇诲彇鐨勬暟鎹細銆恵HandShake}銆慭n搴撳彛鏄惁鏈夎揣鐘舵�佸湴鍧�锛氥�恵deviceProDTO.DeviceProAddress}銆戯紝璇诲彇鐨勬暟鎹�恵StationNum}銆�");
+                  if (Roadway == "C" || Roadway == "G") return StationNum == 0 && HandShake == 0;
+                return (StationNum == 1 && HandShake == 0 && Roadway == "B");
             }
             catch (Exception ex)
             {
-                Console.WriteLine("璇诲彇绔欏彴淇℃伅閿欒锛�"+ex.Message);
+              Console.WriteLine("璇诲彇绔欏彴淇℃伅閿欒锛�" + ex.Message);
+                return false;
             }
-
-            return false;
         }
         /// <summary>
         /// 鍏ュ簱浠诲姟搴撳彛鏈夎揣鏃犺揣鐘舵��
         /// </summary>
-        private void InTaskStationIsOccupied(string SourceAddress, string Roadway)
+        public bool InTaskStationIsOccupied(string SourceAddress, string Roadway)
         {
             try
             {
-                if (Roadway == "C")
-                {
-                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1004");
-                    CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
-                    DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SourceAddress && x.DeviceProParamName == "StationNum");
-                    DeviceProDTO? HandShakeprodto = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SourceAddress && x.DeviceProParamName == "HandShake");
- 
-                    int StationNum = conveyorLine.Communicator.Read<ushort>(deviceProDTO.DeviceProAddress);
-                    int HandShake = conveyorLine.Communicator.Read<ushort>(HandShakeprodto.DeviceProAddress);
-                    WriteLog.Write_Log("鍏ュ簱搴撳彛鐘舵�佷俊鎭�", "鍏ュ簱搴撳彛鐘舵�佷俊鎭�", $"搴撳彛鏄�恵SourceAddress}銆戯紝鐢宠鐘舵�佸湴鍧�锛氥�恵HandShakeprodto.DeviceProAddress}銆�,璇诲彇鐨勬暟鎹細銆恵HandShake}銆慭n" +
-                        $"搴撳彛鏄惁鏈夎揣鐘舵�佸湴鍧�锛氥�恵deviceProDTO.DeviceProAddress}銆戯紝璇诲彇鐨勬暟鎹�恵StationNum}銆�");
-                }
-                else
-                {
-                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1003");
-                    CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
-                    DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SourceAddress && x.DeviceProParamName == "StationNum");
-                    DeviceProDTO? HandShakeprodto = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SourceAddress && x.DeviceProParamName == "HandShake");
 
-                    int StationNum = conveyorLine.Communicator.Read<ushort>(deviceProDTO.DeviceProAddress);
-                    int HandShake = conveyorLine.Communicator.Read<ushort>(HandShakeprodto.DeviceProAddress);
-                    WriteLog.Write_Log("鍏ュ簱搴撳彛鐘舵�佷俊鎭�", "鍏ュ簱搴撳彛鐘舵�佷俊鎭�", $"搴撳彛鏄�恵SourceAddress}銆戯紝鐢宠鐘舵�佸湴鍧�锛氥�恵HandShakeprodto.DeviceProAddress}銆�,璇诲彇鐨勬暟鎹細銆恵HandShake}銆慭n" +
-                        $"搴撳彛鏄惁鏈夎揣鐘舵�佸湴鍧�锛氥�恵deviceProDTO.DeviceProAddress}銆戯紝璇诲彇鐨勬暟鎹�恵StationNum}銆�");
-                }
+                CommonConveyorLine? conveyorLine = null;
+                    string deviceCode = Roadway == "C" ? "1004" : "1003";
+                    conveyorLine = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceCode) as CommonConveyorLine;
+                if (conveyorLine == null) return false;
+
+                DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SourceAddress && x.DeviceProParamName == "StationNum");
+                DeviceProDTO? HandShakeprodto = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SourceAddress && 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);
+                WriteLog.Write_Log("鍏ュ簱搴撳彛鐘舵�佷俊鎭�", "鍏ュ簱搴撳彛鐘舵�佷俊鎭�", $"搴撳彛鏄�恵SourceAddress}銆戯紝鐢宠鐘舵�佸湴鍧�锛氥�恵HandShakeprodto.DeviceProAddress}銆�,璇诲彇鐨勬暟鎹細銆恵HandShake}銆慭n搴撳彛鏄惁鏈夎揣鐘舵�佸湴鍧�锛氥�恵deviceProDTO.DeviceProAddress}銆戯紝璇诲彇鐨勬暟鎹�恵StationNum}銆�");
+                return StationNum == 1;
             }
             catch (Exception ex)
             {
-                Console.WriteLine("璇诲彇绔欏彴淇℃伅閿欒锛�" + ex.Message);
+               Console.WriteLine("璇诲彇绔欏彴淇℃伅閿欒锛�" + ex.Message);
+                return false;
             }
-
         }
 
         /// <summary>
@@ -421,7 +434,7 @@
                 {
 
                     //鏁版嵁閰嶇疆閿欒
-                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"绉诲簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�");
+                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鐩樼偣浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�");
                     return null;
                 }
 
@@ -451,54 +464,62 @@
         /// <param name="stackerCraneWorkStatusDes"></param>
         public void UpdateHandShake(int taskNum, string stackerCraneWorkStatusDes)
         {
-            // 1. 鏌ヨ浠诲姟锛岀┖鍊肩洿鎺ヨ繑鍥�
-            Dt_Task? dtTask = _taskRepository.QueryFirst(x => x.TaskNum == taskNum);
-            if (dtTask == null) return;
-
-            // 2. 瀹氫箟鍥哄畾鍦板潃
-            string[] targetAddresses = { "G03", "G04", "C02", "C01" };
-
-            // 3. 鏉′欢鍒ゆ柇 + 纭畾鍐欏叆鍊�
-            short writeValue = -1;
-            if (dtTask.TaskType == 100 && targetAddresses.Contains(dtTask.TargetAddress))
-            {
-                writeValue = stackerCraneWorkStatusDes switch
+                try
                 {
-                    "鏀捐揣涓�" => 1,
-                    "浠诲姟瀹屾垚" => 0,
-                    _ => -1
-                };
-            }
+                    var dtTask = _taskRepository.QueryFirst(x => x.TaskNum == taskNum);
+                    if (dtTask == null) return;
 
-            // 4. 鑾峰彇璁惧缂栫爜
-            string deviceCode = dtTask.CurrentAddress.StartsWith("C") ? "1004" : "1003";
+                    string[] targets = { "G02", "G03", "G04", "C02", "C01" };
+                    if (dtTask.TaskType != 100 || !targets.Contains(dtTask.TargetAddress)) return;
 
-            // 5. 鑾峰彇璁惧锛岀┖鍊肩洿鎺ヨ繑鍥�
-            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceCode);
-            if (device != null && writeValue != -1)
-            {
-                CommonConveyorLine? conveyorLine = (CommonConveyorLine)device;
+                    short writeValue = stackerCraneWorkStatusDes switch
+                    {
+                        "鏀捐揣涓�" => 1,
+                        "浠诲姟瀹屾垚" => 0,
+                        _ => -1
+                    };
+                    if (writeValue == -1) return;
 
-                // 6. 鑾峰彇鎻℃墜鐐逛綅锛岀┖鍊肩洿鎺ヨ繑鍥�
-                DeviceProDTO? handShake = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == dtTask.TargetAddress && x.DeviceProParamName == "HandShake");
-                if (handShake == null)
-                {
-                    WriteLog.Write_Log("鍑哄簱搴撳彛鍏夋爡鐘舵�侀敊璇俊鎭�", "鍑哄簱搴撳彛鍏夋爡鐘舵�侀敊璇俊鎭�", $"WCS鏈壘鍒板簱鍙d俊鎭槸銆恵dtTask.TargetAddress}銆戯紝浠诲姟鍙凤細銆恵dtTask.TaskNum}銆�,鍫嗗灈鏈轰綔涓氱姸鎬侊細銆恵stackerCraneWorkStatusDes}銆�");
-                    return;
+                    CommonConveyorLine? conveyorLine = null;
+                    lock (Storage.Devices)
+                    {
+                        string deviceCode = dtTask.CurrentAddress.StartsWith("C") ? "1004" : "1003";
+                        conveyorLine = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceCode) as CommonConveyorLine;
+                    }
+                    if (conveyorLine == null) return;
+
+                    var handShake = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == dtTask.TargetAddress && x.DeviceProParamName == "HandShake");
+                    if (handShake == null) return;
+
+                    conveyorLine.Communicator.Write<short>(handShake.DeviceProAddress, writeValue);
                 }
-                    // 7. 鍐欏叆鍊�
-                 conveyorLine.Communicator.Write<short>(handShake.DeviceProAddress, writeValue);
-                WriteLog.Write_Log("鍑哄簱搴撳彛鍏夋爡鐘舵�佹甯镐俊鎭�", "鍑哄簱搴撳彛鍏夋爡鐘舵�佹甯镐俊鎭�", $"搴撳彛鏄�恵dtTask.TargetAddress}銆戯紝鐢宠鐘舵�佸湴鍧�锛氥�恵handShake.DeviceProAddress}銆�,璇诲彇鐨勬暟鎹細銆恵conveyorLine.Communicator.Read<ushort>(handShake.DeviceProAddress)}銆慭n" +
-                 $"浠诲姟鍙凤細銆恵dtTask.TaskNum}銆�,鍫嗗灈鏈轰綔涓氱姸鎬侊細銆恵stackerCraneWorkStatusDes}銆�");
-                return;
-            }
-            else
-            {
-                WriteLog.Write_Log("鍑哄簱搴撳彛鍏夋爡鐘舵�侀敊璇俊鎭�", "鍑哄簱搴撳彛鍏夋爡鐘舵�侀敊璇俊鎭�", $"搴撳彛鏄�恵dtTask.TargetAddress}銆戯紝浠诲姟鍙凤細銆恵dtTask.TaskNum}銆�,鍫嗗灈鏈轰綔涓氱姸鎬侊細銆恵stackerCraneWorkStatusDes}銆�");
-                return;
-            }
-           
+                catch
+                { }
         }
 
+        /// <summary>
+        /// 璇诲彇鏁呴殰锛堜紭鍖朑C锛�
+        /// </summary>
+        public string ReadStackerFaults(CommonStackerCrane crane)
+        {
+            try
+            {
+                foreach (StackerFault fault in Enum.GetValues(typeof(StackerFault)))
+                {
+                    try
+                    {
+                        bool isFault = crane.Communicator.Read<bool>(fault.ToPlcAddress());
+                        if (isFault)
+                            return fault.GetDesc();
+                    }
+                    catch { }
+                }
+            }
+            catch (Exception ex)
+            {
+                WriteLog.Write_Log("DB107鏁呴殰璇诲彇寮傚父", "閿欒", ex.ToString());
+            }
+            return string.Empty;
+        }
     }
 }

--
Gitblit v1.9.3