From 7ff298c6834275b63b612af49651673689a39660 Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期三, 27 十一月 2024 11:33:18 +0800
Subject: [PATCH] 更新

---
 WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ShuttleCar/ShuttleCar.cs |   73 ++++++++++++++++++------------------
 1 files changed, 36 insertions(+), 37 deletions(-)

diff --git a/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ShuttleCar/ShuttleCar.cs b/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ShuttleCar/ShuttleCar.cs
index 5b62d38..73706a4 100644
--- a/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ShuttleCar/ShuttleCar.cs
+++ b/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ShuttleCar/ShuttleCar.cs
@@ -65,11 +65,7 @@
 
         public string DeviceName => _deviceName;
 
-        public bool IsFault => false;
-
         public bool IsConnected => Communicator.IsConnected && _isConnected;
-
-        public DeviceStatus Status => DeviceStatus.Offline;
         #endregion
 
         #region Constructor Function
@@ -111,19 +107,27 @@
         #endregion
 
         #region Public Method
+
+        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($"璇诲彇鏁版嵁閿欒,鏈湪鍗忚淇℃伅閲岄潰鎵惧埌鍙傛暟{value.ToString()}") : (TResult)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType);
+        }
+
         /// <summary>
         /// 璇诲彇PLC鍗忚鍦板潃鐨勬暟鎹�
         /// </summary>
         /// <typeparam name="TEnum">鍗忚淇℃伅鐨勬灇涓惧璞′俊鎭��</typeparam>
-        /// <typeparam name="TRsult">璇诲彇鏁版嵁鐨勭被鍨嬪璞′俊鎭��</typeparam>
+        /// <typeparam name="TResult">璇诲彇鏁版嵁鐨勭被鍨嬪璞′俊鎭��</typeparam>
         /// <param name="value">鏋氫妇鍊�</param>
         /// <param name="deviceChildCode">璁惧瀛愮紪鍙�</param>
         /// <returns>璇诲彇鍒扮殑鏁版嵁</returns>
-        public TRsult GetValue<TEnum, TRsult>(TEnum value, string deviceChildCode) where TEnum : Enum
+        public TResult GetValue<TEnum, TResult>(TEnum value, string deviceChildCode) where TEnum : Enum
         {
             if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁�");
             DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == value.ToString() && x.DeviceChildCode == deviceChildCode);
-            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>
@@ -131,7 +135,6 @@
         /// </summary>
         public void Heartbeat()
         {
-            throw new NotImplementedException();
         }
 
         /// <summary>
@@ -144,38 +147,23 @@
         /// <exception cref="Exception"></exception>
         public bool SendCommand<T>(T command, string deviceChildCode) where T : IDataTransfer, new()
         {
-            if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁�");
-            DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand) && x.DeviceChildCode == deviceChildCode).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) && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+                if (devicePro == null)
+                {
+                    return false;
+                }
+                if (Communicator.WriteCustomer(devicePro.DeviceProAddress, command))
+                {
+                    return true;
+                }
                 return false;
-            }
-            if (Communicator.WriteCustomer(devicePro.DeviceProAddress, command))
-            {
-                return true;
-            }
-            return false;
-        }
-
-        /// <summary>
-        /// 璇诲彇PLC鏁版嵁锛岃繑鍥炶嚜瀹氫箟瀵硅薄
-        /// </summary>
-        /// <typeparam name="T">娉涘瀷</typeparam>
-        /// <param name="deviceChildCode">瀛愯澶囩紪鍙�</param>
-        /// <returns>杩斿洖鑷畾涔夊璞℃垨鎶涘嚭寮傚父</returns>
-        /// <exception cref="Exception"></exception>
-        public T ReadCustomer<T>(string deviceChildCode) where T : IDataTransfer, new()
-        {
-            if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁�");
-            DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == "ReadDeviceCommand" && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
-
-            if (devicePro == null)
-            {
-                throw new Exception("鏈壘鍒板崗璁俊鎭�");
             }
             else
             {
-                return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress);
+                throw new Exception("鏆備笉鏀寔闄よタ闂ㄥ瓙涔嬪鐨凱LC");
             }
         }
 
@@ -194,12 +182,23 @@
         {
             if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁�");
             DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString() && x.DeviceChildCode == deviceChildCode);
-            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);
+        }
+
+        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($"鍐欏叆鏁版嵁閿欒,鏈湪鍗忚淇℃伅閲岄潰鎵惧埌鍙傛暟{value.ToString()}") : Communicator.WriteObj(devicePro.DeviceProAddress, devicePro.DeviceDataType, value);
         }
 
         public void Dispose()
         {
-            throw new NotImplementedException();
+            _heartStatr = false;
+            _communicator.Dispose();
+            GC.SuppressFinalize(this);
         }
         #endregion
     }

--
Gitblit v1.9.3