From 74d6e3882b7d20291ad566b2d5703d0e703f5d27 Mon Sep 17 00:00:00 2001 From: hutongqing <hutongqing@hnkhzn.com> Date: 星期三, 21 八月 2024 17:33:20 +0800 Subject: [PATCH] 1 --- WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs | 27 ++++++++++++++++++++------- 1 files changed, 20 insertions(+), 7 deletions(-) diff --git a/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs b/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs index 4fe7441..a96406a 100644 --- a/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs +++ b/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs @@ -137,8 +137,10 @@ /// <exception cref="CommunicationException"></exception> private bool GetResult<T>(OperateResult operateResult, string address, T value) where T : notnull { + string logMsg = ""; try { + logMsg += $"銆恵Name}銆慞LC鍐欏叆鏁版嵁锛屽湴鍧�锛氥�恵address}銆戯紝鍐欏叆鐨勬暟鎹細銆恵value}銆憑Environment.NewLine}"; if (!operateResult.IsSuccess) { throw new CommunicationException(string.Format(CommunicationExceptionMessage.WriteFailedException, typeof(T).Name, address, value, operateResult.Message), CommunicationErrorType.WriteFailed); @@ -149,25 +151,30 @@ for (int i = 0; i < 5; i++) { T readValue = Read<T>(address); + logMsg += $"銆恵Name}銆慞LC鍐欏叆鍚庤鍙栨暟鎹紝鍦板潃锛氥�恵address}銆戯紝璇诲彇鐨勬暟鎹細銆恵value}銆憑Environment.NewLine}"; obj = readValue; if (readValue.Equals(value)) { + logMsg += $"銆恵Name}銆慞LC鍐欏叆鍚庤鍙栨暟鎹牎楠屾垚鍔燂紝鍦板潃锛氥�恵address}銆戯紝璇诲彇鐨勬暟鎹細銆恵value}銆戯紝鍐欏叆鐨勬暟鎹細銆恵value}銆憑Environment.NewLine}"; return true; } - else + else if(i < 4) { Write(address, value); } } + + logMsg += $"銆恵Name}銆慞LC鍐欏叆鍚庤鍙栨暟鎹牎楠屽け璐ワ紝鍦板潃锛氥�恵address}銆戯紝璇诲彇鐨勬暟鎹細銆恵value}銆戯紝鍐欏叆鐨勬暟鎹細銆恵value}銆憑Environment.NewLine}"; + throw new CommunicationException(string.Format(CommunicationExceptionMessage.ReadWriteDifferentException, typeof(T).Name, address, value, obj), CommunicationErrorType.WriteFailed); } } - catch(Exception ex) + catch (Exception ex) { LogNet.WriteException(Name, $"銆恵Name}銆慞LC鍐欏叆寮傚父锛屽湴鍧�锛氥�恵address}銆戯紝鍐欏叆鐨勬暟鎹細銆恵value}銆戯紝閿欒淇℃伅锛氥�恵ex.Message}銆�", ex); throw new CommunicationException(ex.Message, CommunicationErrorType.WriteFailed, innerException: ex); } - + } /// <summary> @@ -206,6 +213,8 @@ default: throw new CommunicationException(string.Format(CommunicationExceptionMessage.DataTypeErrorException, type.Name, address), CommunicationErrorType.TypeError); } + + } catch (CommunicationException ex) { @@ -215,6 +224,10 @@ { //璇诲彇寮傚父鏃舵姏鍑鸿嚜瀹氫箟閫氳寮傚父绫� throw new CommunicationException($"鍐欏叆鏁版嵁寮傚父,閿欒淇℃伅:{ex.Message}", CommunicationErrorType.TypeError, innerException: ex); + } + finally + { + } } @@ -634,12 +647,12 @@ { return plc.ReadCustomer<T>(address).Content; } - catch(Exception ex) + catch (Exception ex) { LogNet.WriteException(Name, $"銆恵Name}銆慞LC璇诲彇寮傚父锛屽湴鍧�锛氥�恵address}銆戯紝閿欒淇℃伅锛氥�恵ex.Message}銆�", ex); throw new CommunicationException(ex.Message, CommunicationErrorType.ReadException, innerException: ex); } - + } #endregion @@ -680,12 +693,12 @@ } return operateResult.IsSuccess; } - catch(Exception ex) + catch (Exception ex) { LogNet.WriteException(Name, $"銆恵Name}銆慞LC鍐欏叆寮傚父锛屽湴鍧�锛氥�恵address}銆戯紝鍐欏叆鐨勬暟鎹細銆恵JsonConvert.SerializeObject(value)}銆戯紝閿欒淇℃伅锛氥�恵ex.Message}銆�", ex); throw new CommunicationException(ex.Message, CommunicationErrorType.WriteFailed, innerException: ex); } - + } #endregion -- Gitblit v1.9.3