From 70233af5426b0d1c343ebe87183303a34a9aaa58 Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期三, 20 十一月 2024 09:05:38 +0800
Subject: [PATCH] WIDESEAWCS_QuartzJob更新版本

---
 WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Spec/SpeStackerCrane.cs |  113 ++++++++++----------------------------------------------
 1 files changed, 21 insertions(+), 92 deletions(-)

diff --git a/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Spec/SpeStackerCrane.cs b/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Spec/SpeStackerCrane.cs
index 114795a..e2d0ed2 100644
--- a/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Spec/SpeStackerCrane.cs
+++ b/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Spec/SpeStackerCrane.cs
@@ -17,10 +17,7 @@
     /// <summary>
     /// 鑷畾涔夊爢鍨涙満
     /// </summary>
-    /// <typeparam name="T1">鍫嗗灈鏈虹姸鎬�1娉涘瀷</typeparam>
-    /// <typeparam name="T2">鍫嗗灈鏈虹姸鎬�2娉涘瀷</typeparam>
-    /// <typeparam name="T3">鍫嗗灈鏈虹姸鎬�3娉涘瀷</typeparam>
-    [Description("鍫嗗灈鏈�")]
+    [Description("鍫嗗灈鏈�2")]
     public class SpeStackerCrane : IStackerCrane
     {
         #region Private Member
@@ -73,16 +70,7 @@
 
         public string DeviceName => _deviceName;
 
-        public bool IsFault => throw new NotImplementedException();
-
         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
@@ -137,7 +125,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()
@@ -166,8 +154,7 @@
         #endregion
 
         #region Public Method
-        public T GetStackerCraneStatus<T>()
-        where T : notnull, Enum
+        public T GetStackerCraneStatus<T>() where T : notnull, Enum
         {
             return (T)GetStatus(typeof(T).Name);
         }
@@ -179,11 +166,11 @@
             GC.SuppressFinalize(this);
         }
 
-        public TRsult GetValue<TEnum, TRsult>(TEnum value) where TEnum : Enum
+        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);
         }
 
         public void Heartbeat()
@@ -193,84 +180,26 @@
 
         public bool SendCommand<T>(T command) where T : IDataTransfer, new()
         {
-            if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁�");
-            DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
-            if (devicePro == null)
+            if (Communicator is SiemensS7)
             {
+                if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁�");
+                DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+                if (devicePro == null)
+                {
+                    return false;
+                }
+                if (Communicator.WriteCustomer(devicePro.DeviceProAddress, command))
+                {
+                    StackerCraneTaskCommand = command;
+                    //CheckStackerCraneTaskCompleted();
+                    return true;
+                }
                 return false;
             }
-            if (Communicator.WriteCustomer(devicePro.DeviceProAddress, command))
+            else
             {
-                StackerCraneTaskCommand = command;
-                //CheckStackerCraneTaskCompleted();
-                return true;
+                throw new Exception("鏆備笉鏀寔闄よタ闂ㄥ瓙涔嬪鐨凱LC");
             }
-            return false;
-        }
-
-        /// <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;
-                }
-            });
         }
 
         public bool SetValue<TEnum, TValue>(TEnum @enum, TValue value)
@@ -279,7 +208,7 @@
         {
             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