Skip to content

Commit

Permalink
Remove duplicate observable, add distinct on isConnected
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman committed Jul 26, 2022
1 parent c0996c1 commit 7ac6c13
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 29 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.0.1",
"version": "1.0.2",
"publicReleaseRefSpec": [
"^refs/heads/master$",
"^refs/heads/main$"
Expand Down
21 changes: 12 additions & 9 deletions src/S7PlcRx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ VisualStudioVersion = 17.2.32630.192
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ProjectConfig", "ProjectConfig", "{62ECE40E-CA31-4602-8670-35BAF2C83672}"
ProjectSection(SolutionItems) = preProject
..\..\.editorconfig = ..\..\.editorconfig
..\..\.gitignore = ..\..\.gitignore
..\..\.github\workflows\BuildOnly.yml = ..\..\.github\workflows\BuildOnly.yml
..\..\.github\dependabot.yml = ..\..\.github\dependabot.yml
..\..\Directory.Build.props = ..\..\Directory.Build.props
..\..\.github\workflows\dotnet.yml = ..\..\.github\workflows\dotnet.yml
..\..\README.md = ..\..\README.md
..\..\stylecop.json = ..\..\stylecop.json
..\..\Version.json = ..\..\Version.json
..\.editorconfig = ..\.editorconfig
..\.gitignore = ..\.gitignore
..\.github\workflows\BuildOnly.yml = ..\.github\workflows\BuildOnly.yml
..\.github\dependabot.yml = ..\.github\dependabot.yml
..\Directory.Build.props = ..\Directory.Build.props
..\.github\workflows\dotnet.yml = ..\.github\workflows\dotnet.yml
..\LICENSE = ..\LICENSE
..\README.md = ..\README.md
..\Images\S7PlcRx.ico = ..\Images\S7PlcRx.ico
..\Images\S7PlcRx.png = ..\Images\S7PlcRx.png
..\stylecop.json = ..\stylecop.json
..\Version.json = ..\Version.json
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "S7PlcRx", "S7PlcRx\S7PlcRx.csproj", "{1F953491-ABF8-4BF3-BEB9-1AE00996DE49}"
Expand Down
2 changes: 1 addition & 1 deletion src/S7PlcRx/Core/S7SocketRx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public S7SocketRx(string ip, CpuType plcType, short rack, short slot)
});

return new SingleAssignmentDisposable { Disposable = tim };
}).Retry().Publish(false).RefCount();
}).Retry().Publish(false).RefCount().DistinctUntilChanged();

/// <summary>
/// Gets the type of the PLC.
Expand Down
8 changes: 0 additions & 8 deletions src/S7PlcRx/IRxS7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ public interface IRxS7 : ICancelable
/// </value>
IObservable<Tag> ObserveAll { get; }

/// <summary>
/// Gets the PLC status.
/// </summary>
/// <value>
/// The PLC status.
/// </value>
IObservable<bool> PLCStatus { get; }

/// <summary>
/// Gets the type of the PLC.
/// </summary>
Expand Down
12 changes: 2 additions & 10 deletions src/S7PlcRx/RxS7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class RxS7 : IRxS7
private readonly ISubject<string> _lastError = new Subject<string>();
private readonly ISubject<ErrorCode> _lastErrorCode = new Subject<ErrorCode>();
private readonly ISubject<PLCRequest> _pLCRequestSubject = new Subject<PLCRequest>();
private readonly ISubject<bool> _pLCstatus = new Subject<bool>();
private readonly ISubject<Unit> _restartReadCycle = new Subject<Unit>();
private readonly ISubject<string> _status = new Subject<string>();
private readonly SemaphoreSlim _lock = new SemaphoreSlim(1);
Expand Down Expand Up @@ -59,7 +58,7 @@ public RxS7(CpuType type, string ip, short rack, short slot, string? watchDogAdd
}

_isConnected = x;
_pLCstatus.OnNext(x);
_status.OnNext($"{DateTime.Now} - PLC Connected Status: {x}");
}));

if (!string.IsNullOrWhiteSpace(watchDogAddress))
Expand Down Expand Up @@ -130,14 +129,6 @@ public RxS7(CpuType type, string ip, short rack, short slot, string? watchDogAdd
/// </value>
public IObservable<ErrorCode> LastErrorCode => _lastErrorCode.AsObservable();

/// <summary>
/// Gets the PLC status.
/// </summary>
/// <value>
/// The PLC status.
/// </value>
public IObservable<bool> PLCStatus => _pLCstatus.AsObservable();

/// <summary>
/// Gets the type of the PLC.
/// </summary>
Expand Down Expand Up @@ -315,6 +306,7 @@ protected virtual void Dispose(bool disposing)
{
if (disposing)
{
_lock.Wait();
_lock.Dispose();
_disposables.Dispose();
_socketRx?.Dispose();
Expand Down

0 comments on commit 7ac6c13

Please sign in to comment.