diff --git a/Sharp7.Rx/Basics/LimitedConcurrencyLevelTaskScheduler.cs b/Sharp7.Rx/Basics/LimitedConcurrencyLevelTaskScheduler.cs index 98c24c6..56ca27b 100644 --- a/Sharp7.Rx/Basics/LimitedConcurrencyLevelTaskScheduler.cs +++ b/Sharp7.Rx/Basics/LimitedConcurrencyLevelTaskScheduler.cs @@ -26,7 +26,7 @@ internal class LimitedConcurrencyLevelTaskScheduler : TaskScheduler /// The maximum degree of parallelism provided by this scheduler. public LimitedConcurrencyLevelTaskScheduler(int maxDegreeOfParallelism) { - if (maxDegreeOfParallelism < 1) throw new ArgumentOutOfRangeException("maxDegreeOfParallelism"); + if (maxDegreeOfParallelism < 1) throw new ArgumentOutOfRangeException(nameof(maxDegreeOfParallelism)); this.maxDegreeOfParallelism = maxDegreeOfParallelism; } diff --git a/Sharp7.Rx/S7ErrorCodes.cs b/Sharp7.Rx/S7ErrorCodes.cs index 5e54922..7734149 100644 --- a/Sharp7.Rx/S7ErrorCodes.cs +++ b/Sharp7.Rx/S7ErrorCodes.cs @@ -1,5 +1,7 @@ #nullable enable +using System.Diagnostics.CodeAnalysis; + namespace Sharp7.Rx; public static class S7ErrorCodes @@ -7,12 +9,12 @@ public static class S7ErrorCodes /// /// This list is not exhaustive and should be considered work in progress. /// - private static readonly HashSet notDisconnectedErrorCodes = new HashSet - { + private static readonly HashSet notDisconnectedErrorCodes = + [ 0x000000, // OK 0xC00000, // CPU: Item not available - 0x900000, // CPU: Address out of range - }; + 0x900000 // CPU: Address out of range + ]; private static readonly IReadOnlyDictionary additionalErrorTexts = new Dictionary { @@ -31,11 +33,9 @@ public static class S7ErrorCodes /// Other error codes indicate a user error, like reading from an unavailable DB or exceeding /// the DBs range. In this case the driver should not consider the connection to be lost. /// - public static bool AssumeConnectionLost(int errorCode) - { - return !notDisconnectedErrorCodes.Contains(errorCode); - } + public static bool AssumeConnectionLost(int errorCode) => + !notDisconnectedErrorCodes.Contains(errorCode); public static string? GetAdditionalErrorText(int errorCode) => - additionalErrorTexts.TryGetValue(errorCode, out var text) ? text : null; + additionalErrorTexts.GetValueOrDefault(errorCode); } diff --git a/Sharp7.Rx/Sharp7.Rx.csproj b/Sharp7.Rx/Sharp7.Rx.csproj index 196f263..210e8d5 100644 --- a/Sharp7.Rx/Sharp7.Rx.csproj +++ b/Sharp7.Rx/Sharp7.Rx.csproj @@ -18,6 +18,13 @@ Apache-2.0 true snupkg + + + $(NoWarn);CA1848;CA2254;CA1859 diff --git a/Sharp7.Rx/Sharp7Connector.cs b/Sharp7.Rx/Sharp7Connector.cs index cf95ab4..d04af97 100644 --- a/Sharp7.Rx/Sharp7Connector.cs +++ b/Sharp7.Rx/Sharp7Connector.cs @@ -98,7 +98,9 @@ internal class Sharp7Connector : IS7Connector .Select(x => { var buffer = new byte[x.Address.BufferLength]; +#pragma warning disable CS0618 // Type or member is obsolete, no matching overload. s7MultiVar.Add(S7Consts.S7AreaDB, S7Consts.S7WLByte, x.Address.DbNo, x.Address.Start, x.Address.BufferLength, ref buffer); +#pragma warning restore CS0618 return new {x.VariableName, Buffer = buffer}; }) .ToArray(); diff --git a/Sharp7.Rx/Sharp7Plc.cs b/Sharp7.Rx/Sharp7Plc.cs index 3727bc9..a9e7c62 100644 --- a/Sharp7.Rx/Sharp7Plc.cs +++ b/Sharp7.Rx/Sharp7Plc.cs @@ -230,8 +230,9 @@ public class Sharp7Plc : IPlc var min = performanceCounter.Min(); var max = performanceCounter.Max(); - Logger?.LogTrace("Performance statistic during {0} elements of plc notification. Min: {1}, Max: {2}, Average: {3}, Plc: '{4}', Number of variables: {5}, Batch size: {6}", - performanceCounter.Capacity, min, max, average, plcConnectionSettings.IpAddress, + Logger?.LogTrace("PLC {Plc} notification perf: {Elements} calls, min {Min}, max {Max}, avg {Avg}, variables {Vars}, batch size {BatchSize}", + plcConnectionSettings.IpAddress, + performanceCounter.Capacity, min, max, average, multiVariableSubscriptions.ExistingKeys.Count(), MultiVarRequestMaxItems); performanceCounter.Clear(); diff --git a/Sharp7.Rx/VariableNameParser.cs b/Sharp7.Rx/VariableNameParser.cs index 734c33e..7191a48 100644 --- a/Sharp7.Rx/VariableNameParser.cs +++ b/Sharp7.Rx/VariableNameParser.cs @@ -48,8 +48,7 @@ internal class VariableNameParser : IVariableNameParser public VariableAddress Parse(string input) { - if (input == null) - throw new ArgumentNullException(nameof(input)); + ArgumentNullException.ThrowIfNull(input); var match = regex.Match(input); if (!match.Success)