Exemple #1
0
            static string BuildErrorMessage(MessageType messageType, HeaderErrorClass errorClass, byte errorCode)
            {
                var sb = new StringBuilder("An error was returned during communication:").AppendLine().AppendLine();

                sb.Append("\tMessage type: ").Append(messageType).Append(" / 0x").AppendFormat("{0:X}", messageType).AppendLine();

                sb.Append("\tError class: ");
                if (Enum.IsDefined(typeof(HeaderErrorClass), errorClass))
                {
                    sb.Append(errorClass).Append(" / ");
                }
                sb.Append("0x").AppendFormat("{0:X}", errorClass).AppendLine();

                sb.Append("\tError code: 0x").AppendFormat("{0:X}", errorCode).AppendLine();

                var combinedErrorCode = (ParameterErrorCode)(((int)errorClass << 8) | errorCode);

                sb.Append("\tCombined error: ");
                if (Enum.IsDefined(typeof(ParameterErrorCode), combinedErrorCode))
                {
                    sb.Append(combinedErrorCode).Append(" / ");
                }
                sb.Append("0x").AppendFormat("{0:X}", combinedErrorCode).AppendLine();

                return(sb.ToString());
            }
Exemple #2
0
 internal static void ThrowCommunicationFailure(MessageType messageType, HeaderErrorClass errorClass, byte errorCode)
 {
     throw new S7ProtocolException(BuildErrorMessage(messageType, errorClass, errorCode));