Skip to content

Commit

Permalink
Merge pull request #45 from ChrisPulman/UpdateWatchdog
Browse files Browse the repository at this point in the history
Update Watchdog
  • Loading branch information
ChrisPulman authored Jan 16, 2024
2 parents 7b8dc35 + 9b33c85 commit 7dbdba3
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.2.5",
"version": "1.3.0",
"publicReleaseRefSpec": [
"^refs/heads/master$",
"^refs/heads/main$"
Expand Down
4 changes: 2 additions & 2 deletions src/S7PlcRx/IRxS7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ public interface IRxS7 : ICancelable
ushort WatchDogValueToWrite { get; set; }

/// <summary>
/// Gets or sets the watch dog writing time. (Sec).
/// Gets the watch dog writing time. (Sec).
/// </summary>
/// <value>The watch dog writing time. (Sec).</value>
int WatchDogWritingTime { get; set; }
int WatchDogWritingTime { get; }

/// <summary>
/// Gets the read time.
Expand Down
30 changes: 17 additions & 13 deletions src/S7PlcRx/RxS7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ public class RxS7 : IRxS7
{
private readonly S7SocketRx _socketRx;
private readonly Subject<Tag?> _dataRead = new();
private readonly CompositeDisposable _disposables = new();
private readonly Subject<string> _lastError = new Subject<string>();
private readonly Subject<ErrorCode> _lastErrorCode = new Subject<ErrorCode>();
private readonly Subject<PLCRequest> _pLCRequestSubject = new Subject<PLCRequest>();
private readonly Subject<string> _status = new Subject<string>();
private readonly Subject<long> _readTime = new Subject<long>();
private readonly CompositeDisposable _disposables = [];
private readonly Subject<string> _lastError = new();
private readonly Subject<ErrorCode> _lastErrorCode = new();
private readonly Subject<PLCRequest> _pLCRequestSubject = new();
private readonly Subject<string> _status = new();
private readonly Subject<long> _readTime = new();
private readonly SemaphoreSlim _lock = new(1);
private readonly SemaphoreSlim _lockTagList = new(1);
private readonly object _socketLock = new();
private readonly Stopwatch _stopwatch = new();
private readonly Subject<bool> _paused = new Subject<bool>();
private readonly Subject<bool> _paused = new();
private bool _pause;

/// <summary>
Expand All @@ -44,7 +44,9 @@ public class RxS7 : IRxS7
/// <param name="slot">The slot.</param>
/// <param name="watchDogAddress">The watch dog address.</param>
/// <param name="interval">The interval to observe on.</param>
public RxS7(CpuType type, string ip, short rack, short slot, string? watchDogAddress = null, double interval = 100)
/// <param name="watchDogValueToWrite">The watch dog value to write.</param>
/// <param name="watchDogInterval">The watch dog interval.</param>
public RxS7(CpuType type, string ip, short rack, short slot, string? watchDogAddress = null, double interval = 100, ushort watchDogValueToWrite = 4500, int watchDogInterval = 10)
{
PLCType = type;
IP = ip;
Expand All @@ -66,6 +68,8 @@ public RxS7(CpuType type, string ip, short rack, short slot, string? watchDogAdd

if (!string.IsNullOrWhiteSpace(watchDogAddress))
{
WatchDogWritingTime = watchDogInterval;
WatchDogValueToWrite = watchDogValueToWrite;
_disposables.Add(WatchDogObservable().Subscribe());
}

Expand Down Expand Up @@ -190,10 +194,10 @@ public RxS7(CpuType type, string ip, short rack, short slot, string? watchDogAdd
public ushort WatchDogValueToWrite { get; set; } = 4500;

/// <summary>
/// Gets or sets the watch dog writing time. (Seconds).
/// Gets the watch dog writing time. (Seconds).
/// </summary>
/// <value>The watch dog writing time. (Seconds).</value>
public int WatchDogWritingTime { get; set; } = 10;
public int WatchDogWritingTime { get; } = 10;

/// <summary>
/// Gets a value indicating whether gets a value that indicates whether the object is disposed.
Expand Down Expand Up @@ -1086,8 +1090,8 @@ private void GetTagValue(Tag? tag)
throw new Exception();
}

mByte = int.Parse(txt2.Substring(0, txt2.IndexOf(".")));
mBit = int.Parse(txt2.Substring(txt2.IndexOf(".") + 1));
mByte = int.Parse(txt2.Substring(0, txt2.IndexOf('.')));
mBit = int.Parse(txt2.Substring(txt2.IndexOf('.') + 1));
if (mBit > 7)
{
throw new Exception();
Expand Down Expand Up @@ -1535,7 +1539,7 @@ private bool WriteString(Tag? tag)
}

addressLocation = tagAddress.Substring(1);
var decimalPointIndex = addressLocation.IndexOf(".");
var decimalPointIndex = addressLocation.IndexOf('.');
if (decimalPointIndex == -1)
{
throw new Exception(string.Format("Cannot parse variable {0}. Input, Output, Memory Address, Timer, and Counter types require bit-level addressing (e.g. I0.1).", addressLocation));
Expand Down
10 changes: 0 additions & 10 deletions src/S7PlcRx/S7Exception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,4 @@ public S7Exception(string message, Exception innerException)
: base(message, innerException)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="S7Exception"/> class.
/// </summary>
/// <param name="serializationInfo">The serialization information.</param>
/// <param name="streamingContext">The streaming context.</param>
protected S7Exception(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext)
: base(serializationInfo, streamingContext)
{
}
}
10 changes: 0 additions & 10 deletions src/S7PlcRx/TagAddressOutOfRangeException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,4 @@ public TagAddressOutOfRangeException(Tag tag, object actualValue, string message
: base(nameof(tag.Address), actualValue, message)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="TagAddressOutOfRangeException"/> class.
/// </summary>
/// <param name="serializationInfo">The serialization information.</param>
/// <param name="streamingContext">The streaming context.</param>
protected TagAddressOutOfRangeException(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext)
: base(serializationInfo, streamingContext)
{
}
}
17 changes: 0 additions & 17 deletions src/S7PlcRx/Tags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections;
using System.Runtime.Serialization;

namespace S7PlcRx;

Expand All @@ -20,22 +19,6 @@ public Tags()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="Tags"/> class.
/// </summary>
/// <param name="info">
/// A <see cref="SerializationInfo"/> object containing the
/// information required to serialize the <see cref="Hashtable"/> object.
/// </param>
/// <param name="context">
/// A <see cref="StreamingContext"/> object containing the
/// source and destination of the serialized stream associated with the <see cref="Hashtable"/>.
/// </param>
protected Tags(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}

/// <summary>
/// Gets or sets the <see cref="object"/> with the specified key.
/// </summary>
Expand Down

0 comments on commit 7dbdba3

Please sign in to comment.