From 2f75b4c0a67ccc3a443e7cc4f2f0f909defd9a92 Mon Sep 17 00:00:00 2001 From: hutongqing <hutongqing@hnkhzn.com> Date: 星期五, 01 十一月 2024 09:49:23 +0800 Subject: [PATCH] 版本更新 --- WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ShuttleCar/ShuttleCar.cs | 65 ++++++++++++++++---------------- 1 files changed, 32 insertions(+), 33 deletions(-) diff --git a/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ShuttleCar/ShuttleCar.cs b/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ShuttleCar/ShuttleCar.cs index 5b62d38..b9c30a1 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,6 +107,14 @@ #endregion #region Public Method + + public TRsult GetValue<TEnum, TRsult>(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); + } + /// <summary> /// 璇诲彇PLC鍗忚鍦板潃鐨勬暟鎹� /// </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"); } } @@ -197,9 +185,20 @@ return devicePro == null ? throw new Exception() : 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() : 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