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 | 34 +++++++++++++--------------------- 1 files changed, 13 insertions(+), 21 deletions(-) diff --git a/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs b/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs index 55dde71..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,7 +340,7 @@ /// <returns></returns> public bool SendCommand<T>(T command) where T : IDataTransfer, new() { - if(Communicator is SiemensS7) + if (Communicator is SiemensS7) { if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁�"); DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); @@ -443,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> @@ -476,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