From fe2a1e74780259605cd230e6f9c629c3dd7fdf15 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期五, 10 四月 2026 20:19:06 +0800
Subject: [PATCH] feat: 添加消防任务支持并修复堆垛机状态处理

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs |   64 ++++++++++++++++++++-----------
 1 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs
index 66e63ff..d940fb7 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs
@@ -1,4 +1,5 @@
 锘�#region << 鐗� 鏈� 娉� 閲� >>
+
 /*----------------------------------------------------------------
  * 鍛藉悕绌洪棿锛歐IDESEAWCS_QuartzJob
  * 鍒涘缓鑰咃細鑳$搴�
@@ -11,24 +12,19 @@
  * 淇敼鏃堕棿锛�
  * 鐗堟湰锛歏1.0.1
  * 淇敼璇存槑锛�
- * 
+ *
  *----------------------------------------------------------------*/
+
 #endregion << 鐗� 鏈� 娉� 閲� >>
 
 using HslCommunication;
-using Microsoft.AspNetCore.Http;
-using System;
-using System.Collections.Generic;
 using System.ComponentModel;
-using System.Linq;
 using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
 using WIDESEAWCS_Communicator;
-using WIDESEAWCS_Core.Enums;
 using WIDESEAWCS_QuartzJob.DeviceBase;
 using WIDESEAWCS_QuartzJob.DTO;
 using WIDESEAWCS_QuartzJob.StackerCrane;
+using WIDESEAWCS_QuartzJob.StackerCrane.Common;
 using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
 
 namespace WIDESEAWCS_QuartzJob
@@ -37,29 +33,35 @@
     /// 涓�鑸爢鍨涙満瀹炵幇绫伙紝瀹炵幇鍫嗗灈鏈烘帴鍙e眰
     /// </summary>
     [Description("鍫嗗灈鏈�")]
-    public class CommonStackerCrane : IStackerCrane
+    public class CommonStackerCrane : StackerCraneBase, IStackerCrane
     {
         #region Private Member
+
         /// <summary>
         /// 鍫嗗灈鏈洪�氳瀵硅薄
         /// </summary>
         private BaseCommunicator _communicator;
+
         /// <summary>
         /// 鍫嗗灈鏈哄崗璁俊鎭�
         /// </summary>
         private readonly List<DeviceProDTO> _deviceProDTOs;
+
         /// <summary>
         /// 鍫嗗灈鏈哄崗璁槑缁嗕俊鎭�
         /// </summary>
         private readonly List<DeviceProtocolDetailDTO> _deviceProtocolDetailDTOs;
+
         /// <summary>
         /// 璁惧缂栧彿
         /// </summary>
         public readonly string _deviceCode;
+
         /// <summary>
         /// 璁惧鍚嶇О
         /// </summary>
         public readonly string _deviceName;
+
         /// <summary>
         /// 涓婁竴娆′换鍔″彿
         /// </summary>
@@ -70,9 +72,11 @@
         private bool _heartStatr = true;
 
         private bool _isConnected = true;
+
         #endregion Private Member
 
         #region Public Member
+
         /// <summary>
         /// 鍫嗗灈鏈洪�氳瀵硅薄
         /// </summary>
@@ -154,6 +158,11 @@
         public bool IsConnected => Communicator.IsConnected && _isConnected;
 
         /// <summary>
+        /// 鍫嗗灈鏈哄畬鎴愪簨浠舵槸鍚﹀凡璁㈤槄
+        /// </summary>
+        public bool IsEventSubscribed => StackerCraneTaskCompletedEventHandler != null;
+
+        /// <summary>
         /// 鍫嗗灈鏈轰换鍔″畬鎴愪簨浠�
         /// </summary>
         public event EventHandler<StackerCraneTaskCompletedEventArgs> StackerCraneTaskCompletedEventHandler;
@@ -163,10 +172,6 @@
         /// </summary>
         public object StackerCraneTaskCommand { get; set; }
 
-        /// <summary>
-        /// 鍫嗗灈鏈哄畬鎴愪簨浠舵槸鍚﹀凡璁㈤槄
-        /// </summary>
-        public bool IsEventSubscribed => StackerCraneTaskCompletedEventHandler != null;
 
         /// <summary>
         /// 涓婁竴娆′换鍔$殑绫诲瀷
@@ -176,6 +181,7 @@
         #endregion
 
         #region Constructor Function
+
         /// <summary>
         /// 鏋勯�犲嚱鏁�
         /// </summary>
@@ -193,9 +199,11 @@
             _deviceName = deviceName;
             CheckConnect();
         }
+
         #endregion
 
         #region Private Method
+
         /// <summary>
         /// 鏍规嵁鍗忚璇诲彇鍫嗗灈鏈虹姸鎬�
         /// </summary>
@@ -217,7 +225,7 @@
                 {
                     return DeviceStatus.Idle;
                 }
-                else if (StackerCraneWorkStatusValue == StackerCraneWorkStatus.Putting || StackerCraneWorkStatusValue == StackerCraneWorkStatus.PickUp || StackerCraneWorkStatusValue == StackerCraneWorkStatus.PickUpCompleted || StackerCraneWorkStatusValue == StackerCraneWorkStatus.PutCompleted)
+                else if (StackerCraneWorkStatusValue == StackerCraneWorkStatus.Putting || StackerCraneWorkStatusValue == StackerCraneWorkStatus.PickUp || StackerCraneWorkStatusValue == StackerCraneWorkStatus.PutMove || StackerCraneWorkStatusValue == StackerCraneWorkStatus.PutCompleted)
                 {
                     return DeviceStatus.Working;
                 }
@@ -228,7 +236,11 @@
         private int GetCurrentTaskNum()
         {
             DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(CurrentTaskNum));
-            return devicePro == null ? throw new Exception($"璇诲彇褰撳墠浠诲姟鍙烽敊璇�,鏈幏鍙栧埌鍗忚淇℃伅,璇锋鏌ラ厤缃弬鏁板悕绉版槸鍚﹂厤缃�,涓旈厤缃负涓簕nameof(CurrentTaskNum)}") : (int)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType);
+            if (devicePro == null)
+                throw new Exception($"璇诲彇褰撳墠浠诲姟鍙烽敊璇�,鏈幏鍙栧埌鍗忚淇℃伅,璇锋鏌ラ厤缃弬鏁板悕绉版槸鍚﹂厤缃�,涓旈厤缃负{nameof(CurrentTaskNum)}");
+
+            object value = Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType);
+            return Convert.ToInt32(value);  // 缁熶竴杞崲涓� int
         }
 
         /// <summary>
@@ -303,11 +315,10 @@
                     {
                         return deviceProtocolDetail.ProtocolDetailType;
                     }
-                    return StackerCraneStatus.Unkonw.ToString();
+                    return StackerCraneStatus.Unknown.ToString();
                 }
             }
-            //todo 閫氳鏈繛鎺ユ椂鎶涘嚭寮傚父
-            return StackerCraneStatus.Unkonw.ToString();
+            return StackerCraneStatus.Unknown.ToString();
         }
 
         private void CheckConnect()
@@ -333,9 +344,11 @@
                 }
             });
         }
+
         #endregion
 
         #region Public Method
+
         /// <summary>
         /// 鍙戦�佷换鍔″懡浠�
         /// </summary>
@@ -378,10 +391,10 @@
                 _isChecked = true;
                 try
                 {
-                    DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(StackerCraneWorkStatus));
+                    DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(StackerCraneCompleted));
                     if (devicePro != null)
                     {
-                        DeviceProtocolDetailDTO? deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePro.DeviceProParamName && x.ProtocolDetailType == StackerCraneWorkStatus.WorkCompleted.ToString());
+                        DeviceProtocolDetailDTO? deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePro.DeviceProParamName && x.ProtocolDetailType == StackerCraneCompleted.Completed.ToString());
                         if (deviceProtocolDetail != null)
                         {
                             OperateResult<TimeSpan> operateResult = new OperateResult<TimeSpan>();
@@ -391,21 +404,27 @@
                                 case TypeCode.Boolean:
                                     operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToBoolean(deviceProtocolDetail.ProtocalDetailValue));
                                     break;
+
                                 case TypeCode.Byte:
                                     operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToByte(deviceProtocolDetail.ProtocalDetailValue));
                                     break;
+
                                 case TypeCode.Int16:
                                     operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToInt16(deviceProtocolDetail.ProtocalDetailValue));
                                     break;
+
                                 case TypeCode.Int32:
                                     operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToInt32(deviceProtocolDetail.ProtocalDetailValue));
                                     break;
+
                                 case TypeCode.UInt16:
                                     operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToUInt16(deviceProtocolDetail.ProtocalDetailValue));
                                     break;
+
                                 case TypeCode.UInt32:
                                     operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToUInt32(deviceProtocolDetail.ProtocalDetailValue));
                                     break;
+
                                 default:
                                     break;
                             }
@@ -421,7 +440,6 @@
                 }
                 catch (Exception ex)
                 {
-
                 }
                 finally
                 {
@@ -450,7 +468,6 @@
         /// </summary>
         public void Heartbeat()
         {
-
         }
 
         /// <summary>
@@ -483,6 +500,7 @@
             // 鍛婅瘔鍨冨溇鍥炴敹鍣ㄤ笉鍐嶈皟鐢ㄦ瀵硅薄鐨勭粓缁撳櫒
             GC.SuppressFinalize(this);
         }
+
         #endregion
     }
-}
+}
\ No newline at end of file

--
Gitblit v1.9.3