| | |
| | | } |
| | | else |
| | | { |
| | | //return true; |
| | | return true; |
| | | object? obj = null; |
| | | for (int i = 0; i < 5; i++) |
| | | { |
| | |
| | | { |
| | | OperateResult operateResult = plc.WriteCustomer(address, value); |
| | | stringBuilder.AppendLine(string.Format(CommunicationInfoMessage.WriteData, address, JsonConvert.SerializeObject(value))); |
| | | #region |
| | | if (operateResult.IsSuccess) |
| | | { |
| | | object? obj = null; |
| | | for (int i = 0; i < 5; i++) |
| | | { |
| | | T readValue = ReadCustomer<T>(address); |
| | | stringBuilder.AppendLine(string.Format(CommunicationInfoMessage.WriteAfterRead, address, JsonConvert.SerializeObject(readValue))); |
| | | obj = readValue; |
| | | PropertyInfo[] propertyInfos = typeof(T).GetProperties(); |
| | | for (int j = 0; j < propertyInfos.Length; j++) |
| | | { |
| | | object? writeValueItem = propertyInfos[j].GetValue(value); |
| | | object? readValueItem = propertyInfos[j].GetValue(readValue); |
| | | if (writeValueItem.Equals(readValueItem)) |
| | | { |
| | | stringBuilder.AppendLine(string.Format(CommunicationInfoMessage.WriteAndReadCheckSuccess, address, JsonConvert.SerializeObject(value), JsonConvert.SerializeObject(readValue))); |
| | | } |
| | | else |
| | | { |
| | | break; |
| | | } |
| | | if (j == propertyInfos.Length - 1) |
| | | return true; |
| | | } |
| | | plc.WriteCustomer(address, value); |
| | | } |
| | | stringBuilder.AppendLine(string.Format(CommunicationExceptionMessage.WriteAndReadCheckFaild, address, JsonConvert.SerializeObject(value), JsonConvert.SerializeObject(obj))); |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.WriteAndReadCheckFaild, address, JsonConvert.SerializeObject(value), JsonConvert.SerializeObject(obj)), CommunicationErrorType.WriteFailed); |
| | | //object? obj = null; |
| | | //for (int i = 0; i < 5; i++) |
| | | //{ |
| | | // T readValue = ReadCustomer<T>(address); |
| | | // stringBuilder.AppendLine(string.Format(CommunicationInfoMessage.WriteAfterRead, address, JsonConvert.SerializeObject(readValue))); |
| | | // obj = readValue; |
| | | // PropertyInfo[] propertyInfos = typeof(T).GetProperties(); |
| | | // for (int j = 0; j < propertyInfos.Length; j++) |
| | | // { |
| | | // object? writeValueItem = propertyInfos[j].GetValue(value); |
| | | // object? readValueItem = propertyInfos[j].GetValue(readValue); |
| | | // if (writeValueItem.Equals(readValueItem)) |
| | | // { |
| | | // stringBuilder.AppendLine(string.Format(CommunicationInfoMessage.WriteAndReadCheckSuccess, address, JsonConvert.SerializeObject(value), JsonConvert.SerializeObject(readValue))); |
| | | // } |
| | | // else |
| | | // { |
| | | // break; |
| | | // } |
| | | // if (j == propertyInfos.Length - 1) |
| | | // return true; |
| | | // } |
| | | // plc.WriteCustomer(address, value); |
| | | //} |
| | | //stringBuilder.AppendLine(string.Format(CommunicationExceptionMessage.WriteAndReadCheckFaild, address, JsonConvert.SerializeObject(value), JsonConvert.SerializeObject(obj))); |
| | | //throw new CommunicationException(string.Format(CommunicationExceptionMessage.WriteAndReadCheckFaild, address, JsonConvert.SerializeObject(value), JsonConvert.SerializeObject(obj)), CommunicationErrorType.WriteFailed); |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.WriteFailedException, typeof(T).Name, address, JsonConvert.SerializeObject(value), operateResult.Message), CommunicationErrorType.WriteFailed); |
| | | } |
| | | #endregion |
| | | } |
| | | catch (Exception ex) |
| | | { |