From 8c6fd742db249ad4cc819cf041eb98d880a3ef73 Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期四, 02 一月 2025 15:09:07 +0800
Subject: [PATCH] 1

---
 WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Spec/SpeStackerCrane.cs |  138 ++++++++++++++++++++-------------------------
 1 files changed, 62 insertions(+), 76 deletions(-)

diff --git a/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Spec/SpeStackerCrane.cs b/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Spec/SpeStackerCrane.cs
index 6038eca..6d19535 100644
--- a/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Spec/SpeStackerCrane.cs
+++ b/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Spec/SpeStackerCrane.cs
@@ -54,33 +54,54 @@
         #endregion Private Member
 
         #region Public Member
+        /// <summary>
+        /// 閫氳瀵硅薄
+        /// </summary>
         public BaseCommunicator Communicator => _communicator;
 
+        /// <summary>
+        /// 閫氳鍗忚淇℃伅
+        /// </summary>
         public List<DeviceProDTO> DeviceProDTOs => _deviceProDTOs;
 
+        /// <summary>
+        /// 閫氳鍗忚鏄庣粏淇℃伅
+        /// </summary>
         public List<DeviceProtocolDetailDTO> DeviceProtocolDetailDTOs => _deviceProtocolDetailDTOs;
 
+        /// <summary>
+        /// 涓婁竴娆℃墽琛岀殑浠诲姟鍙�
+        /// </summary>
         public int LastTaskNum => _lastTaskNum;
 
+        /// <summary>
+        /// 褰撳墠姝e湪鎵ц鐨勪换鍔″彿
+        /// </summary>
         public int CurrentTaskNum => GetCurrentTaskNum();
 
+        /// <summary>
+        /// 涓婁竴娆℃墽琛岀殑浠诲姟绫诲瀷
+        /// </summary>
         public int? LastTaskType { get; set; } = null;
 
+        /// <summary>
+        /// 璁惧缂栧彿
+        /// </summary>
         public string DeviceCode => _deviceCode;
 
+        /// <summary>
+        /// 璁惧鍚嶇О
+        /// </summary>
         public string DeviceName => _deviceName;
 
-        public bool IsFault => throw new NotImplementedException();
-
+        /// <summary>
+        /// 璁惧鏄惁宸茶繛鎺�
+        /// </summary>
         public bool IsConnected => Communicator.IsConnected && _isConnected;
 
-        public DeviceStatus Status => throw new NotImplementedException();
-
         /// <summary>
-        /// 鏃犵敤
+        /// 鍫嗗灈鏈轰换鍔″懡浠�
         /// </summary>
-        public event EventHandler<StackerCraneTaskCompletedEventArgs> StackerCraneTaskCompletedEventHandler;
-
         public object StackerCraneTaskCommand { get; set; }
         #endregion
 
@@ -134,7 +155,7 @@
         private int GetCurrentTaskNum()
         {
             DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(CurrentTaskNum));
-            return devicePro == null ? throw new Exception() : (int)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType);
+            return devicePro == null ? throw new Exception($"璇诲彇褰撳墠浠诲姟鍙烽敊璇�,鏈幏鍙栧埌鍗忚淇℃伅,璇锋鏌ラ厤缃弬鏁板悕绉版槸鍚﹂厤缃�,涓旈厤缃负{nameof(CurrentTaskNum)}") : (int)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType);
         }
 
         private void CheckConnect()
@@ -163,12 +184,17 @@
         #endregion
 
         #region Public Method
-        public T GetStackerCraneStatus<T>()
-        where T : notnull, Enum
+        /// <summary>
+        /// 鑾峰彇鍫嗗灈鏈虹姸鎬�
+        /// </summary>
+        public T GetStackerCraneStatus<T>() where T : notnull, Enum
         {
             return (T)GetStatus(typeof(T).Name);
         }
 
+        /// <summary>
+        /// 閲婃斁瀵硅薄
+        /// </summary>
         public void Dispose()
         {
             _heartStatr = false;
@@ -176,18 +202,34 @@
             GC.SuppressFinalize(this);
         }
 
-        public TRsult GetValue<TEnum, TRsult>(TEnum value) where TEnum : Enum
+        /// <summary>
+        /// 鏍规嵁鍙傛暟鍚嶇О璇诲彇鍫嗗灈鏈哄搴旂殑鏁版嵁銆�
+        /// </summary>
+        /// <typeparam name="TEnum">鍙傛暟鍚嶇О鏋氫妇绫诲瀷銆�</typeparam>
+        /// <typeparam name="TResult">璇诲彇缁撴灉鐨勮繑鍥炲�肩被鍨嬨��</typeparam>
+        /// <param name="value">鍙傛暟鍚嶇О銆�</param>
+        /// <returns>杩斿洖璇诲彇鍒扮殑鏁版嵁銆�</returns>
+        /// <exception cref="Exception"></exception>
+        public TResult GetValue<TEnum, TResult>(TEnum value) where TEnum : Enum
         {
             if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁�");
             DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == value.ToString());
-            return devicePro == null ? throw new Exception() : (TRsult)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType);
+            return devicePro == null ? throw new Exception($"璇诲彇鏁版嵁閿欒,鏈湪鍗忚淇℃伅閲岄潰鎵惧埌鍙傛暟{value.ToString()}") : (TResult)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType);
         }
 
+        /// <summary>
+        /// 蹇冭烦
+        /// </summary>
         public void Heartbeat()
         {
 
         }
 
+        /// <summary>
+        /// 鍙戦�佷换鍔″懡浠�
+        /// </summary>
+        /// <param name="command">浠诲姟鍛戒护</param>
+        /// <returns></returns>
         public bool SendCommand<T>(T command) where T : IDataTransfer, new()
         {
             if (Communicator is SiemensS7)
@@ -213,77 +255,21 @@
         }
 
         /// <summary>
-        /// 鐩戞祴鍫嗗灈鏈轰换鍔℃槸鍚﹀畬鎴�(闃叉浠诲姟瀹屾垚浜嬩欢鐩戞祴瓒呮椂锛屽畾涔夋墜鍔ㄨЕ鍙戝姛鑳�)
+        /// 鏍规嵁鍙傛暟鍚嶇О鍐欏叆鍫嗗灈鏈哄搴旂殑鏁版嵁銆�
         /// </summary>
-        void CheckStackerCraneTaskCompleted()
-        {
-            if (_isChecked)
-                return;
-
-            Task.Run(() =>
-            {
-                _isChecked = true;
-                try
-                {
-                    DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(StackerCraneWorkStatus));
-                    if (devicePro != null)
-                    {
-                        DeviceProtocolDetailDTO? deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePro.DeviceProParamName && x.ProtocolDetailType == StackerCraneWorkStatus.WorkCompleted.ToString());
-                        if (deviceProtocolDetail != null)
-                        {
-                            OperateResult<TimeSpan> operateResult = new OperateResult<TimeSpan>();
-                            TypeCode typeCode = SiemensDBDataType.GetTypeCode(devicePro.DeviceDataType);
-                            switch (typeCode)
-                            {
-                                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;
-                            }
-                            int taskNum = CurrentTaskNum;
-                            if (operateResult.IsSuccess /*&& LastTaskNum != taskNum*/)
-                            {
-                                StackerCraneTaskCompletedEventArgs args = new(taskNum);
-                                StackerCraneTaskCompletedEventHandler?.Invoke(this, args);
-                                _lastTaskNum = taskNum;
-                            }
-                        }
-                    }
-                }
-                catch (Exception ex)
-                {
-
-                }
-                finally
-                {
-                    _isChecked = false;
-                }
-            });
-        }
-
+        /// <typeparam name="TEnum">鍙傛暟鍚嶇О鏋氫妇绫诲瀷銆�</typeparam>
+        /// <typeparam name="TValue">瑕佸啓鍏ョ殑鏁版嵁绫诲瀷銆�</typeparam>
+        /// <param name="enum">鍙傛暟鍚嶇О銆�</param>
+        /// <param name="value">瑕佸啓鍏ョ殑鏁版嵁銆�</param>
+        /// <returns>杩斿洖鍐欏叆鎴愬姛鎴栧け璐�</returns>
+        /// <exception cref="Exception"></exception>
         public bool SetValue<TEnum, TValue>(TEnum @enum, TValue value)
             where TEnum : Enum
             where TValue : notnull
         {
             if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁�");
             DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString());
-            return devicePro == null ? throw new Exception() : Communicator.WriteObj(devicePro.DeviceProAddress, devicePro.DeviceDataType, value);
+            return devicePro == null ? throw new Exception($"鍐欏叆鏁版嵁閿欒,鏈湪鍗忚淇℃伅閲岄潰鎵惧埌鍙傛暟{value.ToString()}") : Communicator.WriteObj(devicePro.DeviceProAddress, devicePro.DeviceDataType, value);
         }
         #endregion
     }

--
Gitblit v1.9.3