mirror of
https://github.com/evopro-ag/Sharp7Reactive.git
synced 2026-02-04 07:42:53 +00:00
Move GetAdditionalErrorText to S7ErrorCodes
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
namespace Sharp7.Rx;
|
#nullable enable
|
||||||
|
|
||||||
|
namespace Sharp7.Rx;
|
||||||
|
|
||||||
public static class S7ErrorCodes
|
public static class S7ErrorCodes
|
||||||
{
|
{
|
||||||
@@ -12,6 +14,18 @@ public static class S7ErrorCodes
|
|||||||
0x900000, // CPU: Address out of range
|
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>
|
/// <summary>
|
||||||
/// Some error codes indicate connection lost, in which case, the driver tries to reestablish connection.
|
/// 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
|
/// 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);
|
return !notDisconnectedErrorCodes.Contains(errorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string? GetAdditionalErrorText(int errorCode) =>
|
||||||
|
additionalErrorTexts.TryGetValue(errorCode, out var text) ? text : null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,18 +12,6 @@ namespace Sharp7.Rx;
|
|||||||
|
|
||||||
internal class Sharp7Connector : IS7Connector
|
internal class Sharp7Connector : IS7Connector
|
||||||
{
|
{
|
||||||
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.
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private readonly BehaviorSubject<ConnectionState> connectionStateSubject = new(Enums.ConnectionState.Initial);
|
private readonly BehaviorSubject<ConnectionState> connectionStateSubject = new(Enums.ConnectionState.Initial);
|
||||||
private readonly int cpuSlotNr;
|
private readonly int cpuSlotNr;
|
||||||
|
|
||||||
@@ -239,7 +227,8 @@ internal class Sharp7Connector : IS7Connector
|
|||||||
var errorText = EvaluateErrorCode(result);
|
var errorText = EvaluateErrorCode(result);
|
||||||
var completeMessage = $"{message}: {errorText}";
|
var completeMessage = $"{message}: {errorText}";
|
||||||
|
|
||||||
if (additionalErrorTexts.TryGetValue(result, out var additionalErrorText))
|
var additionalErrorText = S7ErrorCodes.GetAdditionalErrorText(result);
|
||||||
|
if (additionalErrorText != null)
|
||||||
completeMessage += Environment.NewLine + additionalErrorText;
|
completeMessage += Environment.NewLine + additionalErrorText;
|
||||||
|
|
||||||
throw new S7CommunicationException(completeMessage, result, errorText);
|
throw new S7CommunicationException(completeMessage, result, errorText);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class Sharp7Plc : IPlc
|
|||||||
private readonly ConcurrentSubjectDictionary<string, byte[]> multiVariableSubscriptions = new(StringComparer.InvariantCultureIgnoreCase);
|
private readonly ConcurrentSubjectDictionary<string, byte[]> multiVariableSubscriptions = new(StringComparer.InvariantCultureIgnoreCase);
|
||||||
private readonly List<long> performanceCoutner = new(1000);
|
private readonly List<long> performanceCoutner = new(1000);
|
||||||
private readonly PlcConnectionSettings plcConnectionSettings;
|
private readonly PlcConnectionSettings plcConnectionSettings;
|
||||||
private readonly IVariableNameParser varaibleNameParser = new CacheVariableNameParser(new VariableNameParser());
|
private readonly CacheVariableNameParser varaibleNameParser = new CacheVariableNameParser(new VariableNameParser());
|
||||||
private bool disposed;
|
private bool disposed;
|
||||||
private Sharp7Connector s7Connector;
|
private Sharp7Connector s7Connector;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user