Move GetAdditionalErrorText to S7ErrorCodes

This commit is contained in:
Peter Butzhammer
2024-02-09 12:38:16 +01:00
parent 4701a224a7
commit 996706df2f
3 changed files with 21 additions and 15 deletions

View File

@@ -1,4 +1,6 @@
namespace Sharp7.Rx;
#nullable enable
namespace Sharp7.Rx;
public static class S7ErrorCodes
{
@@ -12,6 +14,18 @@ public static class S7ErrorCodes
0x900000, // CPU: Address out of range
};
private static readonly IReadOnlyDictionary<int, string> additionalErrorTexts = new Dictionary<int, string>
{
{0xC00000, "This happens when the DB does not exist."},
{0x900000, "This happens when the DB is not long enough."},
{
0x40000, """
This error occurs when the DB is "optimized" or "PUT/GET communication" is not enabled.
See https://snap7.sourceforge.net/snap7_client.html#target_compatibility.
"""
}
};
/// <summary>
/// Some error codes indicate connection lost, in which case, the driver tries to reestablish connection.
/// Other error codes indicate a user error, like reading from an unavailable DB or exceeding
@@ -21,4 +35,7 @@ public static class S7ErrorCodes
{
return !notDisconnectedErrorCodes.Contains(errorCode);
}
public static string? GetAdditionalErrorText(int errorCode) =>
additionalErrorTexts.TryGetValue(errorCode, out var text) ? text : null;
}