From 3c39996f5ef6a6de0ade93019878de9b8d4d6f4c Mon Sep 17 00:00:00 2001 From: Peter Butzhammer Date: Wed, 7 Feb 2024 13:33:50 +0100 Subject: [PATCH] Make CreateNotification for nonexistent variable fail with Exception --- Sharp7.Rx/Sharp7Plc.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sharp7.Rx/Sharp7Plc.cs b/Sharp7.Rx/Sharp7Plc.cs index 974619d..0265a80 100644 --- a/Sharp7.Rx/Sharp7Plc.cs +++ b/Sharp7.Rx/Sharp7Plc.cs @@ -85,8 +85,14 @@ public class Sharp7Plc : IPlc var disposeableContainer = multiVariableSubscriptions.GetOrCreateObservable(variableName); disposeableContainer.AddDisposableTo(disposables); - var observable = disposeableContainer.Observable - .Select(bytes => S7ValueConverter.ConvertToType(bytes, address)); + var observable = + // Directly read variable first. + // This will propagate any errors due to reading from invalid addresses. + Observable.FromAsync(() => GetValue(variableName)) + .Concat( + disposeableContainer.Observable + .Select(bytes => S7ValueConverter.ConvertToType(bytes, address)) + ); if (transmissionMode == TransmissionMode.OnChange) observable = observable.DistinctUntilChanged();