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/ConveyorLine/CommonConveyorLine.cs | 39 ++++++++++++++++++++------------------- 1 files changed, 20 insertions(+), 19 deletions(-) diff --git a/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine.cs b/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine.cs index 7aa2adf..e3d5c36 100644 --- a/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine.cs +++ b/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine.cs @@ -91,19 +91,10 @@ public string DeviceName => _deviceName; /// <summary> - /// 鏄惁鏈夋晠闅� - /// </summary> - public bool IsFault => false; - - /// <summary> /// 閫氳鏄惁宸茶繛鎺� /// </summary> public bool IsConnected => Communicator.IsConnected && _isConnected; - /// <summary> - /// 璁惧鐘舵�� - /// </summary> - public DeviceStatus Status => DeviceStatus.Offline; #endregion #region Constructor Function @@ -157,15 +148,15 @@ /// 璇诲彇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> @@ -186,17 +177,24 @@ /// <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)) + else { - return true; + throw new Exception("鏆備笉鏀寔闄よタ闂ㄥ瓙涔嬪鐨凱LC"); } - return false; } /// <summary> @@ -236,7 +234,7 @@ { 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); } /// <summary> @@ -274,8 +272,11 @@ public void Dispose() { + // 璁剧疆蹇冭烦鐘舵�佷负false _heartStatr = false; + // 閲婃斁閫氫俊鍣ㄨ祫婧� _communicator.Dispose(); + // 鍛婅瘔鍨冨溇鍥炴敹鍣ㄤ笉鍐嶈皟鐢ㄧ粓缁撳櫒 GC.SuppressFinalize(this); } #endregion -- Gitblit v1.9.3