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/Common/CommonStackerCrane.cs |   55 +++++++++++++++++++++++++++----------------------------
 1 files changed, 27 insertions(+), 28 deletions(-)

diff --git a/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs b/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs
index c1f1ae4..04e16dc 100644
--- a/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs
+++ b/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs
@@ -17,7 +17,6 @@
 
 using HslCommunication;
 using Microsoft.AspNetCore.Http;
-using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -170,6 +169,7 @@
         public bool IsEventSubscribed => StackerCraneTaskCompletedEventHandler != null;
 
         public int? LastTaskType { get; set; } = null;
+
         #endregion
 
         #region Constructor Function
@@ -225,7 +225,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);
         }
 
         /// <summary>
@@ -294,7 +294,6 @@
                 for (int i = 0; i < devicePros.Count; i++)
                 {
                     object readStatus = Communicator.ReadAsObj(devicePros[i].DeviceProAddress, devicePros[i].DeviceDataType);
-                    //todo 鍗忚鏄庣粏淇℃伅鏈幏鍙栧埌鏃舵姏鍑哄紓甯�
                     DeviceProtocolDetailDTO? deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePros[i].DeviceProParamName) ?? throw new Exception();
                     deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePros[i].DeviceProParamType && x.ProtocalDetailValue.Equals(readStatus.ToString()));
                     if (deviceProtocolDetail != null)
@@ -306,17 +305,6 @@
             }
             //todo 閫氳鏈繛鎺ユ椂鎶涘嚭寮傚父
             return StackerCraneStatus.Unkonw.ToString();
-        }
-
-        /// <summary>
-        /// 姣旇緝涓や釜鍊兼槸鍚︾浉绛夈��
-        /// </summary>
-        /// <param name="value">绗竴涓�笺��</param>
-        /// <param name="paramValue">绗簩涓�笺��</param>
-        /// <returns>杩斿洖姣旇緝缁撴灉銆�</returns>
-        private bool Compare(object value, object paramValue)
-        {
-            return value.Equals(paramValue);
         }
 
         private void CheckConnect()
@@ -352,19 +340,26 @@
         /// <returns></returns>
         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>
@@ -436,15 +431,15 @@
         /// 鏍规嵁鍙傛暟鍚嶇О璇诲彇鍫嗗灈鏈哄搴旂殑鏁版嵁銆�
         /// </summary>
         /// <typeparam name="TEnum">鍙傛暟鍚嶇О鏋氫妇绫诲瀷銆�</typeparam>
-        /// <typeparam name="TRsult">璇诲彇缁撴灉鐨勮繑鍥炲�肩被鍨嬨��</typeparam>
+        /// <typeparam name="TResult">璇诲彇缁撴灉鐨勮繑鍥炲�肩被鍨嬨��</typeparam>
         /// <param name="value">鍙傛暟鍚嶇О銆�</param>
         /// <returns>杩斿洖璇诲彇鍒扮殑鏁版嵁銆�</returns>
         /// <exception cref="Exception"></exception>
-        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);
+            DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == value.ToString()) ?? throw new Exception($"璇诲彇鏁版嵁閿欒,鏈湪鍗忚淇℃伅閲岄潰鎵惧埌鍙傛暟{value.ToString()}");
+            return (TResult)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType);
         }
 
         /// <summary>
@@ -469,14 +464,18 @@
             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);
+            DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString()) ?? throw new Exception($"鍐欏叆鏁版嵁閿欒,鏈湪鍗忚淇℃伅閲岄潰鎵惧埌鍙傛暟{value.ToString()}");
+            return Communicator.WriteObj(devicePro.DeviceProAddress, devicePro.DeviceDataType, value);
         }
 
+        // 瀹炵幇IDisposable鎺ュ彛鐨凞ispose鏂规硶
         public void Dispose()
         {
+            // 灏哶heartStatr璁剧疆涓篺alse
             _heartStatr = false;
+            // 璋冪敤_communicator鐨凞ispose鏂规硶
             _communicator.Dispose();
+            // 鍛婅瘔鍨冨溇鍥炴敹鍣ㄤ笉鍐嶈皟鐢ㄦ瀵硅薄鐨勭粓缁撳櫒
             GC.SuppressFinalize(this);
         }
         #endregion

--
Gitblit v1.9.3